OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/cert_verify_proc_ios.h" | 5 #include "net/cert/cert_verify_proc_ios.h" |
6 | 6 |
7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
8 #include <Security/Security.h> | 8 #include <Security/Security.h> |
9 | 9 |
10 #include "base/mac/scoped_cftyperef.h" | 10 #include "base/mac/scoped_cftyperef.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "net/cert/x509_certificate.h" | 12 #include "net/cert/x509_certificate.h" |
| 13 #include "net/cert/x509_util_ios_and_mac.h" |
13 #include "net/test/cert_test_util.h" | 14 #include "net/test/cert_test_util.h" |
14 #include "net/test/test_data_directory.h" | 15 #include "net/test/test_data_directory.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // Creates new SecTrustRef object backed up by cert from |cert_file|. | 20 // Creates new SecTrustRef object backed up by cert from |cert_file|. |
20 base::ScopedCFTypeRef<SecTrustRef> CreateSecTrust( | 21 base::ScopedCFTypeRef<SecTrustRef> CreateSecTrust( |
21 const std::string& cert_file) { | 22 const std::string& cert_file) { |
22 base::ScopedCFTypeRef<SecTrustRef> scoped_result; | 23 base::ScopedCFTypeRef<SecTrustRef> scoped_result; |
23 | 24 |
24 scoped_refptr<net::X509Certificate> cert = | 25 scoped_refptr<net::X509Certificate> cert = |
25 net::ImportCertFromFile(net::GetTestCertsDirectory(), cert_file); | 26 net::ImportCertFromFile(net::GetTestCertsDirectory(), cert_file); |
| 27 if (!cert) { |
| 28 ADD_FAILURE(); |
| 29 return scoped_result; |
| 30 } |
26 base::ScopedCFTypeRef<CFMutableArrayRef> certs( | 31 base::ScopedCFTypeRef<CFMutableArrayRef> certs( |
27 CFArrayCreateMutable(kCFAllocatorDefault, 1, &kCFTypeArrayCallBacks)); | 32 net::x509_util::CreateSecCertificateArrayForX509Certificate(cert.get())); |
28 CFArrayAppendValue(certs, cert->os_cert_handle()); | 33 if (!certs) { |
| 34 ADD_FAILURE(); |
| 35 return scoped_result; |
| 36 } |
29 | 37 |
30 base::ScopedCFTypeRef<SecPolicyRef> policy( | 38 base::ScopedCFTypeRef<SecPolicyRef> policy( |
31 SecPolicyCreateSSL(TRUE, CFSTR("chromium.org"))); | 39 SecPolicyCreateSSL(TRUE, CFSTR("chromium.org"))); |
32 SecTrustRef result = nullptr; | 40 SecTrustRef result = nullptr; |
33 if (SecTrustCreateWithCertificates(certs, policy, &result) == errSecSuccess) { | 41 if (SecTrustCreateWithCertificates(certs.get(), policy, &result) == |
| 42 errSecSuccess) { |
34 scoped_result.reset(result); | 43 scoped_result.reset(result); |
35 } | 44 } |
36 return scoped_result; | 45 return scoped_result; |
37 } | 46 } |
38 | 47 |
39 } // namespace | 48 } // namespace |
40 | 49 |
41 namespace net { | 50 namespace net { |
42 | 51 |
43 // Tests |GetCertFailureStatusFromTrust| with null trust object. | 52 // Tests |GetCertFailureStatusFromTrust| with null trust object. |
(...skipping 19 matching lines...) Expand all Loading... |
63 ASSERT_TRUE(trust); | 72 ASSERT_TRUE(trust); |
64 SecTrustEvaluate(trust, nullptr); | 73 SecTrustEvaluate(trust, nullptr); |
65 | 74 |
66 CertStatus status = CertVerifyProcIOS::GetCertFailureStatusFromTrust(trust); | 75 CertStatus status = CertVerifyProcIOS::GetCertFailureStatusFromTrust(trust); |
67 EXPECT_TRUE(status & CERT_STATUS_COMMON_NAME_INVALID); | 76 EXPECT_TRUE(status & CERT_STATUS_COMMON_NAME_INVALID); |
68 EXPECT_TRUE(status & CERT_STATUS_AUTHORITY_INVALID); | 77 EXPECT_TRUE(status & CERT_STATUS_AUTHORITY_INVALID); |
69 EXPECT_TRUE(status & CERT_STATUS_DATE_INVALID); | 78 EXPECT_TRUE(status & CERT_STATUS_DATE_INVALID); |
70 } | 79 } |
71 | 80 |
72 } // namespace net | 81 } // namespace net |
OLD | NEW |