[stunnel-users] how to connect to server by C++ or Java with default certificate

何召卫 dabaohe at gmail.com
Mon Aug 18 05:08:54 CEST 2008


I have a application server after stunnel and I want to write a client
program running on handset with default certificate(that means I don't
want to create a new certificate and just use stunnel's certificate to
do this).

I don't see any sample code in google, and I just find some java code
fragment and I put it together here.

[code]
Socket mySocket = null;
SSLSocketFactory sslFactory = null;
SSLContext sslCtx = SSLContext.getInstance( "TLS" );
KeyManagerFactory kMF = KeyManagerFactory.getInstance( "SunX509" );
KeyStore kS = KeyStore.getInstance( "JKS") ;

//Hard-coded password for decrypting Client Key
char[] passWord= "myPassword".toCharArray();

kS.load(new FileInputStream("D:/program/stunnel/client.pem"), null);
kMF.init(kS, passWord);

TrustManagerFactory tMF = TrustManagerFactory.getInstance("SunX509");

tMF.init(kS );

sslCtx.init(kMF.getKeyManagers(), tMF.getTrustManagers(), null);
sslFactory = sslCtx.getSocketFactory();

mySocket = sslFactory.createSocket("10.0.0.220", 5555);
[/code]

as you see, I am on windows and install stunnel on D:/Program/stunnel,
and I copy the public key part of the stunnel.pem
to client.pem

THE QUESTION is I don't know anything about PASSORD, such as
KeyStore.load() or KeyManagerFactory.init(), so the code fragment
can't work at all.

any one can provide me the sample code connect to stunnel server,
either Java or C/C++

most advice in google is using stunnel client and server but in
handset it is impossible and unresonable.

Tks for any help!



More information about the stunnel-users mailing list