Ich habe einen WebSocket-Server in einem eingebetteten Jetty (8.1.8.v20121106) ausgeführt und möchte von einer anderen Java-Anwendung mit dem WebSocketClient verbinden. Dies ist die Testmethode ich benutze:Jetty WebSocketClient über SSL
@Test
public void testWebSockets() throws Exception {
logger.debug("START testWebSockets()");
WebSocketClientFactory factory = new WebSocketClientFactory();
factory.setBufferSize(4096);
factory.start();
WebSocketClient client = factory.newWebSocketClient();
client.setMaxIdleTime(30000);
client.setMaxTextMessageSize(1024);
client.setProtocol("MyProtocol");
WebSocket webSocket = new ClientWebSocket();
String wsUrl = "ws://localhost:8080/websocket";
String wssUrl = "wss://localhost:8443/websocket";
Future future = client.open(new URI(wssUrl), webSocket);
WebSocket.Connection connection = (Connection) future.get(10, TimeUnit.SECONDS);
assertNotNull("No connection!", connection);
connection.sendMessage("TestMessage");
connection.close();
logger.debug("END testWebSockets()");
}
Es ist kein Problem, die wsUrl verwenden, aber ich kann es nicht mit WSS bekommen arbeiten. Ich denke nicht, dass der Server das Problem ist, da ich kein Problem habe, mit wss von Javascript zu verbinden. Was mache ich in diesem Test falsch?
Sowohl der Server als auch der Client protokollieren einen "bad record MAC" im ssl-Setup. Dies ist der letzte Teil des Server-Log:
2013-01-15 10:26:06,398 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] unwrap OK NEED_TASK consumed=107 produced=0
2013-01-15 10:26:06,399 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] [email protected] SSL NEED_TASK i/o/u=75/0/0 ishut=false oshut=false {[email protected],g=HttpGenerator{s=0,h=-1
,b=-1,c=-1},p=HttpParser{s=-14,l=0,c=0},r=0} NEED_TASK filled=69/75 flushed=0/0
2013-01-15 10:26:06,413 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] [email protected] SSL NEED_UNWRAP i/o/u=75/0/0 ishut=false oshut=false {[email protected],g=HttpGenerator{s=0,h=
-1,b=-1,c=-1},p=HttpParser{s=-14,l=0,c=0},r=0} NEED_UNWRAP filled=0/75 flushed=0/0
2013-01-15 10:26:06,415 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] unwrap OK NEED_UNWRAP consumed=6 produced=0
2013-01-15 10:26:06,416 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] [email protected] SSL NEED_UNWRAP i/o/u=69/0/0 ishut=false oshut=false {[email protected],g=HttpGenerator{s=0,h=
-1,b=-1,c=-1},p=HttpParser{s=-14,l=0,c=0},r=0} NEED_UNWRAP filled=0/69 flushed=0/0
2013-01-15 10:26:06,419 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] unwrap OK NEED_WRAP consumed=69 produced=0
2013-01-15 10:26:06,420 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] [email protected] SSL NEED_WRAP i/o/u=0/0/0 ishut=false oshut=false {[email protected],g=HttpGenerator{s=0,h=-1,
b=-1,c=-1},p=HttpParser{s=-14,l=0,c=0},r=0} NEED_WRAP filled=0/0 flushed=0/0
2013-01-15 10:26:06,421 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] wrap OK NEED_WRAP consumed=0 produced=6
2013-01-15 10:26:06,422 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] [email protected] SSL NEED_WRAP i/o/u=0/0/0 ishut=false oshut=false {[email protected],g=HttpGenerator{s=0,h=-1,
b=-1,c=-1},p=HttpParser{s=-14,l=0,c=0},r=0} NEED_WRAP filled=0/0 flushed=6/0
2013-01-15 10:26:06,423 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] wrap OK FINISHED consumed=0 produced=69
2013-01-15 10:26:06,424 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] [email protected] SSL NOT_HANDSHAKING i/o/u=0/0/0 ishut=false oshut=false {[email protected],g=HttpGenerator{s=0
,h=-1,b=-1,c=-1},p=HttpParser{s=-14,l=0,c=0},r=0} NOT_HANDSHAKING filled=0/0 flushed=69/0
2013-01-15 10:26:06,426 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] [email protected] SSL NOT_HANDSHAKING i/o/u=0/0/0 ishut=false oshut=false {[email protected],g=HttpGenerator{s=0
,h=-1,b=-1,c=-1},p=HttpParser{s=-14,l=0,c=0},r=0} NOT_HANDSHAKING filled=0/0 flushed=0/0
2013-01-15 10:26:06,428 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] [email protected] SSL NOT_HANDSHAKING i/o/u=245/0/0 ishut=false oshut=false {[email protected],g=HttpGenerator{s
=0,h=-1,b=-1,c=-1},p=HttpParser{s=-14,l=0,c=0},r=0} NOT_HANDSHAKING filled=245/245 flushed=0/0
2013-01-15 10:26:06,430 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [email protected]{l(/127.0.0.1:65084)<->r(/127.0.0.1:8444),d=true,open=true,ishut=false,oshut=false,rb=false,wb=false,w=true,i=1r}-{[email protected] SSL NEED_WRAP
i/o/u=245/0/0 ishut=false oshut=false {[email protected],g=HttpGenerator{s=0,h=-1,b=-1,c=-1},p=HttpParser{s=-14,l=0,c=0},r=0}}
javax.net.ssl.SSLException: bad record MAC
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1639)
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1607)
at sun.security.ssl.SSLEngineImpl.readRecord(SSLEngineImpl.java:979)
at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:884)
at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:758)
at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624)
at org.eclipse.jetty.io.nio.SslConnection.unwrap(SslConnection.java:524)
at org.eclipse.jetty.io.nio.SslConnection.process(SslConnection.java:359)
at org.eclipse.jetty.io.nio.SslConnection.access$900(SslConnection.java:48)
at org.eclipse.jetty.io.nio.SslConnection$SslEndPoint.fill(SslConnection.java:666)
at org.eclipse.jetty.http.HttpParser.fill(HttpParser.java:1035)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:280)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SslConnection.handle(SslConnection.java:196)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:722)
2013-01-15 10:26:06,463 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ChannelEndPoint - close [email protected]{l(/127.0.0.1:65084)<->r(/127.0.0.1:8444),d=true,open=true,ishut=false,oshut=false,rb=false,wb=false,w=true,i=1!}-{[email protected]
3ac SSL NEED_WRAP i/o/u=245/0/0 ishut=false oshut=false {[email protected],g=HttpGenerator{s=0,h=-1,b=-1,c=-1},p=HttpParser{s=-14,l=0,c=0},r=0}}
2013-01-15 10:26:06,469 qtp9902580-25 DEBUG org.eclipse.jetty.http.HttpParser -
javax.net.ssl.SSLException: bad record MAC
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1639)
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1607)
at sun.security.ssl.SSLEngineImpl.readRecord(SSLEngineImpl.java:979)
at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:884)
at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:758)
at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624)
at org.eclipse.jetty.io.nio.SslConnection.unwrap(SslConnection.java:524)
at org.eclipse.jetty.io.nio.SslConnection.process(SslConnection.java:359)
at org.eclipse.jetty.io.nio.SslConnection.access$900(SslConnection.java:48)
at org.eclipse.jetty.io.nio.SslConnection$SslEndPoint.fill(SslConnection.java:666)
at org.eclipse.jetty.http.HttpParser.fill(HttpParser.java:1035)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:280)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SslConnection.handle(SslConnection.java:196)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:722)
2013-01-15 10:26:06,506 qtp9902580-25 DEBUG org.eclipse.jetty.http.HttpParser - HttpParser{s=-14,l=0,c=0}
org.eclipse.jetty.io.EofException
at org.eclipse.jetty.http.HttpParser.fill(HttpParser.java:1041)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:280)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SslConnection.handle(SslConnection.java:196)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.net.ssl.SSLException: bad record MAC
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1639)
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1607)
at sun.security.ssl.SSLEngineImpl.readRecord(SSLEngineImpl.java:979)
at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:884)
at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:758)
at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624)
at org.eclipse.jetty.io.nio.SslConnection.unwrap(SslConnection.java:524)
at org.eclipse.jetty.io.nio.SslConnection.process(SslConnection.java:359)
at org.eclipse.jetty.io.nio.SslConnection.access$900(SslConnection.java:48)
at org.eclipse.jetty.io.nio.SslConnection$SslEndPoint.fill(SslConnection.java:666)
at org.eclipse.jetty.http.HttpParser.fill(HttpParser.java:1035)
... 9 more
2013-01-15 10:26:06,470 qtp9902580-23 Selector0 DEBUG org.eclipse.jetty.io.nio - destroyEndPoint [email protected]{l(null)<->r(0.0.0.0/0.0.0.0:8444),d=true,open=false,ishut=true,oshut=true,rb=false,wb=false,w=true,i=1!}-{[email protected]
SSL NEED_WRAP i/o/u=245/0/0 ishut=false oshut=false {[email protected],g=HttpGenerator{s=0,h=-1,b=-1,c=-1},p=HttpParser{s=-14,l=0,c=0},r=0}}
2013-01-15 10:26:06,555 qtp9902580-25 DEBUG org.eclipse.jetty.server.AsyncHttpConnection - Disabled read interest while writing response SSL NEED_WRAP i/o/u=245/0/0 ishut=false oshut=false {[email protected],g=HttpGenerator{s=0
,h=-1,b=-1,c=-1},p=HttpParser{s=0,l=0,c=0},r=0}
2013-01-15 10:26:06,559 qtp9902580-23 Selector0 DEBUG org.eclipse.jetty.server.AbstractHttpConnection - closed [email protected],g=HttpGenerator{s=0,h=-1,b=-1,c=-1},p=HttpParser{s=0,l=0,c=0},r=0
2013-01-15 10:26:06,560 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio - EOF
org.eclipse.jetty.io.EofException
at org.eclipse.jetty.http.HttpParser.fill(HttpParser.java:1041)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:280)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SslConnection.handle(SslConnection.java:196)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.net.ssl.SSLException: bad record MAC
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1639)
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1607)
at sun.security.ssl.SSLEngineImpl.readRecord(SSLEngineImpl.java:979)
at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:884)
at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:758)
at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624)
at org.eclipse.jetty.io.nio.SslConnection.unwrap(SslConnection.java:524)
at org.eclipse.jetty.io.nio.SslConnection.process(SslConnection.java:359)
at org.eclipse.jetty.io.nio.SslConnection.access$900(SslConnection.java:48)
at org.eclipse.jetty.io.nio.SslConnection$SslEndPoint.fill(SslConnection.java:666)
at org.eclipse.jetty.http.HttpParser.fill(HttpParser.java:1035)
... 9 more
2013-01-15 10:26:06,623 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ChannelEndPoint - close [email protected]{l(null)<->r(0.0.0.0/0.0.0.0:8444),d=true,open=false,ishut=true,oshut=true,rb=false,wb=false,w=true,i=1-}-{[email protected] SSL
NEED_WRAP i/o/u=245/0/0 ishut=false oshut=false {[email protected],g=HttpGenerator{s=0,h=-1,b=-1,c=-1},p=HttpParser{s=0,l=0,c=0},r=0}}
Ihre Antwort ist hier: http://stackoverflow.com/questions/8154617/how-to-troubleshoot-ssl-bad-record- Mac-Ausnahme – jdelobel
@jdelobel - möglicherweise, aber unwahrscheinlich. Er könnte es wahrscheinlich eingrenzen, indem er IPv6 in seinem Netzwerkadapter deaktiviert und dann die JVM (unter anderem) neu startet. Außerdem kann ein Wireshark-Trace Ihnen eine Vorstellung davon geben, welche Art von Verkehr im Netzwerk zu hören ist. – djangofan
Ich bin der zweite Aufruf für eine Wireshark-Trace - es wäre hilfreich zu sehen, wie weit die SSL-Austausch wird. Welche Version von Java benutzt du? Wenn Sie Java 7 verwenden, würde ich sehen, ob Java 6 einen Unterschied macht (Java 7 versucht standardmäßig TLSv1.2 auszuführen, während Java 6 TLSv1 ausführt). Ich habe dies angesprochen, da ich kürzlich Probleme mit Java 7 TLSv1.2 und einigen mobilen Clients hatte (Java 6 hatte keine Probleme). – Gareth