Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.apache.commons.net.util;
 
 
TrustManager utilities for generating TrustManagers.

Since:
3.0
 
 public final class TrustManagerUtils
 {
     private static final X509Certificate[] EMPTY_X509CERTIFICATE_ARRAY = new X509Certificate[]{};
 
     private static class TrustManager implements X509TrustManager {
 
         private final boolean checkServerValidity;
 
         TrustManager(boolean checkServerValidity) {
             this. = checkServerValidity;
         }

        
Never generates a CertificateException.
 
 //        @Override
         public void checkClientTrusted(X509Certificate[] certificatesString authType)
         {
             return;
         }
 
 //        @Override
         public void checkServerTrusted(X509Certificate[] certificatesString authType)
             throws CertificateException
         {
             if () {
                 for (X509Certificate certificate : certificates)
                 {
                     certificate.checkValidity();
                 }
             }
         }

        

Returns:
an empty array of certificates
 
 //        @Override
         public X509Certificate[] getAcceptedIssuers()
         {
             return ;
         }
     }
 
     private static final X509TrustManager ACCEPT_ALL=new TrustManager(false);
 
     private static final X509TrustManager CHECK_SERVER_VALIDITY=new TrustManager(true);

    
Generate a TrustManager that performs no checks.

Returns:
the TrustManager
 
     public static X509TrustManager getAcceptAllTrustManager(){
         return ;
     }

    
Generate a TrustManager that checks server certificates for validity, but otherwise performs no checks.

Returns:
the validating TrustManager
 
         return ;
     }

    
Return the default TrustManager provided by the JVM.

This should be the same as the default used by SSLContext.init(KeyManager[], TrustManager[], SecureRandom) when the TrustManager parameter is set to null

Parameters:
keyStore the KeyStore to use, may be null
Returns:
the default TrustManager
Throws:
java.security.GeneralSecurityException
    public static X509TrustManager getDefaultTrustManager(KeyStore keyStorethrows GeneralSecurityException {
        String defaultAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
        TrustManagerFactory instance = TrustManagerFactory.getInstance(defaultAlgorithm);
        instance.init(keyStore);
        return (X509TrustManagerinstance.getTrustManagers()[0];
    }
New to GrepCode? Check out our FAQ X