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 | 8 |
9 #include <openssl/err.h> | 9 #include <openssl/err.h> |
10 #include <openssl/ssl.h> | 10 #include <openssl/ssl.h> |
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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 } | 233 } |
233 | 234 |
234 NetLog::ParametersCallback CreateNetLogOpenSSLErrorCallback( | 235 NetLog::ParametersCallback CreateNetLogOpenSSLErrorCallback( |
235 int net_error, | 236 int net_error, |
236 int ssl_error, | 237 int ssl_error, |
237 const OpenSSLErrorInfo& error_info) { | 238 const OpenSSLErrorInfo& error_info) { |
238 return base::Bind(&NetLogOpenSSLErrorCallback, | 239 return base::Bind(&NetLogOpenSSLErrorCallback, |
239 net_error, ssl_error, error_info); | 240 net_error, ssl_error, error_info); |
240 } | 241 } |
241 | 242 |
| 243 void FreeX509Stack(STACK_OF(X509) * ptr) { |
| 244 sk_X509_pop_free(ptr, X509_free); |
| 245 } |
| 246 |
| 247 void FreeX509NameStack(STACK_OF(X509_NAME) * ptr) { |
| 248 sk_X509_NAME_pop_free(ptr, X509_NAME_free); |
| 249 } |
| 250 |
| 251 // Returns the net SSL version number (see ssl_connection_status_flags.h) for |
| 252 // this SSL connection. |
| 253 int GetNetSSLVersion(SSL* ssl) { |
| 254 switch (SSL_version(ssl)) { |
| 255 case TLS1_VERSION: |
| 256 return SSL_CONNECTION_VERSION_TLS1; |
| 257 case TLS1_1_VERSION: |
| 258 return SSL_CONNECTION_VERSION_TLS1_1; |
| 259 case TLS1_2_VERSION: |
| 260 return SSL_CONNECTION_VERSION_TLS1_2; |
| 261 default: |
| 262 NOTREACHED(); |
| 263 return SSL_CONNECTION_VERSION_UNKNOWN; |
| 264 } |
| 265 } |
| 266 |
| 267 ScopedX509 OSCertHandleToOpenSSL(X509Certificate::OSCertHandle os_handle) { |
| 268 #if defined(USE_OPENSSL_CERTS) |
| 269 return ScopedX509(X509Certificate::DupOSCertHandle(os_handle)); |
| 270 #else // !defined(USE_OPENSSL_CERTS) |
| 271 std::string der_encoded; |
| 272 if (!X509Certificate::GetDEREncoded(os_handle, &der_encoded)) |
| 273 return ScopedX509(); |
| 274 const uint8_t* bytes = reinterpret_cast<const uint8_t*>(der_encoded.data()); |
| 275 return ScopedX509(d2i_X509(NULL, &bytes, der_encoded.size())); |
| 276 #endif // defined(USE_OPENSSL_CERTS) |
| 277 } |
| 278 |
| 279 ScopedX509_STACK OSCertHandlesToOpenSSL( |
| 280 const X509Certificate::OSCertHandles& os_handles) { |
| 281 ScopedX509_STACK stack(sk_X509_new_null()); |
| 282 for (size_t i = 0; i < os_handles.size(); i++) { |
| 283 ScopedX509 x509 = OSCertHandleToOpenSSL(os_handles[i]); |
| 284 if (!x509) |
| 285 return ScopedX509_STACK(); |
| 286 sk_X509_push(stack.get(), x509.release()); |
| 287 } |
| 288 return stack.Pass(); |
| 289 } |
| 290 |
242 } // namespace net | 291 } // namespace net |
OLD | NEW |