| 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 <openssl/x509.h> |
| 10 #include <utility> | 11 #include <utility> |
| 11 | 12 |
| 12 #include "base/bind.h" | 13 #include "base/bind.h" |
| 13 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 14 #include "base/location.h" | 15 #include "base/location.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| 17 #include "crypto/openssl_util.h" | 18 #include "crypto/openssl_util.h" |
| 18 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 19 #include "net/ssl/ssl_connection_status_flags.h" | 20 #include "net/ssl/ssl_connection_status_flags.h" |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 case TLS1_2_VERSION: | 214 case TLS1_2_VERSION: |
| 214 return SSL_CONNECTION_VERSION_TLS1_2; | 215 return SSL_CONNECTION_VERSION_TLS1_2; |
| 215 case TLS1_3_VERSION: | 216 case TLS1_3_VERSION: |
| 216 return SSL_CONNECTION_VERSION_TLS1_3; | 217 return SSL_CONNECTION_VERSION_TLS1_3; |
| 217 default: | 218 default: |
| 218 NOTREACHED(); | 219 NOTREACHED(); |
| 219 return SSL_CONNECTION_VERSION_UNKNOWN; | 220 return SSL_CONNECTION_VERSION_UNKNOWN; |
| 220 } | 221 } |
| 221 } | 222 } |
| 222 | 223 |
| 223 ScopedX509 OSCertHandleToOpenSSL(X509Certificate::OSCertHandle os_handle) { | 224 bssl::UniquePtr<X509> OSCertHandleToOpenSSL( |
| 225 X509Certificate::OSCertHandle os_handle) { |
| 224 #if defined(USE_OPENSSL_CERTS) | 226 #if defined(USE_OPENSSL_CERTS) |
| 225 return ScopedX509(X509Certificate::DupOSCertHandle(os_handle)); | 227 return bssl::UniquePtr<X509>(X509Certificate::DupOSCertHandle(os_handle)); |
| 226 #else // !defined(USE_OPENSSL_CERTS) | 228 #else // !defined(USE_OPENSSL_CERTS) |
| 227 std::string der_encoded; | 229 std::string der_encoded; |
| 228 if (!X509Certificate::GetDEREncoded(os_handle, &der_encoded)) | 230 if (!X509Certificate::GetDEREncoded(os_handle, &der_encoded)) |
| 229 return ScopedX509(); | 231 return bssl::UniquePtr<X509>(); |
| 230 const uint8_t* bytes = reinterpret_cast<const uint8_t*>(der_encoded.data()); | 232 const uint8_t* bytes = reinterpret_cast<const uint8_t*>(der_encoded.data()); |
| 231 return ScopedX509(d2i_X509(NULL, &bytes, der_encoded.size())); | 233 return bssl::UniquePtr<X509>(d2i_X509(NULL, &bytes, der_encoded.size())); |
| 232 #endif // defined(USE_OPENSSL_CERTS) | 234 #endif // defined(USE_OPENSSL_CERTS) |
| 233 } | 235 } |
| 234 | 236 |
| 235 ScopedX509Stack OSCertHandlesToOpenSSL( | 237 bssl::UniquePtr<STACK_OF(X509)> OSCertHandlesToOpenSSL( |
| 236 const X509Certificate::OSCertHandles& os_handles) { | 238 const X509Certificate::OSCertHandles& os_handles) { |
| 237 ScopedX509Stack stack(sk_X509_new_null()); | 239 bssl::UniquePtr<STACK_OF(X509)> stack(sk_X509_new_null()); |
| 238 for (size_t i = 0; i < os_handles.size(); i++) { | 240 for (size_t i = 0; i < os_handles.size(); i++) { |
| 239 ScopedX509 x509 = OSCertHandleToOpenSSL(os_handles[i]); | 241 bssl::UniquePtr<X509> x509 = OSCertHandleToOpenSSL(os_handles[i]); |
| 240 if (!x509) | 242 if (!x509) |
| 241 return nullptr; | 243 return nullptr; |
| 242 sk_X509_push(stack.get(), x509.release()); | 244 sk_X509_push(stack.get(), x509.release()); |
| 243 } | 245 } |
| 244 return stack; | 246 return stack; |
| 245 } | 247 } |
| 246 | 248 |
| 247 } // namespace net | 249 } // namespace net |
| OLD | NEW |