Skip to content

Ensure certificate verification by using a singleton and defaults. #526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

wsargent
Copy link
Contributor

@wsargent wsargent commented Apr 8, 2014

Fixes #352

@slandelle
Copy link
Contributor

What's the benefit of this singleton over the static class?

What are the benefits of this SingletonHolder pattern (first time I see it)? Why not an enum?

@wsargent
Copy link
Contributor Author

wsargent commented Apr 8, 2014

singleton holder is a thread safe lazy initialization pattern: https://en.wikipedia.org/wiki/Initialization-on-demand_holder_idiom
After going through an issue where I needed to patch static methods http://tersesystems.com/2014/03/02/monkeypatching-java-classes/ I much prefer singletons because at least you can swap out one reference and have it done with.

@slandelle
Copy link
Contributor

OK, thanks :)

@slandelle
Copy link
Contributor

I just tried to merge and got the following test errors:

Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:196)
    at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:268)
    at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:380)
    at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
    at sun.security.validator.Validator.validate(Validator.java:260)
    at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:326)
    at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:283)
    at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:138)
    at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1328)
    at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:153)
    at sun.security.ssl.Handshaker.processLoop(Handshaker.java:868)
    at sun.security.ssl.Handshaker$1.run(Handshaker.java:808)
    at sun.security.ssl.Handshaker$1.run(Handshaker.java:806)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.security.ssl.Handshaker$DelegatedTask.run(Handshaker.java:1227)

Failed tests:
  GrizzlyFeedableBodyGeneratorTest.testNonBlockingFeederOverSSLMultipleThreads:125->doNonBlockingFeeder:363 expected:<200> but was:<0>
  GrizzlyFeedableBodyGeneratorTest.testSimpleFeederOverSSLMultipleThreads:115->doSimpleFeeder:227 expected:<200> but was:<0>
  GrizzlyHttpToHttpsRedirectTest>HttpToHttpsRedirectTest.runAllSequentiallyBecauseNotThreadSafe:90->HttpToHttpsRedirectTest.httpToHttpsRedirect:102 » Execution
  GrizzlyProxyTunnelingTest>ProxyTunnellingTest.testConfigProxy:126 » Execution ...
  GrizzlyProxyTunnelingTest>ProxyTunnellingTest.testRequestProxy:98 » Execution ...
  GrizzlyProxyTunnelingTest>ProxyTunnellingTest.testSimpleAHCConfigProxy:143 » Execution
  NettyHttpToHttpsRedirectTest.runAllSequentiallyBecauseNotThreadSafe » Execution
  NettyProxyTunnellingTest.testConfigProxy » Execution javax.net.ssl.SSLHandshak...
  NettyProxyTunnellingTest.testRequestProxy » Execution javax.net.ssl.SSLHandsha...
  NettyProxyTunnellingTest.testSimpleAHCConfigProxy » Execution javax.net.ssl.SS...
  NettyProxyTunnellingTest.echoText » Execution javax.net.ssl.SSLHandshakeExcept...

@wsargent Did you run the tests successfully before submitting?

@slandelle
Copy link
Contributor

@wsargent OK, I feel stupid: that's just that the tests use a self-signed certificate.

With your PR, in order to have AHC work with servers using self signed certificates is to expect the users to create a SSLContext with a "trust all" TrustManager and either set the Default SSLContext or pass it in AHC config. Do I get it right?

If so, this is way too much a constraint, we should ship such a permissive TrustManager and have an option for enabling/disabling.

How do you deal with this in Play?

@wsargent
Copy link
Contributor Author

From memory, but I think the way I did it in Play was to add a self signed certificate to a trust manager explicitly in the test.

@slandelle
Copy link
Contributor

But that means that Play WS doesn't work with self signed certificates, like it's usually the case on dev/test platforms?!

@slandelle
Copy link
Contributor

Ha, OK, if acceptAnyCertificate is let to true, you leave AHC as is with current LooseTrustManager.

@slandelle
Copy link
Contributor

So honestly, you're PR was excessive: if you completely remove AHC LooseTrustManager like you did, you're shooting yourself in the foot and will have to reimplement it in Play. :)

@slandelle
Copy link
Contributor

@wsargent I've cherry-picked your commit in #572 and introduced an acceptAnyCertificate config parameter (same name as in Play):

  • if false (default), use SSLContext.getDefault
  • if true, use a loose TrustManager

WDYT?

@slandelle
Copy link
Contributor

@jfarcand @oleksiys WDYT?

@wsargent
Copy link
Contributor Author

So honestly, you're PR was excessive: if you completely remove AHC LooseTrustManager like you did, you're shooting yourself in the foot and will have to reimplement it in Play. :)

By design. playframework/playframework#2855

@slandelle slandelle closed this in df6ed70 Jun 13, 2014
@wsargent wsargent deleted the fix-352 branch June 14, 2014 12:53
cs-workco pushed a commit to cs-workco/async-http-client that referenced this pull request Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SSL/TLS certificate verification disabled
2 participants