This project has retired. For details please refer to its Attic page.
MockSSLSocketFactory.java

MockSSLSocketFactory.java

  1. /*
  2.  * Copyright 2013 The Apache Software Foundation.
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *      http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */
  16. package org.apache.juddi.v3.client.mapping;

  17. import java.io.IOException;
  18. import java.security.KeyManagementException;
  19. import java.security.KeyStoreException;
  20. import java.security.NoSuchAlgorithmException;
  21. import java.security.UnrecoverableKeyException;
  22. import java.security.cert.CertificateException;
  23. import java.security.cert.X509Certificate;
  24. import javax.net.ssl.SSLException;
  25. import javax.net.ssl.SSLSession;
  26. import javax.net.ssl.SSLSocket;
  27. import org.apache.http.conn.ssl.SSLSocketFactory;

  28. import org.apache.http.conn.ssl.TrustStrategy;
  29. import org.apache.http.conn.ssl.X509HostnameVerifier;

  30. /**
  31.  *
  32.  * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
  33.  */
  34. public class MockSSLSocketFactory extends SSLSocketFactory {

  35.     public MockSSLSocketFactory() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
  36.         super(trustStrategy, hostnameVerifier);
  37.     }
  38.     private static final X509HostnameVerifier hostnameVerifier = new X509HostnameVerifier() {
  39.         //@Override
  40.         public void verify(String host, SSLSocket ssl) throws IOException {
  41.             // Do nothing
  42.         }

  43.         //@Override
  44.         public void verify(String host, X509Certificate cert) throws SSLException {
  45.             //Do nothing
  46.         }

  47.         //@Override
  48.         public void verify(String host, String[] cns, String[] subjectAlts) throws SSLException {
  49.             //Do nothing
  50.         }

  51.         //@Override
  52.         public boolean verify(String s, SSLSession sslSession) {
  53.             return true;
  54.         }
  55.     };
  56.     private static final TrustStrategy trustStrategy = new TrustStrategy() {
  57.         //@Override
  58.         public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
  59.             return true;
  60.         }
  61.     };
  62. }