Created
June 28, 2015 22:40
-
-
Save brcolow/fa6fe4918a2f65c93037 to your computer and use it in GitHub Desktop.
Mockserver + Jersey SSL Config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
io.netty.handler.codec.DecoderException: javax.net.ssl.SSLException: Received fatal alert: certificate_unknown | |
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:358) ~[mockserver-netty-3.9.16-jar-with-dependencies.jar:na] | |
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:230) ~[mockserver-netty-3.9.16-jar-with-dependencies.jar:na] | |
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) [mockserver-netty-3.9.16-jar-with-dependencies.jar:na] | |
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) [mockserver-netty-3.9.16-jar-with-dependencies.jar:na] | |
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846) [mockserver-netty-3.9.16-jar-with-dependencies.jar:na] | |
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131) [mockserver-netty-3.9.16-jar-with-dependencies.jar:na] | |
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511) [mockserver-netty-3.9.16-jar-with-dependencies.jar:na] | |
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468) [mockserver-netty-3.9.16-jar-with-dependencies.jar:na] | |
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382) [mockserver-netty-3.9.16-jar-with-dependencies.jar:na] | |
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354) [mockserver-netty-3.9.16-jar-with-dependencies.jar:na] | |
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111) [mockserver-netty-3.9.16-jar-with-dependencies.jar:na] | |
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137) [mockserver-netty-3.9.16-jar-with-dependencies.jar:na] | |
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_60-ea] | |
Caused by: javax.net.ssl.SSLException: Received fatal alert: certificate_unknown | |
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208) ~[na:1.8.0_60-ea] | |
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1666) ~[na:1.8.0_60-ea] | |
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1634) ~[na:1.8.0_60-ea] | |
at sun.security.ssl.SSLEngineImpl.recvAlert(SSLEngineImpl.java:1800) ~[na:1.8.0_60-ea] | |
at sun.security.ssl.SSLEngineImpl.readRecord(SSLEngineImpl.java:1083) ~[na:1.8.0_60-ea] | |
at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:907) ~[na:1.8.0_60-ea] | |
at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:781) ~[na:1.8.0_60-ea] | |
at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624) ~[na:1.8.0_60-ea] | |
at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1140) ~[mockserver-netty-3.9.16-jar-with-dependencies.jar:na] | |
at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1004) ~[mockserver-netty-3.9.16-jar-with-dependencies.jar:na] | |
at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:944) ~[mockserver-netty-3.9.16-jar-with-dependencies.jar:na] | |
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:327) ~[mockserver-netty-3.9.16-jar-with-dependencies.jar:na] | |
... 12 common frames omitted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main() | |
{ | |
public Client getHttpsClient() throws KeyStoreException | |
{ | |
return ClientBuilder.newBuilder() | |
.sslContext(getSSLContextProvider().getSSLContext()) | |
.build(); | |
} | |
@VisibleForTesting | |
public SSLContextProvider getSSLContextProvider() | |
{ | |
return new DefaultSSLContextProvider(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
when(main.getSSLContextProvider()).thenReturn(new MockServerSSLContextProvider()); | |
// later we use the jersey client but get an exception |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.cryptodirect.cryptodash.crypto; | |
import java.security.KeyStore; | |
import java.security.KeyStoreException; | |
import javax.net.ssl.SSLContext; | |
import org.mockserver.socket.SSLFactory; | |
/** | |
* @author Michael Ennen | |
*/ | |
public class MockServerSSLContextProvider implements SSLContextProvider | |
{ | |
@Override | |
public SSLContext getSSLContext() throws KeyStoreException | |
{ | |
return SSLFactory.getInstance().sslContext(); | |
} | |
@Override | |
public KeyStore getKeyStore() throws KeyStoreException | |
{ | |
return SSLFactory.getInstance().buildKeyStore(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment