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.util.internal.EmptyArrays;
19 import io.netty.util.internal.SuppressJava6Requirement;
20
21 import javax.net.ssl.ExtendedSSLSession;
22 import javax.net.ssl.SSLException;
23 import javax.net.ssl.SSLPeerUnverifiedException;
24 import javax.net.ssl.SSLSessionBindingEvent;
25 import javax.net.ssl.SSLSessionBindingListener;
26 import javax.security.cert.X509Certificate;
27 import java.security.Principal;
28 import java.security.cert.Certificate;
29 import java.util.Collections;
30 import java.util.List;
31 import java.util.Map;
32
33
34
35
36
37 @SuppressJava6Requirement(reason = "Usage guarded by java version check")
38 abstract class ExtendedOpenSslSession extends ExtendedSSLSession implements OpenSslSession {
39
40
41
42
43 private static final String[] LOCAL_SUPPORTED_SIGNATURE_ALGORITHMS = {
44 "SHA512withRSA", "SHA512withECDSA", "SHA384withRSA", "SHA384withECDSA", "SHA256withRSA",
45 "SHA256withECDSA", "SHA224withRSA", "SHA224withECDSA", "SHA1withRSA", "SHA1withECDSA",
46 "RSASSA-PSS",
47 };
48
49 private final OpenSslSession wrapped;
50
51 ExtendedOpenSslSession(OpenSslSession wrapped) {
52 this.wrapped = wrapped;
53 }
54
55
56 @Override
57 @SuppressWarnings({ "unchecked", "rawtypes" })
58 public abstract List getRequestedServerNames();
59
60
61 public List<byte[]> getStatusResponses() {
62
63
64 return Collections.emptyList();
65 }
66
67 @Override
68 public void prepareHandshake() {
69 wrapped.prepareHandshake();
70 }
71
72 @Override
73 public Map<String, Object> keyValueStorage() {
74 return wrapped.keyValueStorage();
75 }
76
77 @Override
78 public OpenSslSessionId sessionId() {
79 return wrapped.sessionId();
80 }
81
82 @Override
83 public void setSessionDetails(long creationTime, long lastAccessedTime, OpenSslSessionId id,
84 Map<String, Object> keyValueStorage) {
85 wrapped.setSessionDetails(creationTime, lastAccessedTime, id, keyValueStorage);
86 }
87
88 @Override
89 public final void setLocalCertificate(Certificate[] localCertificate) {
90 wrapped.setLocalCertificate(localCertificate);
91 }
92
93 @Override
94 public String[] getPeerSupportedSignatureAlgorithms() {
95 return EmptyArrays.EMPTY_STRINGS;
96 }
97
98 @Override
99 public final void tryExpandApplicationBufferSize(int packetLengthDataOnly) {
100 wrapped.tryExpandApplicationBufferSize(packetLengthDataOnly);
101 }
102
103 @Override
104 public final String[] getLocalSupportedSignatureAlgorithms() {
105 return LOCAL_SUPPORTED_SIGNATURE_ALGORITHMS.clone();
106 }
107
108 @Override
109 public final byte[] getId() {
110 return wrapped.getId();
111 }
112
113 @Override
114 public final OpenSslSessionContext getSessionContext() {
115 return wrapped.getSessionContext();
116 }
117
118 @Override
119 public final long getCreationTime() {
120 return wrapped.getCreationTime();
121 }
122
123 @Override
124 public final long getLastAccessedTime() {
125 return wrapped.getLastAccessedTime();
126 }
127
128 @Override
129 public void setLastAccessedTime(long time) {
130 wrapped.setLastAccessedTime(time);
131 }
132
133 @Override
134 public final void invalidate() {
135 wrapped.invalidate();
136 }
137
138 @Override
139 public final boolean isValid() {
140 return wrapped.isValid();
141 }
142
143 @Override
144 public final void putValue(String name, Object value) {
145 if (value instanceof SSLSessionBindingListener) {
146
147 value = new SSLSessionBindingListenerDecorator((SSLSessionBindingListener) value);
148 }
149 wrapped.putValue(name, value);
150 }
151
152 @Override
153 public final Object getValue(String s) {
154 Object value = wrapped.getValue(s);
155 if (value instanceof SSLSessionBindingListenerDecorator) {
156
157 return ((SSLSessionBindingListenerDecorator) value).delegate;
158 }
159 return value;
160 }
161
162 @Override
163 public final void removeValue(String s) {
164 wrapped.removeValue(s);
165 }
166
167 @Override
168 public final String[] getValueNames() {
169 return wrapped.getValueNames();
170 }
171
172 @Override
173 public final Certificate[] getPeerCertificates() throws SSLPeerUnverifiedException {
174 return wrapped.getPeerCertificates();
175 }
176
177 @Override
178 public final Certificate[] getLocalCertificates() {
179 return wrapped.getLocalCertificates();
180 }
181
182 @Override
183 public final X509Certificate[] getPeerCertificateChain() throws SSLPeerUnverifiedException {
184 return wrapped.getPeerCertificateChain();
185 }
186
187 @Override
188 public final Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
189 return wrapped.getPeerPrincipal();
190 }
191
192 @Override
193 public final Principal getLocalPrincipal() {
194 return wrapped.getLocalPrincipal();
195 }
196
197 @Override
198 public final String getCipherSuite() {
199 return wrapped.getCipherSuite();
200 }
201
202 @Override
203 public String getProtocol() {
204 return wrapped.getProtocol();
205 }
206
207 @Override
208 public final String getPeerHost() {
209 return wrapped.getPeerHost();
210 }
211
212 @Override
213 public final int getPeerPort() {
214 return wrapped.getPeerPort();
215 }
216
217 @Override
218 public final int getPacketBufferSize() {
219 return wrapped.getPacketBufferSize();
220 }
221
222 @Override
223 public final int getApplicationBufferSize() {
224 return wrapped.getApplicationBufferSize();
225 }
226
227 private final class SSLSessionBindingListenerDecorator implements SSLSessionBindingListener {
228
229 final SSLSessionBindingListener delegate;
230
231 SSLSessionBindingListenerDecorator(SSLSessionBindingListener delegate) {
232 this.delegate = delegate;
233 }
234
235 @Override
236 public void valueBound(SSLSessionBindingEvent event) {
237 delegate.valueBound(new SSLSessionBindingEvent(ExtendedOpenSslSession.this, event.getName()));
238 }
239
240 @Override
241 public void valueUnbound(SSLSessionBindingEvent event) {
242 delegate.valueUnbound(new SSLSessionBindingEvent(ExtendedOpenSslSession.this, event.getName()));
243 }
244 }
245
246 @Override
247 public void handshakeFinished(byte[] id, String cipher, String protocol, byte[] peerCertificate,
248 byte[][] peerCertificateChain, long creationTime, long timeout) throws SSLException {
249 wrapped.handshakeFinished(id, cipher, protocol, peerCertificate, peerCertificateChain, creationTime, timeout);
250 }
251
252 @Override
253 public boolean equals(Object o) {
254 return wrapped.equals(o);
255 }
256
257 @Override
258 public int hashCode() {
259 return wrapped.hashCode();
260 }
261
262 @Override
263 public String toString() {
264 return "ExtendedOpenSslSession{" +
265 "wrapped=" + wrapped +
266 '}';
267 }
268 }