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;
General utilities for SSLContext.

Since:
3.0
public class SSLContextUtils {
    private SSLContextUtils() {
        // Not instantiable
    }

    
Create and initialise sn SSLContext.

Parameters:
protocol the protocol used to instatiate the context
keyManager the key manager, may be null
trustManager the trust manager, may be null
Returns:
the initialised context.
Throws:
java.io.IOException this is used to wrap any java.security.GeneralSecurityException that occurs
    public static SSLContext createSSLContext(String protocolKeyManager keyManagerTrustManager trustManagerthrows IOException {
        return createSSLContext(protocol,
                keyManager == null ? null : new KeyManager[] { keyManager },
                trustManager == null ? null : new TrustManager[] { trustManager });
    }

    
Create and initialise sn SSLContext.

Parameters:
protocol the protocol used to instatiate the context
keyManagers the array of key managers, may be null but array entries must not be null
trustManagers the array of trust managers, may be null but array entries must not be null
Returns:
the initialised context.
Throws:
java.io.IOException this is used to wrap any java.security.GeneralSecurityException that occurs
    public static SSLContext createSSLContext(String protocolKeyManager[] keyManagersTrustManager[] trustManagers)
        throws IOException {
        SSLContext ctx;
        try {
            ctx = SSLContext.getInstance(protocol);
            ctx.init(keyManagerstrustManagers/*SecureRandom*/ null);
        } catch (GeneralSecurityException e) {
            IOException ioe = new IOException("Could not initialize SSL context");
            ioe.initCause(e);
            throw ioe;
        }
        return ctx;
    }
New to GrepCode? Check out our FAQ X