1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
26
27 public final class OpenSslServerSessionContext extends OpenSslSessionContext {
28 OpenSslServerSessionContext(ReferenceCountedOpenSslContext context) {
29 super(context);
30 }
31
32 @Override
33 public void setSessionTimeout(int seconds) {
34 if (seconds < 0) {
35 throw new IllegalArgumentException();
36 }
37 Lock writerLock = context.ctxLock.writeLock();
38 writerLock.lock();
39 try {
40 SSLContext.setSessionCacheTimeout(context.ctx, seconds);
41 } finally {
42 writerLock.unlock();
43 }
44 }
45
46 @Override
47 public int getSessionTimeout() {
48 Lock readerLock = context.ctxLock.readLock();
49 readerLock.lock();
50 try {
51 return (int) SSLContext.getSessionCacheTimeout(context.ctx);
52 } finally {
53 readerLock.unlock();
54 }
55 }
56
57 @Override
58 public void setSessionCacheSize(int size) {
59 if (size < 0) {
60 throw new IllegalArgumentException();
61 }
62 Lock writerLock = context.ctxLock.writeLock();
63 writerLock.lock();
64 try {
65 SSLContext.setSessionCacheSize(context.ctx, size);
66 } finally {
67 writerLock.unlock();
68 }
69 }
70
71 @Override
72 public int getSessionCacheSize() {
73 Lock readerLock = context.ctxLock.readLock();
74 readerLock.lock();
75 try {
76 return (int) SSLContext.getSessionCacheSize(context.ctx);
77 } finally {
78 readerLock.unlock();
79 }
80 }
81
82 @Override
83 public void setSessionCacheEnabled(boolean enabled) {
84 long mode = enabled ? SSL.SSL_SESS_CACHE_SERVER : SSL.SSL_SESS_CACHE_OFF;
85
86 Lock writerLock = context.ctxLock.writeLock();
87 writerLock.lock();
88 try {
89 SSLContext.setSessionCacheMode(context.ctx, mode);
90 } finally {
91 writerLock.unlock();
92 }
93 }
94
95 @Override
96 public boolean isSessionCacheEnabled() {
97 Lock readerLock = context.ctxLock.readLock();
98 readerLock.lock();
99 try {
100 return SSLContext.getSessionCacheMode(context.ctx) == SSL.SSL_SESS_CACHE_SERVER;
101 } finally {
102 readerLock.unlock();
103 }
104 }
105
106
107
108
109
110
111
112
113
114
115 public boolean setSessionIdContext(byte[] sidCtx) {
116 Lock writerLock = context.ctxLock.writeLock();
117 writerLock.lock();
118 try {
119 return SSLContext.setSessionIdContext(context.ctx, sidCtx);
120 } finally {
121 writerLock.unlock();
122 }
123 }
124 }