| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/cert/test_root_certs.h" | |
| 6 | |
| 7 #include "base/location.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "crypto/openssl_util.h" | |
| 10 #include "net/cert/x509_certificate.h" | |
| 11 #include "third_party/boringssl/src/include/openssl/err.h" | |
| 12 #include "third_party/boringssl/src/include/openssl/x509v3.h" | |
| 13 | |
| 14 namespace net { | |
| 15 | |
| 16 bool TestRootCerts::Add(X509Certificate* certificate) { | |
| 17 if (!X509_STORE_add_cert(X509Certificate::cert_store(), | |
| 18 certificate->os_cert_handle())) { | |
| 19 uint32_t error_code = ERR_peek_error(); | |
| 20 if (ERR_GET_LIB(error_code) != ERR_LIB_X509 || | |
| 21 ERR_GET_REASON(error_code) != X509_R_CERT_ALREADY_IN_HASH_TABLE) { | |
| 22 crypto::ClearOpenSSLERRStack(FROM_HERE); | |
| 23 return false; | |
| 24 } | |
| 25 ERR_clear_error(); | |
| 26 } | |
| 27 | |
| 28 temporary_roots_.push_back(certificate); | |
| 29 return true; | |
| 30 } | |
| 31 | |
| 32 void TestRootCerts::Clear() { | |
| 33 if (temporary_roots_.empty()) | |
| 34 return; | |
| 35 | |
| 36 temporary_roots_.clear(); | |
| 37 X509Certificate::ResetCertStore(); | |
| 38 } | |
| 39 | |
| 40 bool TestRootCerts::IsEmpty() const { | |
| 41 return temporary_roots_.empty(); | |
| 42 } | |
| 43 | |
| 44 bool TestRootCerts::Contains(X509* cert) const { | |
| 45 for (std::vector<scoped_refptr<X509Certificate> >::const_iterator it = | |
| 46 temporary_roots_.begin(); | |
| 47 it != temporary_roots_.end(); ++it) { | |
| 48 if (X509Certificate::IsSameOSCert(cert, (*it)->os_cert_handle())) | |
| 49 return true; | |
| 50 } | |
| 51 return false; | |
| 52 } | |
| 53 | |
| 54 TestRootCerts::~TestRootCerts() {} | |
| 55 | |
| 56 void TestRootCerts::Init() {} | |
| 57 | |
| 58 } // namespace net | |
| OLD | NEW |