OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 99 |
100 enum SSLRole { SSL_CLIENT, SSL_SERVER }; | 100 enum SSLRole { SSL_CLIENT, SSL_SERVER }; |
101 enum SSLMode { SSL_MODE_TLS, SSL_MODE_DTLS }; | 101 enum SSLMode { SSL_MODE_TLS, SSL_MODE_DTLS }; |
102 enum SSLProtocolVersion { | 102 enum SSLProtocolVersion { |
103 SSL_PROTOCOL_TLS_10, | 103 SSL_PROTOCOL_TLS_10, |
104 SSL_PROTOCOL_TLS_11, | 104 SSL_PROTOCOL_TLS_11, |
105 SSL_PROTOCOL_TLS_12, | 105 SSL_PROTOCOL_TLS_12, |
106 SSL_PROTOCOL_DTLS_10 = SSL_PROTOCOL_TLS_11, | 106 SSL_PROTOCOL_DTLS_10 = SSL_PROTOCOL_TLS_11, |
107 SSL_PROTOCOL_DTLS_12 = SSL_PROTOCOL_TLS_12, | 107 SSL_PROTOCOL_DTLS_12 = SSL_PROTOCOL_TLS_12, |
108 }; | 108 }; |
| 109 enum class SSLPeerCertificateDigestError { |
| 110 NONE, |
| 111 UNKNOWN_ALGORITHM, |
| 112 INVALID_LENGTH, |
| 113 VERIFICATION_FAILED, |
| 114 }; |
109 | 115 |
110 // Errors for Read -- in the high range so no conflict with OpenSSL. | 116 // Errors for Read -- in the high range so no conflict with OpenSSL. |
111 enum { SSE_MSG_TRUNC = 0xff0001 }; | 117 enum { SSE_MSG_TRUNC = 0xff0001 }; |
112 | 118 |
113 // Used to send back UMA histogram value. Logged when Dtls handshake fails. | 119 // Used to send back UMA histogram value. Logged when Dtls handshake fails. |
114 enum class SSLHandshakeError { UNKNOWN, INCOMPATIBLE_CIPHERSUITE, MAX_VALUE }; | 120 enum class SSLHandshakeError { UNKNOWN, INCOMPATIBLE_CIPHERSUITE, MAX_VALUE }; |
115 | 121 |
116 class SSLStreamAdapter : public StreamAdapterInterface { | 122 class SSLStreamAdapter : public StreamAdapterInterface { |
117 public: | 123 public: |
118 // Instantiate an SSLStreamAdapter wrapping the given stream, | 124 // Instantiate an SSLStreamAdapter wrapping the given stream, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 // asynchronously. In that case, the exposed stream will open after | 172 // asynchronously. In that case, the exposed stream will open after |
167 // successful negotiation and verification, or an SE_CLOSE event will be | 173 // successful negotiation and verification, or an SE_CLOSE event will be |
168 // raised if negotiation fails. | 174 // raised if negotiation fails. |
169 virtual int StartSSL() = 0; | 175 virtual int StartSSL() = 0; |
170 | 176 |
171 // Specify the digest of the certificate that our peer is expected to use. | 177 // Specify the digest of the certificate that our peer is expected to use. |
172 // Only this certificate will be accepted during SSL verification. The | 178 // Only this certificate will be accepted during SSL verification. The |
173 // certificate is assumed to have been obtained through some other secure | 179 // certificate is assumed to have been obtained through some other secure |
174 // channel (such as the signaling channel). This must specify the terminal | 180 // channel (such as the signaling channel). This must specify the terminal |
175 // certificate, not just a CA. SSLStream makes a copy of the digest value. | 181 // certificate, not just a CA. SSLStream makes a copy of the digest value. |
176 virtual bool SetPeerCertificateDigest(const std::string& digest_alg, | 182 // |
177 const unsigned char* digest_val, | 183 // Returns true if successful. |
178 size_t digest_len) = 0; | 184 // |error| is optional and provides more information about the failure. |
| 185 virtual bool SetPeerCertificateDigest( |
| 186 const std::string& digest_alg, |
| 187 const unsigned char* digest_val, |
| 188 size_t digest_len, |
| 189 SSLPeerCertificateDigestError* error = nullptr) = 0; |
179 | 190 |
180 // Retrieves the peer's X.509 certificate, if a connection has been | 191 // Retrieves the peer's X.509 certificate, if a connection has been |
181 // established. It returns the transmitted over SSL, including the entire | 192 // established. It returns the transmitted over SSL, including the entire |
182 // chain. | 193 // chain. |
183 virtual std::unique_ptr<SSLCertificate> GetPeerCertificate() const = 0; | 194 virtual std::unique_ptr<SSLCertificate> GetPeerCertificate() const = 0; |
184 | 195 |
185 // Retrieves the IANA registration id of the cipher suite used for the | 196 // Retrieves the IANA registration id of the cipher suite used for the |
186 // connection (e.g. 0x2F for "TLS_RSA_WITH_AES_128_CBC_SHA"). | 197 // connection (e.g. 0x2F for "TLS_RSA_WITH_AES_128_CBC_SHA"). |
187 virtual bool GetSslCipherSuite(int* cipher_suite); | 198 virtual bool GetSslCipherSuite(int* cipher_suite); |
188 | 199 |
(...skipping 15 matching lines...) Expand all Loading... |
204 const uint8_t* context, | 215 const uint8_t* context, |
205 size_t context_len, | 216 size_t context_len, |
206 bool use_context, | 217 bool use_context, |
207 uint8_t* result, | 218 uint8_t* result, |
208 size_t result_len); | 219 size_t result_len); |
209 | 220 |
210 // DTLS-SRTP interface | 221 // DTLS-SRTP interface |
211 virtual bool SetDtlsSrtpCryptoSuites(const std::vector<int>& crypto_suites); | 222 virtual bool SetDtlsSrtpCryptoSuites(const std::vector<int>& crypto_suites); |
212 virtual bool GetDtlsSrtpCryptoSuite(int* crypto_suite); | 223 virtual bool GetDtlsSrtpCryptoSuite(int* crypto_suite); |
213 | 224 |
| 225 // Returns true if a TLS connection has been established. |
| 226 // The only difference between this and "GetState() == SE_OPEN" is that if |
| 227 // the peer certificate digest hasn't been verified, the state will still be |
| 228 // SS_OPENING but IsTlsConnected should return true. |
| 229 virtual bool IsTlsConnected() = 0; |
| 230 |
214 // Capabilities testing | 231 // Capabilities testing |
215 static bool HaveDtls(); | 232 static bool HaveDtls(); |
216 static bool HaveDtlsSrtp(); | 233 static bool HaveDtlsSrtp(); |
217 static bool HaveExporter(); | 234 static bool HaveExporter(); |
218 static bool IsBoringSsl(); | 235 static bool IsBoringSsl(); |
219 | 236 |
220 // Returns true iff the supplied cipher is deemed to be strong. | 237 // Returns true iff the supplied cipher is deemed to be strong. |
221 // TODO(torbjorng): Consider removing the KeyType argument. | 238 // TODO(torbjorng): Consider removing the KeyType argument. |
222 static bool IsAcceptableCipher(int cipher, KeyType key_type); | 239 static bool IsAcceptableCipher(int cipher, KeyType key_type); |
223 static bool IsAcceptableCipher(const std::string& cipher, KeyType key_type); | 240 static bool IsAcceptableCipher(const std::string& cipher, KeyType key_type); |
(...skipping 13 matching lines...) Expand all Loading... |
237 | 254 |
238 // If true (default), the client is required to provide a certificate during | 255 // If true (default), the client is required to provide a certificate during |
239 // handshake. If no certificate is given, handshake fails. This applies to | 256 // handshake. If no certificate is given, handshake fails. This applies to |
240 // server mode only. | 257 // server mode only. |
241 bool client_auth_enabled_; | 258 bool client_auth_enabled_; |
242 }; | 259 }; |
243 | 260 |
244 } // namespace rtc | 261 } // namespace rtc |
245 | 262 |
246 #endif // WEBRTC_BASE_SSLSTREAMADAPTER_H_ | 263 #endif // WEBRTC_BASE_SSLSTREAMADAPTER_H_ |
OLD | NEW |