| 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/cert_verify_proc.h" | 5 #include "net/cert/cert_verify_proc.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 int flags = 0; | 1120 int flags = 0; |
| 1121 CertVerifyResult verify_result; | 1121 CertVerifyResult verify_result; |
| 1122 int error = Verify( | 1122 int error = Verify( |
| 1123 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); | 1123 cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, &verify_result); |
| 1124 EXPECT_EQ(OK, error); | 1124 EXPECT_EQ(OK, error); |
| 1125 EXPECT_EQ(0U, verify_result.cert_status); | 1125 EXPECT_EQ(0U, verify_result.cert_status); |
| 1126 // But should not be marked as a known root. | 1126 // But should not be marked as a known root. |
| 1127 EXPECT_FALSE(verify_result.is_issued_by_known_root); | 1127 EXPECT_FALSE(verify_result.is_issued_by_known_root); |
| 1128 } | 1128 } |
| 1129 | 1129 |
| 1130 #if defined(OS_MACOSX) && !defined(OS_IOS) | |
| 1131 // Tests that, on OS X, issues with a cross-certified Baltimore CyberTrust | |
| 1132 // Root can be successfully worked around once Apple completes removing the | |
| 1133 // older GTE CyberTrust Root from its trusted root store. | |
| 1134 // | |
| 1135 // The issue is caused by servers supplying the cross-certified intermediate | |
| 1136 // (necessary for certain mobile platforms), which OS X does not recognize | |
| 1137 // as already existing within its trust store. | |
| 1138 TEST_F(CertVerifyProcTest, CybertrustGTERoot) { | |
| 1139 CertificateList certs = CreateCertificateListFromFile( | |
| 1140 GetTestCertsDirectory(), | |
| 1141 "cybertrust_omniroot_chain.pem", | |
| 1142 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); | |
| 1143 ASSERT_EQ(2U, certs.size()); | |
| 1144 | |
| 1145 X509Certificate::OSCertHandles intermediates; | |
| 1146 intermediates.push_back(certs[1]->os_cert_handle()); | |
| 1147 | |
| 1148 scoped_refptr<X509Certificate> cybertrust_basic = | |
| 1149 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | |
| 1150 intermediates); | |
| 1151 ASSERT_TRUE(cybertrust_basic.get()); | |
| 1152 | |
| 1153 scoped_refptr<X509Certificate> baltimore_root = | |
| 1154 ImportCertFromFile(GetTestCertsDirectory(), | |
| 1155 "cybertrust_baltimore_root.pem"); | |
| 1156 ASSERT_TRUE(baltimore_root.get()); | |
| 1157 | |
| 1158 ScopedTestRoot scoped_root(baltimore_root.get()); | |
| 1159 | |
| 1160 // Ensure that ONLY the Baltimore CyberTrust Root is trusted. This | |
| 1161 // simulates Keychain removing support for the GTE CyberTrust Root. | |
| 1162 TestRootCerts::GetInstance()->SetAllowSystemTrust(false); | |
| 1163 base::ScopedClosureRunner reset_system_trust( | |
| 1164 base::Bind(&TestRootCerts::SetAllowSystemTrust, | |
| 1165 base::Unretained(TestRootCerts::GetInstance()), | |
| 1166 true)); | |
| 1167 | |
| 1168 // First, make sure a simple certificate chain from | |
| 1169 // EE -> Public SureServer SV -> Baltimore CyberTrust | |
| 1170 // works. Only the first two certificates are included in the chain. | |
| 1171 int flags = 0; | |
| 1172 CertVerifyResult verify_result; | |
| 1173 int error = Verify(cybertrust_basic.get(), | |
| 1174 "cacert.omniroot.com", | |
| 1175 flags, | |
| 1176 NULL, | |
| 1177 empty_cert_list_, | |
| 1178 &verify_result); | |
| 1179 EXPECT_EQ(OK, error); | |
| 1180 EXPECT_EQ(CERT_STATUS_SHA1_SIGNATURE_PRESENT, verify_result.cert_status); | |
| 1181 | |
| 1182 // Attempt to verify with the first known cross-certified intermediate | |
| 1183 // provided. | |
| 1184 scoped_refptr<X509Certificate> baltimore_intermediate_1 = | |
| 1185 ImportCertFromFile(GetTestCertsDirectory(), | |
| 1186 "cybertrust_baltimore_cross_certified_1.pem"); | |
| 1187 ASSERT_TRUE(baltimore_intermediate_1.get()); | |
| 1188 | |
| 1189 X509Certificate::OSCertHandles intermediate_chain_1 = | |
| 1190 cybertrust_basic->GetIntermediateCertificates(); | |
| 1191 intermediate_chain_1.push_back(baltimore_intermediate_1->os_cert_handle()); | |
| 1192 | |
| 1193 scoped_refptr<X509Certificate> baltimore_chain_1 = | |
| 1194 X509Certificate::CreateFromHandle(cybertrust_basic->os_cert_handle(), | |
| 1195 intermediate_chain_1); | |
| 1196 error = Verify(baltimore_chain_1.get(), | |
| 1197 "cacert.omniroot.com", | |
| 1198 flags, | |
| 1199 NULL, | |
| 1200 empty_cert_list_, | |
| 1201 &verify_result); | |
| 1202 EXPECT_EQ(OK, error); | |
| 1203 EXPECT_EQ(CERT_STATUS_SHA1_SIGNATURE_PRESENT, verify_result.cert_status); | |
| 1204 | |
| 1205 // Attempt to verify with the second known cross-certified intermediate | |
| 1206 // provided. | |
| 1207 scoped_refptr<X509Certificate> baltimore_intermediate_2 = | |
| 1208 ImportCertFromFile(GetTestCertsDirectory(), | |
| 1209 "cybertrust_baltimore_cross_certified_2.pem"); | |
| 1210 ASSERT_TRUE(baltimore_intermediate_2.get()); | |
| 1211 | |
| 1212 X509Certificate::OSCertHandles intermediate_chain_2 = | |
| 1213 cybertrust_basic->GetIntermediateCertificates(); | |
| 1214 intermediate_chain_2.push_back(baltimore_intermediate_2->os_cert_handle()); | |
| 1215 | |
| 1216 scoped_refptr<X509Certificate> baltimore_chain_2 = | |
| 1217 X509Certificate::CreateFromHandle(cybertrust_basic->os_cert_handle(), | |
| 1218 intermediate_chain_2); | |
| 1219 error = Verify(baltimore_chain_2.get(), | |
| 1220 "cacert.omniroot.com", | |
| 1221 flags, | |
| 1222 NULL, | |
| 1223 empty_cert_list_, | |
| 1224 &verify_result); | |
| 1225 EXPECT_EQ(OK, error); | |
| 1226 EXPECT_EQ(CERT_STATUS_SHA1_SIGNATURE_PRESENT, verify_result.cert_status); | |
| 1227 | |
| 1228 // Attempt to verify when both a cross-certified intermediate AND | |
| 1229 // the legacy GTE root are provided. | |
| 1230 scoped_refptr<X509Certificate> cybertrust_root = | |
| 1231 ImportCertFromFile(GetTestCertsDirectory(), | |
| 1232 "cybertrust_gte_root.pem"); | |
| 1233 ASSERT_TRUE(cybertrust_root.get()); | |
| 1234 | |
| 1235 intermediate_chain_2.push_back(cybertrust_root->os_cert_handle()); | |
| 1236 scoped_refptr<X509Certificate> baltimore_chain_with_root = | |
| 1237 X509Certificate::CreateFromHandle(cybertrust_basic->os_cert_handle(), | |
| 1238 intermediate_chain_2); | |
| 1239 error = Verify(baltimore_chain_with_root.get(), | |
| 1240 "cacert.omniroot.com", | |
| 1241 flags, | |
| 1242 NULL, | |
| 1243 empty_cert_list_, | |
| 1244 &verify_result); | |
| 1245 EXPECT_EQ(OK, error); | |
| 1246 EXPECT_EQ(CERT_STATUS_SHA1_SIGNATURE_PRESENT, verify_result.cert_status); | |
| 1247 | |
| 1248 TestRootCerts::GetInstance()->Clear(); | |
| 1249 EXPECT_TRUE(TestRootCerts::GetInstance()->IsEmpty()); | |
| 1250 } | |
| 1251 #endif | |
| 1252 | |
| 1253 #if defined(USE_NSS_CERTS) || defined(OS_IOS) || defined(OS_WIN) || \ | 1130 #if defined(USE_NSS_CERTS) || defined(OS_IOS) || defined(OS_WIN) || \ |
| 1254 defined(OS_MACOSX) | 1131 defined(OS_MACOSX) |
| 1255 // Test that CRLSets are effective in making a certificate appear to be | 1132 // Test that CRLSets are effective in making a certificate appear to be |
| 1256 // revoked. | 1133 // revoked. |
| 1257 TEST_F(CertVerifyProcTest, CRLSet) { | 1134 TEST_F(CertVerifyProcTest, CRLSet) { |
| 1258 CertificateList ca_cert_list = | 1135 CertificateList ca_cert_list = |
| 1259 CreateCertificateListFromFile(GetTestCertsDirectory(), | 1136 CreateCertificateListFromFile(GetTestCertsDirectory(), |
| 1260 "root_ca_cert.pem", | 1137 "root_ca_cert.pem", |
| 1261 X509Certificate::FORMAT_AUTO); | 1138 X509Certificate::FORMAT_AUTO); |
| 1262 ASSERT_EQ(1U, ca_cert_list.size()); | 1139 ASSERT_EQ(1U, ca_cert_list.size()); |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1705 int flags = 0; | 1582 int flags = 0; |
| 1706 CertVerifyResult verify_result; | 1583 CertVerifyResult verify_result; |
| 1707 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, | 1584 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, |
| 1708 &verify_result); | 1585 &verify_result); |
| 1709 EXPECT_EQ(ERR_CERT_INVALID, error); | 1586 EXPECT_EQ(ERR_CERT_INVALID, error); |
| 1710 EXPECT_EQ(CERT_STATUS_INVALID, verify_result.cert_status); | 1587 EXPECT_EQ(CERT_STATUS_INVALID, verify_result.cert_status); |
| 1711 } | 1588 } |
| 1712 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 1589 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 1713 | 1590 |
| 1714 } // namespace net | 1591 } // namespace net |
| OLD | NEW |