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.hc.core5.http.nio.ssl; 29 30 import java.net.SocketAddress; 31 32 import org.apache.hc.core5.concurrent.FutureCallback; 33 import org.apache.hc.core5.http.HttpHost; 34 import org.apache.hc.core5.http.URIScheme; 35 import org.apache.hc.core5.net.NamedEndpoint; 36 import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer; 37 import org.apache.hc.core5.util.Timeout; 38 39 /** 40 * TLS protocol upgrade strategy for non-blocking {@link TransportSecurityLayer} sessions. 41 * 42 * @since 5.0 43 */ 44 public interface TlsStrategy { 45 46 /** 47 * Secures current session layer with TLS. 48 * 49 * @param sessionLayer the session layer 50 * @param host the name of the opposite endpoint when given or {@code null} otherwise. 51 * @param localAddress the address of the local endpoint. 52 * @param remoteAddress the address of the remote endpoint. 53 * @param attachment arbitrary object passes to the TLS session initialization code. 54 * @param handshakeTimeout the timeout to use while performing the TLS handshake; may be {@code null}. 55 * @return {@code true} if the session has been upgraded, {@code false} otherwise. 56 * 57 * @deprecated use {@link #upgrade(TransportSecurityLayer, NamedEndpoint, Object, Timeout, FutureCallback)} 58 */ 59 @Deprecated 60 boolean upgrade( 61 TransportSecurityLayer sessionLayer, 62 HttpHost host, 63 SocketAddress localAddress, 64 SocketAddress remoteAddress, 65 Object attachment, 66 Timeout handshakeTimeout); 67 68 /** 69 * Secures current session layer with TLS. 70 * 71 * @param sessionLayer the session layer 72 * @param endpoint the name of the opposite endpoint when applicable or {@code null} otherwise. 73 * @param attachment arbitrary object passes to the TLS session initialization code. 74 * @param handshakeTimeout the timeout to use while performing the TLS handshake; may be {@code null}. 75 * @param callback Operation result callback. 76 * 77 * @since 5.2 78 */ 79 default void upgrade( 80 TransportSecurityLayer sessionLayer, 81 NamedEndpoint endpoint, 82 Object attachment, 83 Timeout handshakeTimeout, 84 FutureCallback<TransportSecurityLayer> callback) { 85 upgrade(sessionLayer, new HttpHost(URIScheme.HTTPS.id, endpoint.getHostName(), endpoint.getPort()), 86 null, null, attachment, handshakeTimeout); 87 if (callback != null) { 88 callback.completed(sessionLayer); 89 } 90 } 91 92 }