1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.handler.ssl;
17
18 import io.netty.internal.tcnative.SSL;
19
20 import javax.net.ssl.KeyManagerFactory;
21 import javax.net.ssl.SSLException;
22 import javax.net.ssl.TrustManagerFactory;
23 import java.security.PrivateKey;
24 import java.security.cert.X509Certificate;
25 import java.util.Map;
26
27 import static io.netty5.handler.ssl.ReferenceCountedOpenSslServerContext.newSessionContext;
28
29
30
31
32
33
34 final class OpenSslServerContext extends OpenSslContext {
35 private final OpenSslServerSessionContext sessionContext;
36
37 OpenSslServerContext(
38 X509Certificate[] trustCertCollection, TrustManagerFactory trustManagerFactory,
39 X509Certificate[] keyCertChain, PrivateKey key, String keyPassword, KeyManagerFactory keyManagerFactory,
40 Iterable<String> ciphers, CipherSuiteFilter cipherFilter, ApplicationProtocolConfig apn,
41 long sessionCacheSize, long sessionTimeout, ClientAuth clientAuth, String[] protocols, boolean startTls,
42 boolean enableOcsp, String keyStore, Map.Entry<SslContextOption<?>, Object>... options)
43 throws SSLException {
44 this(trustCertCollection, trustManagerFactory, keyCertChain, key, keyPassword, keyManagerFactory, ciphers,
45 cipherFilter, toNegotiator(apn), sessionCacheSize, sessionTimeout, clientAuth, protocols, startTls,
46 enableOcsp, keyStore, options);
47 }
48
49 @SuppressWarnings("deprecation")
50 private OpenSslServerContext(
51 X509Certificate[] trustCertCollection, TrustManagerFactory trustManagerFactory,
52 X509Certificate[] keyCertChain, PrivateKey key, String keyPassword, KeyManagerFactory keyManagerFactory,
53 Iterable<String> ciphers, CipherSuiteFilter cipherFilter, OpenSslApplicationProtocolNegotiator apn,
54 long sessionCacheSize, long sessionTimeout, ClientAuth clientAuth, String[] protocols, boolean startTls,
55 boolean enableOcsp, String keyStore, Map.Entry<SslContextOption<?>, Object>... options)
56 throws SSLException {
57 super(ciphers, cipherFilter, apn, SSL.SSL_MODE_SERVER, keyCertChain,
58 clientAuth, protocols, startTls, enableOcsp, options);
59
60 boolean success = false;
61 try {
62 OpenSslKeyMaterialProvider.validateKeyMaterialSupported(keyCertChain, key, keyPassword);
63 sessionContext = newSessionContext(this, ctx, engineMap, trustCertCollection, trustManagerFactory,
64 keyCertChain, key, keyPassword, keyManagerFactory, keyStore,
65 sessionCacheSize, sessionTimeout);
66 success = true;
67 } finally {
68 if (!success) {
69 release();
70 }
71 }
72 }
73
74 @Override
75 public OpenSslServerSessionContext sessionContext() {
76 return sessionContext;
77 }
78 }