Showing posts with label xfire. Show all posts
Showing posts with label xfire. Show all posts

Thursday, April 7, 2011

Ignoring Certs for Testing

Had an issue while using XFire (legacy version of CXF), where I needed to access a website using ssl but that had a self-signed cert. The Protocol constructor is depreciated, but for testing purposes works fine.

Example
//protocol=https, etc
protected static void ignoreCertsFor(String protocol, int port){
  Protocol.registerProtocol(protocol, new Protocol(protocol, new EasySSLProtocolSocketFactory(), port));
}

EasySSLProtocolSocketFactory basically uses a "null" implementation of a X509TrustManager.

"null" X509TrustManager Example
new X509TrustManager() {

  public void checkClientTrusted(X509Certificate[] certs, String authType) {
  }

  public void checkServerTrusted(X509Certificate[] certs, String authType) {
  }

  public X509Certificate[] getAcceptedIssuers() {
    return null;
  }
};

See Also:
http://stackoverflow.com/questions/2301548/calling-axis2-web-service-from-xfire-client-the-endpoint-reference-epr-for-the