1 /* 2 * Copyright 2014 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.netty5.handler.ssl; 17 18 import io.netty.internal.tcnative.SSL; 19 import io.netty.internal.tcnative.SSLContext; 20 21 import java.util.concurrent.locks.Lock; 22 23 /** 24 * {@link OpenSslSessionContext} implementation which offers extra methods which are only useful for the server-side. 25 */ 26 public final class OpenSslServerSessionContext extends OpenSslSessionContext { 27 OpenSslServerSessionContext(ReferenceCountedOpenSslContext context, OpenSslKeyMaterialProvider provider) { 28 super(context, provider, SSL.SSL_SESS_CACHE_SERVER, new OpenSslSessionCache(context.engineMap)); 29 } 30 31 /** 32 * Set the context within which session be reused (server side only) 33 * See <a href="https://www.openssl.org/docs/ssl/SSL_CTX_set_session_id_context.html"> 34 * man SSL_CTX_set_session_id_context</a> 35 * 36 * @param sidCtx can be any kind of binary data, it is therefore possible to use e.g. the name 37 * of the application and/or the hostname and/or service name 38 * @return {@code true} if success, {@code false} otherwise. 39 */ 40 public boolean setSessionIdContext(byte[] sidCtx) { 41 Lock writerLock = context.ctxLock.writeLock(); 42 writerLock.lock(); 43 try { 44 return SSLContext.setSessionIdContext(context.ctx, sidCtx); 45 } finally { 46 writerLock.unlock(); 47 } 48 } 49 }