Bouncycastle / Spongycastle与PSK合作

时间:2014-07-04 07:20:46

标签: android ssl bouncycastle spongycastle

我的spongycastle使用tls和psk实现了我的问题。

我从网络服务获得了一个psk并尝试连接到网络服务器。在我的HttpTransportLayer类中,我创建了一个包含服务器地址和端口的套接字。然后我创建一个TLSIdentity,它获取sessionIdentifier和共享密钥。

try {
    socket = new Socket(hostAddress, port);
}catch(UnknownHostException e){
    e.printStackTrace();
}

TlsPSKIdentity identity = new BcTlsPSKIdentity(sessionID.getBytes("UTF-8"), Util.hexStringToByteArray(psk));
BcPSKTlsClient pskTlsClient = new BcPSKTlsClient(identity);

this.tlsClientProtocol = new TlsClientProtocol(socket.getInputStream(), socket.getOutputStream());
this.tlsClientProtocol.connect(pskTlsClient);

outputStream = tlsClientProtocol.getOutputStream(); 

当我尝试连接服务器时,我收到异常。有谁知道如何解决这个问题?非常感谢你!

    07-04 09:17:38.726: W/System.err(3889): java.io.IOException: Internal TLS error, this could be an attack
07-04 09:17:38.726: W/System.err(3889):     at org.spongycastle.crypto.tls.TlsProtocol.failWithError(TlsProtocol.java:637)
07-04 09:17:38.736: W/System.err(3889):     at org.spongycastle.crypto.tls.TlsProtocol.safeReadRecord(TlsProtocol.java:457)
07-04 09:17:38.736: W/System.err(3889):     at org.spongycastle.crypto.tls.TlsProtocol.completeHandshake(TlsProtocol.java:148)
07-04 09:17:38.746: W/System.err(3889):     at org.spongycastle.crypto.tls.TlsClientProtocol.connect(TlsClientProtocol.java:97)
07-04 09:17:38.756: W/System.err(3889):     at de.rs.webserviceprovider.HttpTransportLayer.connect(HttpTransportLayer.java:135)
07-04 09:17:38.756: W/System.err(3889):     at de.rs.webserviceprovider.HttpTransportLayer.<init>(HttpTransportLayer.java:77)
07-04 09:17:38.766: W/System.err(3889):     at de.rs.eidserviceprovider.ServiceProvider.setServerConnection(ServiceProvider.java:106)
07-04 09:17:38.776: W/System.err(3889):     at de.rs.eidservices.tools.AsyncConnectionTask.doInBackground(AsyncConnectionTask.java:47)
07-04 09:17:38.776: W/System.err(3889):     at de.rs.eidservices.tools.AsyncConnectionTask.doInBackground(AsyncConnectionTask.java:1)
07-04 09:17:38.796: W/System.err(3889):     at android.os.AsyncTask$2.call(AsyncTask.java)
07-04 09:17:38.796: W/System.err(3889):     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
07-04 09:17:38.806: W/System.err(3889):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java)
07-04 09:17:38.816: W/System.err(3889):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
07-04 09:17:38.826: W/System.err(3889):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
07-04 09:17:38.826: W/System.err(3889):     at java.lang.Thread.run(Thread.java:864)

0 个答案:

没有答案