1 /* 2 * Copyright 2018 The Netty Project 3 * 4 * The Netty Project licenses this file to you under the Apache License, 5 * version 2.0 (the "License"); you may not use this file except in compliance 6 * with the License. You may obtain a copy of the License at: 7 * 8 * https://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, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations 14 * under the License. 15 */ 16 package io.netty.handler.ssl; 17 18 import javax.net.ssl.SSLException; 19 import javax.net.ssl.SSLSession; 20 import java.security.cert.Certificate; 21 import java.util.Map; 22 23 /** 24 * {@link SSLSession} that is specific to our native implementation. 25 */ 26 interface OpenSslSession extends SSLSession { 27 28 /** 29 * Called on a handshake session before being exposed to a {@link javax.net.ssl.TrustManager}. 30 * Session data must be cleared by this call. 31 */ 32 void prepareHandshake(); 33 34 /** 35 * Return the {@link OpenSslSessionId} that can be used to identify this session. 36 */ 37 OpenSslSessionId sessionId(); 38 39 /** 40 * Set the local certificate chain that is used. It is not expected that this array will be changed at all 41 * and so its ok to not copy the array. 42 */ 43 void setLocalCertificate(Certificate[] localCertificate); 44 45 /** 46 * Set the details for the session which might come from a cache. 47 * 48 * @param creationTime the time at which the session was created. 49 * @param lastAccessedTime the time at which the session was last accessed via the session infrastructure (cache). 50 * @param id the {@link OpenSslSessionId} 51 * @param keyValueStorage the key value store. See {@link #keyValueStorage()}. 52 */ 53 void setSessionDetails(long creationTime, long lastAccessedTime, OpenSslSessionId id, 54 Map<String, Object> keyValueStorage); 55 56 /** 57 * Return the underlying {@link Map} that is used by the following methods: 58 * 59 * <ul> 60 * <li>{@link #putValue(String, Object)}</li> 61 * <li>{@link #removeValue(String)}</li> 62 * <li>{@link #getValue(String)}</li> 63 * <li> {@link #getValueNames()}</li> 64 * </ul> 65 * 66 * The {@link Map} must be thread-safe! 67 * 68 * @return storage 69 */ 70 Map<String, Object> keyValueStorage(); 71 72 /** 73 * Set the last access time which will be returned by {@link #getLastAccessedTime()}. 74 * 75 * @param time the time 76 */ 77 void setLastAccessedTime(long time); 78 79 @Override 80 OpenSslSessionContext getSessionContext(); 81 82 /** 83 * Expand (or increase) the value returned by {@link #getApplicationBufferSize()} if necessary. 84 * <p> 85 * This is only called in a synchronized block, so no need to use atomic operations. 86 * @param packetLengthDataOnly The packet size which exceeds the current {@link #getApplicationBufferSize()}. 87 */ 88 void tryExpandApplicationBufferSize(int packetLengthDataOnly); 89 90 /** 91 * Called once the handshake has completed. 92 */ 93 void handshakeFinished(byte[] id, String cipher, String protocol, byte[] peerCertificate, 94 byte[][] peerCertificateChain, long creationTime, long timeout) throws SSLException; 95 }