Chromium Code Reviews| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 const uint8_t* context, | 100 const uint8_t* context, |
| 101 size_t context_len, | 101 size_t context_len, |
| 102 bool use_context, | 102 bool use_context, |
| 103 uint8_t* result, | 103 uint8_t* result, |
| 104 size_t result_len) override; | 104 size_t result_len) override; |
| 105 | 105 |
| 106 // DTLS-SRTP interface | 106 // DTLS-SRTP interface |
| 107 bool SetDtlsSrtpCryptoSuites(const std::vector<int>& crypto_suites) override; | 107 bool SetDtlsSrtpCryptoSuites(const std::vector<int>& crypto_suites) override; |
| 108 bool GetDtlsSrtpCryptoSuite(int* crypto_suite) override; | 108 bool GetDtlsSrtpCryptoSuite(int* crypto_suite) override; |
| 109 | 109 |
| 110 bool IsTlsConnected() override { return state_ == SSL_CONNECTED; } | |
| 111 | |
| 110 // Capabilities interfaces | 112 // Capabilities interfaces |
| 111 static bool HaveDtls(); | 113 static bool HaveDtls(); |
| 112 static bool HaveDtlsSrtp(); | 114 static bool HaveDtlsSrtp(); |
| 113 static bool HaveExporter(); | 115 static bool HaveExporter(); |
| 114 static bool IsBoringSsl(); | 116 static bool IsBoringSsl(); |
| 115 | 117 |
| 116 static bool IsAcceptableCipher(int cipher, KeyType key_type); | 118 static bool IsAcceptableCipher(int cipher, KeyType key_type); |
| 117 static bool IsAcceptableCipher(const std::string& cipher, KeyType key_type); | 119 static bool IsAcceptableCipher(const std::string& cipher, KeyType key_type); |
| 118 | 120 |
| 119 protected: | 121 protected: |
| 120 void OnEvent(StreamInterface* stream, int events, int err) override; | 122 void OnEvent(StreamInterface* stream, int events, int err) override; |
| 121 | 123 |
| 122 private: | 124 private: |
| 123 enum SSLState { | 125 enum SSLState { |
| 124 // Before calling one of the StartSSL methods, data flows | 126 // Before calling one of the StartSSL methods, data flows |
| 125 // in clear text. | 127 // in clear text. |
| 126 SSL_NONE, | 128 SSL_NONE, |
| 127 SSL_WAIT, // waiting for the stream to open to start SSL negotiation | 129 SSL_WAIT, // waiting for the stream to open to start SSL negotiation |
| 128 SSL_CONNECTING, // SSL negotiation in progress | 130 SSL_CONNECTING, // SSL negotiation in progress |
| 129 SSL_CONNECTED, // SSL stream successfully established | 131 SSL_CONNECTED, // SSL stream successfully established |
| 130 SSL_ERROR, // some SSL error occurred, stream is closed | 132 SSL_ERROR, // some SSL error occurred, stream is closed |
| 131 SSL_CLOSED // Clean close | 133 SSL_CLOSED // Clean close |
| 132 }; | 134 }; |
| 133 | 135 |
| 134 enum { MSG_TIMEOUT = MSG_MAX+1}; | 136 enum { MSG_TIMEOUT = MSG_MAX+1}; |
| 135 | 137 |
| 138 enum SSLTopology { | |
|
mattdr-at-webrtc.org
2016/07/21 08:04:23
SSL really only has one topology: client-server. T
Taylor Brandstetter
2016/07/22 18:52:20
Enum dropped, as discussed.
pthatcher1
2016/07/22 18:58:27
Nothing every uses StartSSLWithServer any more, so
Taylor Brandstetter
2016/07/25 23:54:53
Can we remove StartSSLWithServer in a separate CL,
| |
| 139 TOPOLOGY_CLIENT_SERVER, | |
| 140 TOPOLOGY_PEER_TO_PEER, | |
| 141 TOPOLOGY_UNKNOWN | |
| 142 }; | |
| 143 | |
| 136 // The following three methods return 0 on success and a negative | 144 // The following three methods return 0 on success and a negative |
| 137 // error code on failure. The error code may be from OpenSSL or -1 | 145 // error code on failure. The error code may be from OpenSSL or -1 |
| 138 // on some other error cases, so it can't really be interpreted | 146 // on some other error cases, so it can't really be interpreted |
| 139 // unfortunately. | 147 // unfortunately. |
| 140 | 148 |
| 141 // Go from state SSL_NONE to either SSL_CONNECTING or SSL_WAIT, | 149 // Go from state SSL_NONE to either SSL_CONNECTING or SSL_WAIT, |
| 142 // depending on whether the underlying stream is already open or | 150 // depending on whether the underlying stream is already open or |
| 143 // not. | 151 // not. |
| 144 int StartSSL(); | 152 int StartSSL(); |
| 145 // Prepare SSL library, state is SSL_CONNECTING. | 153 // Prepare SSL library, state is SSL_CONNECTING. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 158 | 166 |
| 159 // Override MessageHandler | 167 // Override MessageHandler |
| 160 void OnMessage(Message* msg) override; | 168 void OnMessage(Message* msg) override; |
| 161 | 169 |
| 162 // Flush the input buffers by reading left bytes (for DTLS) | 170 // Flush the input buffers by reading left bytes (for DTLS) |
| 163 void FlushInput(unsigned int left); | 171 void FlushInput(unsigned int left); |
| 164 | 172 |
| 165 // SSL library configuration | 173 // SSL library configuration |
| 166 SSL_CTX* SetupSSLContext(); | 174 SSL_CTX* SetupSSLContext(); |
| 167 // SSL verification check | 175 // SSL verification check |
| 168 bool SSLPostConnectionCheck(SSL* ssl, const char* server_name, | 176 bool SSLPostConnectionCheck(); |
| 169 const X509* peer_cert, | 177 bool VerifyPeerCertificate(); |
| 170 const std::string& peer_digest); | |
| 171 // SSL certification verification error handler, called back from | 178 // SSL certification verification error handler, called back from |
| 172 // the openssl library. Returns an int interpreted as a boolean in | 179 // the openssl library. Returns an int interpreted as a boolean in |
| 173 // the C style: zero means verification failure, non-zero means | 180 // the C style: zero means verification failure, non-zero means |
| 174 // passed. | 181 // passed. |
| 175 static int SSLVerifyCallback(int ok, X509_STORE_CTX* store); | 182 static int SSLVerifyCallback(int ok, X509_STORE_CTX* store); |
| 176 | 183 |
| 184 bool waiting_to_verify_client_cert() const { | |
| 185 // If |ssl_server_name_| is non-empty we're in client/server mode and don't | |
| 186 // need to verify a peer certificate. | |
| 187 return ssl_server_name_.empty() && client_auth_enabled() && | |
|
pthatcher1
2016/07/22 18:58:27
set_client_auth_enabled() is never called by anyth
Taylor Brandstetter
2016/07/25 23:54:53
See above.
| |
| 188 !certificate_verified_; | |
| 189 } | |
| 190 | |
| 191 bool have_peer_certificate_digest() const { | |
| 192 return peer_certificate_digest_algorithm_.size() && | |
|
mattdr-at-webrtc.org
2016/07/21 08:04:23
personal preference: !xyz.empty()
Taylor Brandstetter
2016/07/22 18:52:20
rtc::Buffer didn't have an "empty" method so I add
pthatcher1
2016/07/22 18:58:27
+1
| |
| 193 peer_certificate_digest_value_.size(); | |
| 194 } | |
| 195 | |
| 177 SSLState state_; | 196 SSLState state_; |
| 178 SSLRole role_; | 197 SSLRole role_; |
| 179 int ssl_error_code_; // valid when state_ == SSL_ERROR or SSL_CLOSED | 198 int ssl_error_code_; // valid when state_ == SSL_ERROR or SSL_CLOSED |
| 180 // Whether the SSL negotiation is blocked on needing to read or | 199 // Whether the SSL negotiation is blocked on needing to read or |
| 181 // write to the wrapped stream. | 200 // write to the wrapped stream. |
| 182 bool ssl_read_needs_write_; | 201 bool ssl_read_needs_write_; |
| 183 bool ssl_write_needs_read_; | 202 bool ssl_write_needs_read_; |
| 184 | 203 |
| 185 SSL* ssl_; | 204 SSL* ssl_; |
| 186 SSL_CTX* ssl_ctx_; | 205 SSL_CTX* ssl_ctx_; |
| 187 | 206 |
| 207 SSLTopology topology_ = TOPOLOGY_UNKNOWN; | |
|
mattdr-at-webrtc.org
2016/07/21 08:04:23
It's nice to be explicit, but in a way this is dup
Taylor Brandstetter
2016/07/22 18:52:20
You're very right. I replaced every "topology" che
| |
| 188 // Our key and certificate, mostly useful in peer-to-peer mode. | 208 // Our key and certificate, mostly useful in peer-to-peer mode. |
| 189 std::unique_ptr<OpenSSLIdentity> identity_; | 209 std::unique_ptr<OpenSSLIdentity> identity_; |
| 190 // in traditional mode, the server name that the server's certificate | 210 // in traditional mode, the server name that the server's certificate |
| 191 // must specify. Empty in peer-to-peer mode. | 211 // must specify. Empty in peer-to-peer mode. |
| 192 std::string ssl_server_name_; | 212 std::string ssl_server_name_; |
|
pthatcher1
2016/07/22 18:58:27
Since this is only set by StartSSLWithServer, and
Taylor Brandstetter
2016/07/25 23:54:53
See above.
| |
| 193 // The certificate that the peer must present or did present. Initially | 213 // The certificate that the peer must present or did present. Initially |
| 194 // null in traditional mode, until the connection is established. | 214 // null in traditional mode, until the connection is established. |
| 195 std::unique_ptr<OpenSSLCertificate> peer_certificate_; | 215 std::unique_ptr<OpenSSLCertificate> peer_certificate_; |
| 196 // In peer-to-peer mode, the digest of the certificate that | 216 // In peer-to-peer mode, the digest of the certificate that |
| 197 // the peer must present. | 217 // the peer must present. |
| 198 Buffer peer_certificate_digest_value_; | 218 Buffer peer_certificate_digest_value_; |
| 199 std::string peer_certificate_digest_algorithm_; | 219 std::string peer_certificate_digest_algorithm_; |
| 220 bool certificate_verified_ = false; | |
|
pthatcher1
2016/07/22 18:58:27
Since the method that changes this is VerifyPeerCe
Taylor Brandstetter
2016/07/25 23:54:53
Done.
| |
| 200 | 221 |
| 201 // OpenSSLAdapter::custom_verify_callback_ result | 222 // OpenSSLAdapter::custom_verify_callback_ result |
|
pthatcher1
2016/07/22 18:58:27
Would it make sense to make everything "remote" as
Taylor Brandstetter
2016/07/25 23:54:53
What about the PeerConnection? :)
Anyway you're p
| |
| 202 bool custom_verification_succeeded_; | 223 bool custom_verification_succeeded_; |
| 203 | 224 |
| 204 // The DtlsSrtp ciphers | 225 // The DtlsSrtp ciphers |
| 205 std::string srtp_ciphers_; | 226 std::string srtp_ciphers_; |
| 206 | 227 |
| 207 // Do DTLS or not | 228 // Do DTLS or not |
| 208 SSLMode ssl_mode_; | 229 SSLMode ssl_mode_; |
| 209 | 230 |
| 210 // Max. allowed protocol version | 231 // Max. allowed protocol version |
| 211 SSLProtocolVersion ssl_max_version_; | 232 SSLProtocolVersion ssl_max_version_; |
| 212 }; | 233 }; |
| 213 | 234 |
| 214 ///////////////////////////////////////////////////////////////////////////// | 235 ///////////////////////////////////////////////////////////////////////////// |
| 215 | 236 |
| 216 } // namespace rtc | 237 } // namespace rtc |
| 217 | 238 |
| 218 #endif // WEBRTC_BASE_OPENSSLSTREAMADAPTER_H__ | 239 #endif // WEBRTC_BASE_OPENSSLSTREAMADAPTER_H__ |
| OLD | NEW |