Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When a TrustManagerFactory is not a TrustManagerFactory (Java)

I am trying to add some additional JUnit test to an existing App-Server (TomCat) product. I have run into an issue with the (existing and fielded) custom TrustManager. This thing works fine in production, but during JUnit, gives exception.

The customized TrustManager merely loads a keystore from a path, and implicitly trusts our own public certs. For some reason, using this in JUnits causes an exception on the following line:

TrustManagerFactory tmFactory = TrustManagerFactory.getInstance("PKIX");     

Exception:

java.security.NoSuchAlgorithmException:  class configured for TrustManagerFactory: com.sun.net.ssl.internal.ssl.TrustManagerFactoryImpl$PKIXFactory not a TrustManagerFactory 

This exception takes place regardless of what Provider/Algorithm combinations are used ("SunX509", .getDefaultAlgorithm(), et al.).

Any insight will be greatly appreciated.

like image 897
David Beveridge Avatar asked Feb 01 '13 20:02

David Beveridge


1 Answers

Well, looks like PowerMock messes up with SSL issues and thus, you run into loading a wrong factory. The solution for that is to use an annotation on the test class:

@PowerMockIgnore("javax.net.ssl.*") 

this is taken from https://groups.google.com/forum/#!topic/powermock/v4nreP2AnOQ

like image 143
GBa Avatar answered Sep 27 '22 21:09

GBa