| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/cert/test_root_certs.h" | 5 #include "net/cert/test_root_certs.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/numerics/safe_conversions.h" |
| 11 #include "base/win/win_util.h" | 12 #include "base/win/win_util.h" |
| 12 #include "net/cert/x509_certificate.h" | 13 #include "net/cert/x509_certificate.h" |
| 13 | 14 |
| 14 namespace net { | 15 namespace net { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 // Provides a CertDllOpenStoreProv callback provider function, to be called | 19 // Provides a CertDllOpenStoreProv callback provider function, to be called |
| 19 // by CertOpenStore when the CERT_STORE_PROV_SYSTEM_W store is opened. See | 20 // by CertOpenStore when the CERT_STORE_PROV_SYSTEM_W store is opened. See |
| 20 // http://msdn.microsoft.com/en-us/library/aa376043(VS.85).aspx. | 21 // http://msdn.microsoft.com/en-us/library/aa376043(VS.85).aspx. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 } | 136 } |
| 136 | 137 |
| 137 } // namespace | 138 } // namespace |
| 138 | 139 |
| 139 bool TestRootCerts::Add(X509Certificate* certificate) { | 140 bool TestRootCerts::Add(X509Certificate* certificate) { |
| 140 // Ensure that the default CryptoAPI functionality has been intercepted. | 141 // Ensure that the default CryptoAPI functionality has been intercepted. |
| 141 // If a test certificate is never added, then no interception should | 142 // If a test certificate is never added, then no interception should |
| 142 // happen. | 143 // happen. |
| 143 g_capi_injector.Get(); | 144 g_capi_injector.Get(); |
| 144 | 145 |
| 145 BOOL ok = CertAddCertificateContextToStore( | 146 std::string der_cert; |
| 146 temporary_roots_, certificate->os_cert_handle(), | 147 X509Certificate::GetDEREncoded(certificate->os_cert_handle(), &der_cert); |
| 147 CERT_STORE_ADD_NEW, NULL); | 148 BOOL ok = CertAddEncodedCertificateToStore( |
| 149 temporary_roots_, X509_ASN_ENCODING, |
| 150 reinterpret_cast<const BYTE*>(der_cert.data()), |
| 151 base::checked_cast<DWORD>(der_cert.size()), CERT_STORE_ADD_NEW, NULL); |
| 148 if (!ok) { | 152 if (!ok) { |
| 149 // If the certificate is already added, return successfully. | 153 // If the certificate is already added, return successfully. |
| 150 return GetLastError() == static_cast<DWORD>(CRYPT_E_EXISTS); | 154 return GetLastError() == static_cast<DWORD>(CRYPT_E_EXISTS); |
| 151 } | 155 } |
| 152 | 156 |
| 153 empty_ = false; | 157 empty_ = false; |
| 154 return true; | 158 return true; |
| 155 } | 159 } |
| 156 | 160 |
| 157 void TestRootCerts::Clear() { | 161 void TestRootCerts::Clear() { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 207 |
| 204 void TestRootCerts::Init() { | 208 void TestRootCerts::Init() { |
| 205 empty_ = true; | 209 empty_ = true; |
| 206 temporary_roots_ = CertOpenStore( | 210 temporary_roots_ = CertOpenStore( |
| 207 CERT_STORE_PROV_MEMORY, 0, NULL, | 211 CERT_STORE_PROV_MEMORY, 0, NULL, |
| 208 CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG, NULL); | 212 CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG, NULL); |
| 209 DCHECK(temporary_roots_); | 213 DCHECK(temporary_roots_); |
| 210 } | 214 } |
| 211 | 215 |
| 212 } // namespace net | 216 } // namespace net |
| OLD | NEW |