1 /* 2 * ==================================================================== 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * ==================================================================== 20 * 21 * This software consists of voluntary contributions made by many 22 * individuals on behalf of the Apache Software Foundation. For more 23 * information on the Apache Software Foundation, please see 24 * <http://www.apache.org/>. 25 * 26 */ 27 28 package org.apache.http.conn.ssl; 29 30 import java.security.KeyManagementException; 31 import java.security.NoSuchAlgorithmException; 32 33 import javax.net.ssl.SSLContext; 34 35 import org.apache.http.annotation.Contract; 36 import org.apache.http.annotation.ThreadingBehavior; 37 38 /** 39 * {@link SSLContext} factory methods. 40 * 41 * @since 4.3 42 * 43 * @deprecated (4.4) use {@link org.apache.http.ssl.SSLContexts}. 44 */ 45 @Contract(threading = ThreadingBehavior.IMMUTABLE) 46 @Deprecated 47 public class SSLContexts { 48 49 /** 50 * Creates default factory based on the standard JSSE trust material 51 * ({@code cacerts} file in the security properties directory). System properties 52 * are not taken into consideration. 53 * 54 * @return the default SSL socket factory 55 */ 56 public static SSLContext createDefault() throws SSLInitializationException { 57 try { 58 final SSLContext sslcontext = SSLContext.getInstance(SSLContextBuilder.TLS); 59 sslcontext.init(null, null, null); 60 return sslcontext; 61 } catch (final NoSuchAlgorithmException ex) { 62 throw new SSLInitializationException(ex.getMessage(), ex); 63 } catch (final KeyManagementException ex) { 64 throw new SSLInitializationException(ex.getMessage(), ex); 65 } 66 } 67 68 /** 69 * Creates default SSL context based on system properties. This method obtains 70 * default SSL context by calling {@code SSLContext.getInstance("Default")}. 71 * Please note that {@code Default} algorithm is supported as of Java 6. 72 * This method will fall back onto {@link #createDefault()} when 73 * {@code Default} algorithm is not available. 74 * 75 * @return default system SSL context 76 */ 77 public static SSLContext createSystemDefault() throws SSLInitializationException { 78 try { 79 return SSLContext.getDefault(); 80 } catch (final NoSuchAlgorithmException ex) { 81 return createDefault(); 82 } 83 } 84 85 /** 86 * Creates custom SSL context. 87 * 88 * @return default system SSL context 89 */ 90 public static SSLContextBuilder custom() { 91 return new SSLContextBuilder(); 92 } 93 94 }