OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/ssl/openssl_ssl_util.h" | 5 #include "net/ssl/openssl_ssl_util.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <openssl/err.h> | 8 #include <openssl/err.h> |
9 #include <openssl/ssl.h> | 9 #include <openssl/ssl.h> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/location.h" | 14 #include "base/location.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "crypto/openssl_util.h" | 17 #include "crypto/openssl_util.h" |
18 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
19 #include "net/ssl/ssl_connection_status_flags.h" | |
19 | 20 |
20 namespace net { | 21 namespace net { |
21 | 22 |
22 SslSetClearMask::SslSetClearMask() | 23 SslSetClearMask::SslSetClearMask() |
23 : set_mask(0), | 24 : set_mask(0), |
24 clear_mask(0) { | 25 clear_mask(0) { |
25 } | 26 } |
26 | 27 |
27 void SslSetClearMask::ConfigureFlag(long flag, bool state) { | 28 void SslSetClearMask::ConfigureFlag(long flag, bool state) { |
28 (state ? set_mask : clear_mask) |= flag; | 29 (state ? set_mask : clear_mask) |= flag; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 } | 199 } |
199 | 200 |
200 NetLog::ParametersCallback CreateNetLogOpenSSLErrorCallback( | 201 NetLog::ParametersCallback CreateNetLogOpenSSLErrorCallback( |
201 int net_error, | 202 int net_error, |
202 int ssl_error, | 203 int ssl_error, |
203 const OpenSSLErrorInfo& error_info) { | 204 const OpenSSLErrorInfo& error_info) { |
204 return base::Bind(&NetLogOpenSSLErrorCallback, | 205 return base::Bind(&NetLogOpenSSLErrorCallback, |
205 net_error, ssl_error, error_info); | 206 net_error, ssl_error, error_info); |
206 } | 207 } |
207 | 208 |
209 void FreeX509Stack(STACK_OF(X509)* ptr) { | |
210 sk_X509_pop_free(ptr, X509_free); | |
211 } | |
212 | |
213 void FreeX509NameStack(STACK_OF(X509_NAME)* ptr) { | |
214 sk_X509_NAME_pop_free(ptr, X509_NAME_free); | |
215 } | |
216 | |
217 // Returns the net SSL version number (see ssl_connection_status_flags.h) for | |
218 // this SSL connection. | |
davidben
2016/01/25 20:56:11
Already in the header file.
ryanchung
2016/01/29 23:22:14
Done. Removed.
| |
219 int GetNetSSLVersion(SSL* ssl) { | |
220 switch (SSL_version(ssl)) { | |
221 case TLS1_VERSION: | |
222 return SSL_CONNECTION_VERSION_TLS1; | |
223 case TLS1_1_VERSION: | |
224 return SSL_CONNECTION_VERSION_TLS1_1; | |
225 case TLS1_2_VERSION: | |
226 return SSL_CONNECTION_VERSION_TLS1_2; | |
227 default: | |
228 NOTREACHED(); | |
229 return SSL_CONNECTION_VERSION_UNKNOWN; | |
230 } | |
231 } | |
232 | |
233 ScopedX509 OSCertHandleToOpenSSL(X509Certificate::OSCertHandle os_handle) { | |
234 #if defined(USE_OPENSSL_CERTS) | |
235 return ScopedX509(X509Certificate::DupOSCertHandle(os_handle)); | |
236 #else // !defined(USE_OPENSSL_CERTS) | |
237 std::string der_encoded; | |
238 if (!X509Certificate::GetDEREncoded(os_handle, &der_encoded)) | |
239 return ScopedX509(); | |
240 const uint8_t* bytes = reinterpret_cast<const uint8_t*>(der_encoded.data()); | |
241 return ScopedX509(d2i_X509(NULL, &bytes, der_encoded.size())); | |
242 #endif // defined(USE_OPENSSL_CERTS) | |
243 } | |
244 | |
245 ScopedX509_STACK OSCertHandlesToOpenSSL( | |
246 const X509Certificate::OSCertHandles& os_handles) { | |
247 ScopedX509_STACK stack(sk_X509_new_null()); | |
248 for (size_t i = 0; i < os_handles.size(); i++) { | |
249 ScopedX509 x509 = OSCertHandleToOpenSSL(os_handles[i]); | |
250 if (!x509) | |
251 return ScopedX509_STACK(); | |
252 sk_X509_push(stack.get(), x509.release()); | |
253 } | |
254 return stack; | |
255 } | |
208 } // namespace net | 256 } // namespace net |
OLD | NEW |