1
我正在嘗試使用適用於Android平臺的SSL來保護基於TCP/IP的套接字連接。 這裏是從我的代碼片段一些:在Android中使用基於SSL的tcp/ip套接字
客戶端:
SSLSocketFactory sslFact = null;
SSLContext ctx;
KeyStore ks;
char[] passphrase = "hosttest".toCharArray();
ks = KeyStore.getInstance("BKS");
ks.load(SSLActivity.mContext.getResources().openRawResource(R.raw.hosttestcert), passphrase);
TrustManagerFactory tmf =TrustManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
tmf.init(ks);
ctx = SSLContext.getInstance("TLS");
ctx.init(null,tmf.getTrustManagers(), null);
sslFact = ctx.getSocketFactory();
mySocket = (SSLSocket)sslFact.createSocket();
mySocket.connect(new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 7891),1000);
服務器端:
SSLServerSocketFactory sslSrvFact = null;
SSLContext ctx;
KeyManagerFactory kmf;
KeyStore ks;
// Load the self-signed server certificate
char[] passphrase = "hosttest".toCharArray();
ks = KeyStore.getInstance("BKS");
ks.load(SSLActivity.mContext.getResources().openRawResource(R.raw.hosttestcert), passphrase);
kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(ks, passphrase);
// Create a SSLContext with the certificate
ctx = SSLContext.getInstance("TLS");
ctx.init(kmf.getKeyManagers(),null, null);
sslSrvFact = ctx.getServerSocketFactory();
myServerSocket =(SSLServerSocket)sslSrvFact.createServerSocket(port);
當我打電話從服務器接受()套接字調用,我發現了以下例外:
javax.net.ssl.SSLException: Could not find any key store entries to support the enabled cipher suites.
org.apache.harmony.xnet.provider.jsse.OpenSSLServerSocketImpl.checkEnabledCipherSuites(OpenSSLServerSocketImpl.java:241)
org.apache.harmony.xnet.provider.jsse.OpenSSLServerSocketImpl.accept(OpenSSLServerSocketImpl.java:186)
at com.aricent.ssltesst.ApplinkTCPServer$1.run(ApplinkTCPServer.java:189)
at java.lang.Thread.run(Thread.java:856)
我正在關注這篇文章以生成我的證書和keystor e: http://randomizedsort.blogspot.in/2010/09/step-to-step-guide-to-programming.html 如果我在Android平臺上丟失了某些東西或其他需要完成的密鑰庫,請提出建議。