OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/base/cert_test_util.h" | 5 #include "net/base/cert_test_util.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #if defined(USE_NSS) | 9 #if defined(USE_NSS) |
10 #include <cert.h> | 10 #include <cert.h> |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 return NULL; | 48 return NULL; |
49 } | 49 } |
50 | 50 |
51 rv = CERT_ChangeCertTrust(CERT_GetDefaultCertDB(), cert, &trust); | 51 rv = CERT_ChangeCertTrust(CERT_GetDefaultCertDB(), cert, &trust); |
52 if (rv != SECSuccess) { | 52 if (rv != SECSuccess) { |
53 LOG(ERROR) << "Can't change trust for certificate " << filename.value(); | 53 LOG(ERROR) << "Can't change trust for certificate " << filename.value(); |
54 CERT_DestroyCertificate(cert); | 54 CERT_DestroyCertificate(cert); |
55 return NULL; | 55 return NULL; |
56 } | 56 } |
57 | 57 |
58 return X509Certificate::CreateFromHandle(cert, | 58 X509Certificate* result = X509Certificate::CreateFromHandle( |
| 59 cert, |
59 X509Certificate::SOURCE_LONE_CERT_IMPORT, | 60 X509Certificate::SOURCE_LONE_CERT_IMPORT, |
60 X509Certificate::OSCertHandles()); | 61 X509Certificate::OSCertHandles()); |
| 62 CERT_DestroyCertificate(cert); |
| 63 return result; |
61 } | 64 } |
62 #endif | 65 #endif |
63 | 66 |
64 #if defined(OS_MACOSX) | 67 #if defined(OS_MACOSX) |
65 X509Certificate* LoadTemporaryRootCert(const FilePath& filename) { | 68 X509Certificate* LoadTemporaryRootCert(const FilePath& filename) { |
66 std::string rawcert; | 69 std::string rawcert; |
67 if (!file_util::ReadFileToString(filename, &rawcert)) { | 70 if (!file_util::ReadFileToString(filename, &rawcert)) { |
68 LOG(ERROR) << "Can't load certificate " << filename.value(); | 71 LOG(ERROR) << "Can't load certificate " << filename.value(); |
69 return NULL; | 72 return NULL; |
70 } | 73 } |
(...skipping 11 matching lines...) Expand all Loading... |
82 if (SecKeychainItemImport(pem, NULL, &input_format, &item_type, 0, NULL, NULL, | 85 if (SecKeychainItemImport(pem, NULL, &input_format, &item_type, 0, NULL, NULL, |
83 &cert_array)) | 86 &cert_array)) |
84 return NULL; | 87 return NULL; |
85 scoped_cftyperef<CFArrayRef> scoped_cert_array(cert_array); | 88 scoped_cftyperef<CFArrayRef> scoped_cert_array(cert_array); |
86 | 89 |
87 if (!CFArrayGetCount(cert_array)) | 90 if (!CFArrayGetCount(cert_array)) |
88 return NULL; | 91 return NULL; |
89 | 92 |
90 SecCertificateRef cert_ref = static_cast<SecCertificateRef>( | 93 SecCertificateRef cert_ref = static_cast<SecCertificateRef>( |
91 const_cast<void*>(CFArrayGetValueAtIndex(cert_array, 0))); | 94 const_cast<void*>(CFArrayGetValueAtIndex(cert_array, 0))); |
92 CFRetain(cert_ref); | 95 |
93 return X509Certificate::CreateFromHandle(cert_ref, | 96 return X509Certificate::CreateFromHandle(cert_ref, |
94 X509Certificate::SOURCE_LONE_CERT_IMPORT, | 97 X509Certificate::SOURCE_LONE_CERT_IMPORT, |
95 X509Certificate::OSCertHandles()); | 98 X509Certificate::OSCertHandles()); |
96 } | 99 } |
97 #endif | 100 #endif |
98 | 101 |
99 } // namespace net | 102 } // namespace net |
OLD | NEW |