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