Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1163)

Side by Side Diff: webrtc/base/opensslstreamadapter.h

Issue 2163683003: Relanding: Allow the DTLS fingerprint verification to occur after the handshake. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing comment grammar. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/base/opensslstreamadapter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 class OpenSSLStreamAdapter : public SSLStreamAdapter { 57 class OpenSSLStreamAdapter : public SSLStreamAdapter {
58 public: 58 public:
59 explicit OpenSSLStreamAdapter(StreamInterface* stream); 59 explicit OpenSSLStreamAdapter(StreamInterface* stream);
60 ~OpenSSLStreamAdapter() override; 60 ~OpenSSLStreamAdapter() override;
61 61
62 void SetIdentity(SSLIdentity* identity) override; 62 void SetIdentity(SSLIdentity* identity) override;
63 63
64 // Default argument is for compatibility 64 // Default argument is for compatibility
65 void SetServerRole(SSLRole role = SSL_SERVER) override; 65 void SetServerRole(SSLRole role = SSL_SERVER) override;
66 bool SetPeerCertificateDigest(const std::string& digest_alg, 66 bool SetPeerCertificateDigest(
67 const unsigned char* digest_val, 67 const std::string& digest_alg,
68 size_t digest_len) override; 68 const unsigned char* digest_val,
69 size_t digest_len,
70 SSLPeerCertificateDigestError* error = nullptr) override;
69 71
70 std::unique_ptr<SSLCertificate> GetPeerCertificate() const override; 72 std::unique_ptr<SSLCertificate> GetPeerCertificate() const override;
71 73
72 // Goes from state SSL_NONE to either SSL_CONNECTING or SSL_WAIT, depending 74 // Goes from state SSL_NONE to either SSL_CONNECTING or SSL_WAIT, depending
73 // on whether the underlying stream is already open or not. 75 // on whether the underlying stream is already open or not.
74 int StartSSL() override; 76 int StartSSL() override;
75 void SetMode(SSLMode mode) override; 77 void SetMode(SSLMode mode) override;
76 void SetMaxProtocolVersion(SSLProtocolVersion version) override; 78 void SetMaxProtocolVersion(SSLProtocolVersion version) override;
77 79
78 StreamResult Read(void* data, 80 StreamResult Read(void* data,
(...skipping 19 matching lines...) Expand all
98 const uint8_t* context, 100 const uint8_t* context,
99 size_t context_len, 101 size_t context_len,
100 bool use_context, 102 bool use_context,
101 uint8_t* result, 103 uint8_t* result,
102 size_t result_len) override; 104 size_t result_len) override;
103 105
104 // DTLS-SRTP interface 106 // DTLS-SRTP interface
105 bool SetDtlsSrtpCryptoSuites(const std::vector<int>& crypto_suites) override; 107 bool SetDtlsSrtpCryptoSuites(const std::vector<int>& crypto_suites) override;
106 bool GetDtlsSrtpCryptoSuite(int* crypto_suite) override; 108 bool GetDtlsSrtpCryptoSuite(int* crypto_suite) override;
107 109
110 bool IsTlsConnected() override;
111
108 // Capabilities interfaces 112 // Capabilities interfaces
109 static bool HaveDtls(); 113 static bool HaveDtls();
110 static bool HaveDtlsSrtp(); 114 static bool HaveDtlsSrtp();
111 static bool HaveExporter(); 115 static bool HaveExporter();
112 static bool IsBoringSsl(); 116 static bool IsBoringSsl();
113 117
114 static bool IsAcceptableCipher(int cipher, KeyType key_type); 118 static bool IsAcceptableCipher(int cipher, KeyType key_type);
115 static bool IsAcceptableCipher(const std::string& cipher, KeyType key_type); 119 static bool IsAcceptableCipher(const std::string& cipher, KeyType key_type);
116 120
117 protected: 121 protected:
(...skipping 22 matching lines...) Expand all
140 int BeginSSL(); 144 int BeginSSL();
141 // Perform SSL negotiation steps. 145 // Perform SSL negotiation steps.
142 int ContinueSSL(); 146 int ContinueSSL();
143 147
144 // Error handler helper. signal is given as true for errors in 148 // Error handler helper. signal is given as true for errors in
145 // asynchronous contexts (when an error method was not returned 149 // asynchronous contexts (when an error method was not returned
146 // through some other method), and in that case an SE_CLOSE event is 150 // through some other method), and in that case an SE_CLOSE event is
147 // raised on the stream with the specified error. 151 // raised on the stream with the specified error.
148 // A 0 error means a graceful close, otherwise there is not really enough 152 // A 0 error means a graceful close, otherwise there is not really enough
149 // context to interpret the error code. 153 // context to interpret the error code.
150 void Error(const char* context, int err, bool signal); 154 // |alert| indicates an alert description (one of the SSL_AD constants) to
151 void Cleanup(); 155 // send to the remote endpoint when closing the association. If 0, a normal
156 // shutdown will be performed.
157 void Error(const char* context, int err, uint8_t alert, bool signal);
158 void Cleanup(uint8_t alert);
152 159
153 // Override MessageHandler 160 // Override MessageHandler
154 void OnMessage(Message* msg) override; 161 void OnMessage(Message* msg) override;
155 162
156 // Flush the input buffers by reading left bytes (for DTLS) 163 // Flush the input buffers by reading left bytes (for DTLS)
157 void FlushInput(unsigned int left); 164 void FlushInput(unsigned int left);
158 165
159 // SSL library configuration 166 // SSL library configuration
160 SSL_CTX* SetupSSLContext(); 167 SSL_CTX* SetupSSLContext();
161 // SSL verification check 168 // Verify the peer certificate matches the signaled digest.
162 bool SSLPostConnectionCheck(SSL* ssl, 169 bool VerifyPeerCertificate();
163 const X509* peer_cert,
164 const std::string& peer_digest);
165 // SSL certification verification error handler, called back from 170 // SSL certification verification error handler, called back from
166 // the openssl library. Returns an int interpreted as a boolean in 171 // the openssl library. Returns an int interpreted as a boolean in
167 // the C style: zero means verification failure, non-zero means 172 // the C style: zero means verification failure, non-zero means
168 // passed. 173 // passed.
169 static int SSLVerifyCallback(int ok, X509_STORE_CTX* store); 174 static int SSLVerifyCallback(int ok, X509_STORE_CTX* store);
170 175
176 bool waiting_to_verify_peer_certificate() const {
177 return client_auth_enabled() && !peer_certificate_verified_;
178 }
179
180 bool has_peer_certificate_digest() const {
181 return !peer_certificate_digest_algorithm_.empty() &&
182 !peer_certificate_digest_value_.empty();
183 }
184
171 SSLState state_; 185 SSLState state_;
172 SSLRole role_; 186 SSLRole role_;
173 int ssl_error_code_; // valid when state_ == SSL_ERROR or SSL_CLOSED 187 int ssl_error_code_; // valid when state_ == SSL_ERROR or SSL_CLOSED
174 // Whether the SSL negotiation is blocked on needing to read or 188 // Whether the SSL negotiation is blocked on needing to read or
175 // write to the wrapped stream. 189 // write to the wrapped stream.
176 bool ssl_read_needs_write_; 190 bool ssl_read_needs_write_;
177 bool ssl_write_needs_read_; 191 bool ssl_write_needs_read_;
178 192
179 SSL* ssl_; 193 SSL* ssl_;
180 SSL_CTX* ssl_ctx_; 194 SSL_CTX* ssl_ctx_;
181 195
182 // Our key and certificate. 196 // Our key and certificate.
183 std::unique_ptr<OpenSSLIdentity> identity_; 197 std::unique_ptr<OpenSSLIdentity> identity_;
184 // The certificate that the peer presented. Initially null, until the 198 // The certificate that the peer presented. Initially null, until the
185 // connection is established. 199 // connection is established.
186 std::unique_ptr<OpenSSLCertificate> peer_certificate_; 200 std::unique_ptr<OpenSSLCertificate> peer_certificate_;
201 bool peer_certificate_verified_ = false;
187 // The digest of the certificate that the peer must present. 202 // The digest of the certificate that the peer must present.
188 Buffer peer_certificate_digest_value_; 203 Buffer peer_certificate_digest_value_;
189 std::string peer_certificate_digest_algorithm_; 204 std::string peer_certificate_digest_algorithm_;
190 205
191 // The DtlsSrtp ciphers 206 // The DtlsSrtp ciphers
192 std::string srtp_ciphers_; 207 std::string srtp_ciphers_;
193 208
194 // Do DTLS or not 209 // Do DTLS or not
195 SSLMode ssl_mode_; 210 SSLMode ssl_mode_;
196 211
197 // Max. allowed protocol version 212 // Max. allowed protocol version
198 SSLProtocolVersion ssl_max_version_; 213 SSLProtocolVersion ssl_max_version_;
199 }; 214 };
200 215
201 ///////////////////////////////////////////////////////////////////////////// 216 /////////////////////////////////////////////////////////////////////////////
202 217
203 } // namespace rtc 218 } // namespace rtc
204 219
205 #endif // WEBRTC_BASE_OPENSSLSTREAMADAPTER_H__ 220 #endif // WEBRTC_BASE_OPENSSLSTREAMADAPTER_H__
OLDNEW
« no previous file with comments | « no previous file | webrtc/base/opensslstreamadapter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698