blob: 7a94928c4ba7ffd964ee1cf906d236f56e32c654 [file] [log] [blame]
Diogo Real4f085432018-09-11 16:00:22 -07001/*
2 * Copyright 2018 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11package org.webrtc;
12
13import java.util.Collections;
14import java.util.List;
15import javax.annotation.Nullable;
16
17/**
18 * Java version of rtc::SSLConfig.
19 *
20 * Contains the configuration of any SSL/TLS connections that are initiated by
21 * our client.
22 */
23public class SslConfig {
24 /** Tracks rtc::TlsCertPolicy */
25 public enum TlsCertPolicy {
26 TLS_CERT_POLICY_SECURE,
27 TLS_CERT_POLICY_INSECURE_NO_CHECK,
28 }
29
30 /** Indicates whether to enable OCSP stapling in TLS. */
31 public final boolean enableOcspStapling;
32 /** Indicates whether to enable the signed certificate timestamp extension in TLS. */
33 public final boolean enableSignedCertTimestamp;
34 /** Indicates whether to enable the TLS Channel ID extension. */
35 public final boolean enableTlsChannelId;
36 /** Indicates whether to enable the TLS GREASE extension. */
37 public final boolean enableGrease;
38
39 /** Indicates how to process TURN server certificates */
40 public final TlsCertPolicy tlsCertPolicy;
41
42 /**
43 * Highest supported SSL version, as defined in the supported_versions TLS extension.
44 * If null, the default OpenSSL/BoringSSL max version will be used.
45 */
46 @Nullable public final Integer maxSslVersion;
47
48 /**
49 * List of protocols to be used in the TLS ALPN extension.
50 * If null, the default list of OpenSSL/BoringSSL ALPN protocols will be used.
51 */
52 @Nullable public final List<String> tlsAlpnProtocols;
53
54 /**
55 * List of elliptic curves to be used in the TLS elliptic curves extension.
56 * Only curve names supported by OpenSSL should be used (eg. "P-256","X25519").
57 * If null, the default list of OpenSSL/BoringSSL curves will be used.
58 */
59 @Nullable public final List<String> tlsEllipticCurves;
60
61 private SslConfig(boolean enableOcspStapling, boolean enableSignedCertTimestamp,
62 boolean enableTlsChannelId, boolean enableGrease, TlsCertPolicy tlsCertPolicy,
63 Integer maxSslVersion, List<String> tlsAlpnProtocols, List<String> tlsEllipticCurves) {
64 this.enableOcspStapling = enableOcspStapling;
65 this.enableSignedCertTimestamp = enableSignedCertTimestamp;
66 this.enableTlsChannelId = enableTlsChannelId;
67 this.enableGrease = enableGrease;
68 this.tlsCertPolicy = tlsCertPolicy;
69 this.maxSslVersion = maxSslVersion;
70 if (tlsAlpnProtocols != null) {
71 this.tlsAlpnProtocols = Collections.unmodifiableList(tlsAlpnProtocols);
72 } else {
73 this.tlsAlpnProtocols = null;
74 }
75 if (tlsEllipticCurves != null) {
76 this.tlsEllipticCurves = Collections.unmodifiableList(tlsEllipticCurves);
77 } else {
78 this.tlsEllipticCurves = null;
79 }
80 }
81
82 @Override
83 public String toString() {
84 return "[enableOcspStapling=" + enableOcspStapling + "] [enableSignedCertTimestamp="
85 + enableSignedCertTimestamp + "] [enableTlsChannelId=" + enableTlsChannelId
86 + "] [enableGrease=" + enableGrease + "] [tlsCertPolicy=" + tlsCertPolicy
87 + "] [maxSslVersion=" + maxSslVersion + "] [tlsAlpnProtocols=" + tlsAlpnProtocols
88 + "] [tlsEllipticCurves=" + tlsEllipticCurves + "]";
89 }
90
91 public static Builder builder() {
92 return new Builder();
93 }
94
95 public static class Builder {
96 private boolean enableOcspStapling;
97 private boolean enableSignedCertTimestamp;
98 private boolean enableTlsChannelId;
99 private boolean enableGrease;
100 private TlsCertPolicy tlsCertPolicy;
101 @Nullable private Integer maxSslVersion;
102 @Nullable private List<String> tlsAlpnProtocols;
103 @Nullable private List<String> tlsEllipticCurves;
104
105 private Builder() {
106 this.enableOcspStapling = true;
107 this.enableSignedCertTimestamp = true;
108 this.enableTlsChannelId = false;
109 this.enableGrease = false;
110 this.tlsCertPolicy = TlsCertPolicy.TLS_CERT_POLICY_SECURE;
111 this.maxSslVersion = null;
112 this.tlsAlpnProtocols = null;
113 this.tlsEllipticCurves = null;
114 }
115
116 public Builder setEnableOcspStapling(boolean enableOcspStapling) {
117 this.enableOcspStapling = enableOcspStapling;
118 return this;
119 }
120
121 public Builder setEnableSignedCertTimestamp(boolean enableSignedCertTimestamp) {
122 this.enableSignedCertTimestamp = enableSignedCertTimestamp;
123 return this;
124 }
125
126 public Builder setEnableTlsChannelId(boolean enableTlsChannelId) {
127 this.enableTlsChannelId = enableTlsChannelId;
128 return this;
129 }
130
131 public Builder setEnableGrease(boolean enableGrease) {
132 this.enableGrease = enableGrease;
133 return this;
134 }
135
136 public Builder setTlsCertPolicy(TlsCertPolicy tlsCertPolicy) {
137 this.tlsCertPolicy = tlsCertPolicy;
138 return this;
139 }
140
141 public Builder setMaxSslVersion(int maxSslVersion) {
142 this.maxSslVersion = maxSslVersion;
143 return this;
144 }
145
146 public Builder setTlsAlpnProtocols(List<String> tlsAlpnProtocols) {
147 this.tlsAlpnProtocols = tlsAlpnProtocols;
148 return this;
149 }
150
151 public Builder setTlsEllipticCurves(List<String> tlsEllipticCurves) {
152 this.tlsEllipticCurves = tlsEllipticCurves;
153 return this;
154 }
155
156 public SslConfig createSslConfig() {
157 return new SslConfig(enableOcspStapling, enableSignedCertTimestamp, enableTlsChannelId,
158 enableGrease, tlsCertPolicy, maxSslVersion, tlsAlpnProtocols, tlsEllipticCurves);
159 }
160 }
161
162 @CalledByNative
163 boolean getEnableOcspStapling() {
164 return enableOcspStapling;
165 }
166
167 @CalledByNative
168 boolean getEnableSignedCertTimestamp() {
169 return enableSignedCertTimestamp;
170 }
171
172 @CalledByNative
173 boolean getEnableTlsChannelId() {
174 return enableTlsChannelId;
175 }
176
177 @CalledByNative
178 boolean getEnableGrease() {
179 return enableGrease;
180 }
181
182 @CalledByNative
183 TlsCertPolicy getTlsCertPolicy() {
184 return tlsCertPolicy;
185 }
186
187 @Nullable
188 @CalledByNative
189 Integer getMaxSslVersion() {
190 return maxSslVersion;
191 }
192
193 @Nullable
194 @CalledByNative
195 List<String> getTlsAlpnProtocols() {
196 return tlsAlpnProtocols;
197 }
198
199 @Nullable
200 @CalledByNative
201 List<String> getTlsEllipticCurves() {
202 return tlsEllipticCurves;
203 }
204}