| OLD | NEW | 
|    1 // Copyright 2014 The Chromium Authors. All rights reserved. |    1 // Copyright 2014 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 "chrome/browser/chromeos/net/cert_verify_proc_chromeos.h" |    5 #include "chrome/browser/chromeos/net/cert_verify_proc_chromeos.h" | 
|    6  |    6  | 
|    7 #include <stddef.h> |    7 #include <stddef.h> | 
|    8  |    8  | 
|    9 #include "crypto/nss_util_internal.h" |    9 #include "crypto/nss_util_internal.h" | 
|   10 #include "crypto/scoped_test_nss_chromeos_user.h" |   10 #include "crypto/scoped_test_nss_chromeos_user.h" | 
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   58                                            "multi-root-chain2.pem", |   58                                            "multi-root-chain2.pem", | 
|   59                                            net::X509Certificate::FORMAT_AUTO); |   59                                            net::X509Certificate::FORMAT_AUTO); | 
|   60     ASSERT_EQ(4U, certs_2_.size()); |   60     ASSERT_EQ(4U, certs_2_.size()); | 
|   61  |   61  | 
|   62     // The chains: |   62     // The chains: | 
|   63     //   1. A (end-entity) -> B -> C -> D (self-signed root) |   63     //   1. A (end-entity) -> B -> C -> D (self-signed root) | 
|   64     //   2. A (end-entity) -> B -> C2 -> E (self-signed root) |   64     //   2. A (end-entity) -> B -> C2 -> E (self-signed root) | 
|   65     ASSERT_TRUE(certs_1_[0]->Equals(certs_2_[0].get())); |   65     ASSERT_TRUE(certs_1_[0]->Equals(certs_2_[0].get())); | 
|   66     ASSERT_TRUE(certs_1_[1]->Equals(certs_2_[1].get())); |   66     ASSERT_TRUE(certs_1_[1]->Equals(certs_2_[1].get())); | 
|   67     ASSERT_FALSE(certs_1_[2]->Equals(certs_2_[2].get())); |   67     ASSERT_FALSE(certs_1_[2]->Equals(certs_2_[2].get())); | 
|   68     ASSERT_EQ("C CA", certs_1_[2]->subject().common_name); |   68     ASSERT_EQ("C CA - Multi-root", certs_1_[2]->subject().common_name); | 
|   69     ASSERT_EQ("C CA", certs_2_[2]->subject().common_name); |   69     ASSERT_EQ("C CA - Multi-root", certs_2_[2]->subject().common_name); | 
|   70  |   70  | 
|   71     root_1_.push_back(certs_1_.back()); |   71     root_1_.push_back(certs_1_.back()); | 
|   72     root_2_.push_back(certs_2_.back()); |   72     root_2_.push_back(certs_2_.back()); | 
|   73  |   73  | 
|   74     ASSERT_EQ("D Root CA", root_1_[0]->subject().common_name); |   74     ASSERT_EQ("D Root CA - Multi-root", root_1_[0]->subject().common_name); | 
|   75     ASSERT_EQ("E Root CA", root_2_[0]->subject().common_name); |   75     ASSERT_EQ("E Root CA - Multi-root", root_2_[0]->subject().common_name); | 
|   76   } |   76   } | 
|   77  |   77  | 
|   78   int VerifyWithAdditionalTrustAnchors( |   78   int VerifyWithAdditionalTrustAnchors( | 
|   79       net::CertVerifyProc* verify_proc, |   79       net::CertVerifyProc* verify_proc, | 
|   80       const net::CertificateList& additional_trust_anchors, |   80       const net::CertificateList& additional_trust_anchors, | 
|   81       net::X509Certificate* cert, |   81       net::X509Certificate* cert, | 
|   82       std::string* root_subject_name) { |   82       std::string* root_subject_name) { | 
|   83     int flags = 0; |   83     int flags = 0; | 
|   84     net::CertVerifyResult verify_result; |   84     net::CertVerifyResult verify_result; | 
|   85     int error = |   85     int error = | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  137   net::NSSCertDatabase::ImportCertFailureList failed; |  137   net::NSSCertDatabase::ImportCertFailureList failed; | 
|  138   EXPECT_TRUE(db_1_->ImportCACerts( |  138   EXPECT_TRUE(db_1_->ImportCACerts( | 
|  139       root_1_, net::NSSCertDatabase::TRUSTED_SSL, &failed)); |  139       root_1_, net::NSSCertDatabase::TRUSTED_SSL, &failed)); | 
|  140   EXPECT_EQ(0U, failed.size()); |  140   EXPECT_EQ(0U, failed.size()); | 
|  141  |  141  | 
|  142   // Imported CA certs are not trusted by default verifier. |  142   // Imported CA certs are not trusted by default verifier. | 
|  143   EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, |  143   EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, | 
|  144             Verify(verify_proc_default_.get(), server.get(), &verify_root)); |  144             Verify(verify_proc_default_.get(), server.get(), &verify_root)); | 
|  145   // User 1 should now verify successfully through the D root. |  145   // User 1 should now verify successfully through the D root. | 
|  146   EXPECT_EQ(net::OK, Verify(verify_proc_1_.get(), server.get(), &verify_root)); |  146   EXPECT_EQ(net::OK, Verify(verify_proc_1_.get(), server.get(), &verify_root)); | 
|  147   EXPECT_EQ("CN=D Root CA", verify_root); |  147   EXPECT_EQ("CN=D Root CA - Multi-root", verify_root); | 
|  148   // User 2 should still fail. |  148   // User 2 should still fail. | 
|  149   EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, |  149   EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, | 
|  150             Verify(verify_proc_2_.get(), server.get(), &verify_root)); |  150             Verify(verify_proc_2_.get(), server.get(), &verify_root)); | 
|  151  |  151  | 
|  152   // Import and trust the E root for user 2. |  152   // Import and trust the E root for user 2. | 
|  153   failed.clear(); |  153   failed.clear(); | 
|  154   EXPECT_TRUE(db_2_->ImportCACerts( |  154   EXPECT_TRUE(db_2_->ImportCACerts( | 
|  155       root_2_, net::NSSCertDatabase::TRUSTED_SSL, &failed)); |  155       root_2_, net::NSSCertDatabase::TRUSTED_SSL, &failed)); | 
|  156   EXPECT_EQ(0U, failed.size()); |  156   EXPECT_EQ(0U, failed.size()); | 
|  157  |  157  | 
|  158   // Imported CA certs are not trusted by default verifier. |  158   // Imported CA certs are not trusted by default verifier. | 
|  159   EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, |  159   EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, | 
|  160             Verify(verify_proc_default_.get(), server.get(), &verify_root)); |  160             Verify(verify_proc_default_.get(), server.get(), &verify_root)); | 
|  161   // User 1 should still verify successfully through the D root. |  161   // User 1 should still verify successfully through the D root. | 
|  162   EXPECT_EQ(net::OK, Verify(verify_proc_1_.get(), server.get(), &verify_root)); |  162   EXPECT_EQ(net::OK, Verify(verify_proc_1_.get(), server.get(), &verify_root)); | 
|  163   EXPECT_EQ("CN=D Root CA", verify_root); |  163   EXPECT_EQ("CN=D Root CA - Multi-root", verify_root); | 
|  164   // User 2 should now verify successfully through the E root. |  164   // User 2 should now verify successfully through the E root. | 
|  165   EXPECT_EQ(net::OK, Verify(verify_proc_2_.get(), server.get(), &verify_root)); |  165   EXPECT_EQ(net::OK, Verify(verify_proc_2_.get(), server.get(), &verify_root)); | 
|  166   EXPECT_EQ("CN=E Root CA", verify_root); |  166   EXPECT_EQ("CN=E Root CA - Multi-root", verify_root); | 
|  167  |  167  | 
|  168   // Delete D root. |  168   // Delete D root. | 
|  169   EXPECT_TRUE(db_1_->DeleteCertAndKey(root_1_[0].get())); |  169   EXPECT_TRUE(db_1_->DeleteCertAndKey(root_1_[0].get())); | 
|  170   EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, |  170   EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, | 
|  171             Verify(verify_proc_default_.get(), server.get(), &verify_root)); |  171             Verify(verify_proc_default_.get(), server.get(), &verify_root)); | 
|  172   // User 1 should now fail to verify. |  172   // User 1 should now fail to verify. | 
|  173   EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, |  173   EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, | 
|  174             Verify(verify_proc_1_.get(), server.get(), &verify_root)); |  174             Verify(verify_proc_1_.get(), server.get(), &verify_root)); | 
|  175   // User 2 should still verify successfully through the E root. |  175   // User 2 should still verify successfully through the E root. | 
|  176   EXPECT_EQ(net::OK, Verify(verify_proc_2_.get(), server.get(), &verify_root)); |  176   EXPECT_EQ(net::OK, Verify(verify_proc_2_.get(), server.get(), &verify_root)); | 
|  177   EXPECT_EQ("CN=E Root CA", verify_root); |  177   EXPECT_EQ("CN=E Root CA - Multi-root", verify_root); | 
|  178  |  178  | 
|  179   // Delete E root. |  179   // Delete E root. | 
|  180   EXPECT_TRUE(db_2_->DeleteCertAndKey(root_2_[0].get())); |  180   EXPECT_TRUE(db_2_->DeleteCertAndKey(root_2_[0].get())); | 
|  181   EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, |  181   EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, | 
|  182             Verify(verify_proc_default_.get(), server.get(), &verify_root)); |  182             Verify(verify_proc_default_.get(), server.get(), &verify_root)); | 
|  183   // User 1 should still fail to verify. |  183   // User 1 should still fail to verify. | 
|  184   EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, |  184   EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, | 
|  185             Verify(verify_proc_1_.get(), server.get(), &verify_root)); |  185             Verify(verify_proc_1_.get(), server.get(), &verify_root)); | 
|  186   // User 2 should now fail to verify. |  186   // User 2 should now fail to verify. | 
|  187   EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, |  187   EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
|  212                                              server.get(), |  212                                              server.get(), | 
|  213                                              &verify_root)); |  213                                              &verify_root)); | 
|  214  |  214  | 
|  215   // Use D Root CA as additional trust anchor. Verifications should succeed now. |  215   // Use D Root CA as additional trust anchor. Verifications should succeed now. | 
|  216   additional_trust_anchors.push_back(root_1_[0]); |  216   additional_trust_anchors.push_back(root_1_[0]); | 
|  217   EXPECT_EQ(net::OK, |  217   EXPECT_EQ(net::OK, | 
|  218             VerifyWithAdditionalTrustAnchors(verify_proc_default_.get(), |  218             VerifyWithAdditionalTrustAnchors(verify_proc_default_.get(), | 
|  219                                              additional_trust_anchors, |  219                                              additional_trust_anchors, | 
|  220                                              server.get(), |  220                                              server.get(), | 
|  221                                              &verify_root)); |  221                                              &verify_root)); | 
|  222   EXPECT_EQ("CN=D Root CA", verify_root); |  222   EXPECT_EQ("CN=D Root CA - Multi-root", verify_root); | 
|  223   EXPECT_EQ(net::OK, |  223   EXPECT_EQ(net::OK, | 
|  224             VerifyWithAdditionalTrustAnchors(verify_proc_1_.get(), |  224             VerifyWithAdditionalTrustAnchors(verify_proc_1_.get(), | 
|  225                                              additional_trust_anchors, |  225                                              additional_trust_anchors, | 
|  226                                              server.get(), |  226                                              server.get(), | 
|  227                                              &verify_root)); |  227                                              &verify_root)); | 
|  228   EXPECT_EQ("CN=D Root CA", verify_root); |  228   EXPECT_EQ("CN=D Root CA - Multi-root", verify_root); | 
|  229   // User 2 should still fail. |  229   // User 2 should still fail. | 
|  230   EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, |  230   EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, | 
|  231             VerifyWithAdditionalTrustAnchors(verify_proc_2_.get(), |  231             VerifyWithAdditionalTrustAnchors(verify_proc_2_.get(), | 
|  232                                              net::CertificateList(), |  232                                              net::CertificateList(), | 
|  233                                              server.get(), |  233                                              server.get(), | 
|  234                                              &verify_root)); |  234                                              &verify_root)); | 
|  235  |  235  | 
|  236   // Without additional trust anchors, verification should fail again. |  236   // Without additional trust anchors, verification should fail again. | 
|  237   additional_trust_anchors.clear(); |  237   additional_trust_anchors.clear(); | 
|  238   EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, |  238   EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
|  255   EXPECT_EQ(0U, failed.size()); |  255   EXPECT_EQ(0U, failed.size()); | 
|  256  |  256  | 
|  257   // Use D Root CA as additional trust anchor. Verifications should still |  257   // Use D Root CA as additional trust anchor. Verifications should still | 
|  258   // succeed even if the cert is trusted by a different profile. |  258   // succeed even if the cert is trusted by a different profile. | 
|  259   additional_trust_anchors.push_back(root_1_[0]); |  259   additional_trust_anchors.push_back(root_1_[0]); | 
|  260   EXPECT_EQ(net::OK, |  260   EXPECT_EQ(net::OK, | 
|  261             VerifyWithAdditionalTrustAnchors(verify_proc_default_.get(), |  261             VerifyWithAdditionalTrustAnchors(verify_proc_default_.get(), | 
|  262                                              additional_trust_anchors, |  262                                              additional_trust_anchors, | 
|  263                                              server.get(), |  263                                              server.get(), | 
|  264                                              &verify_root)); |  264                                              &verify_root)); | 
|  265   EXPECT_EQ("CN=D Root CA", verify_root); |  265   EXPECT_EQ("CN=D Root CA - Multi-root", verify_root); | 
|  266   EXPECT_EQ(net::OK, |  266   EXPECT_EQ(net::OK, | 
|  267             VerifyWithAdditionalTrustAnchors(verify_proc_1_.get(), |  267             VerifyWithAdditionalTrustAnchors(verify_proc_1_.get(), | 
|  268                                              additional_trust_anchors, |  268                                              additional_trust_anchors, | 
|  269                                              server.get(), |  269                                              server.get(), | 
|  270                                              &verify_root)); |  270                                              &verify_root)); | 
|  271   EXPECT_EQ("CN=D Root CA", verify_root); |  271   EXPECT_EQ("CN=D Root CA - Multi-root", verify_root); | 
|  272   EXPECT_EQ(net::OK, |  272   EXPECT_EQ(net::OK, | 
|  273             VerifyWithAdditionalTrustAnchors(verify_proc_2_.get(), |  273             VerifyWithAdditionalTrustAnchors(verify_proc_2_.get(), | 
|  274                                              additional_trust_anchors, |  274                                              additional_trust_anchors, | 
|  275                                              server.get(), |  275                                              server.get(), | 
|  276                                              &verify_root)); |  276                                              &verify_root)); | 
|  277   EXPECT_EQ("CN=D Root CA", verify_root); |  277   EXPECT_EQ("CN=D Root CA - Multi-root", verify_root); | 
|  278 } |  278 } | 
|  279  |  279  | 
|  280 class CertVerifyProcChromeOSOrderingTest |  280 class CertVerifyProcChromeOSOrderingTest | 
|  281     : public CertVerifyProcChromeOSTest, |  281     : public CertVerifyProcChromeOSTest, | 
|  282       public ::testing::WithParamInterface< |  282       public ::testing::WithParamInterface< | 
|  283           std::tr1::tuple<bool, int, std::string> > {}; |  283           std::tr1::tuple<bool, int, std::string> > {}; | 
|  284  |  284  | 
|  285 // Test a variety of different combinations of (maybe) verifying / (maybe) |  285 // Test a variety of different combinations of (maybe) verifying / (maybe) | 
|  286 // importing / verifying again, to try to find any cases where caching might |  286 // importing / verifying again, to try to find any cases where caching might | 
|  287 // affect the results. |  287 // affect the results. | 
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  348         case 'd': |  348         case 'd': | 
|  349           // Default verifier should always fail. |  349           // Default verifier should always fail. | 
|  350           EXPECT_EQ( |  350           EXPECT_EQ( | 
|  351               net::ERR_CERT_AUTHORITY_INVALID, |  351               net::ERR_CERT_AUTHORITY_INVALID, | 
|  352               Verify(verify_proc_default_.get(), server.get(), &verify_root)); |  352               Verify(verify_proc_default_.get(), server.get(), &verify_root)); | 
|  353           break; |  353           break; | 
|  354         case '1': |  354         case '1': | 
|  355           EXPECT_EQ(expected_user1_result, |  355           EXPECT_EQ(expected_user1_result, | 
|  356                     Verify(verify_proc_1_.get(), server.get(), &verify_root)); |  356                     Verify(verify_proc_1_.get(), server.get(), &verify_root)); | 
|  357           if (expected_user1_result == net::OK) |  357           if (expected_user1_result == net::OK) | 
|  358             EXPECT_EQ("CN=D Root CA", verify_root); |  358             EXPECT_EQ("CN=D Root CA - Multi-root", verify_root); | 
|  359           break; |  359           break; | 
|  360         case '2': |  360         case '2': | 
|  361           EXPECT_EQ(expected_user2_result, |  361           EXPECT_EQ(expected_user2_result, | 
|  362                     Verify(verify_proc_2_.get(), server.get(), &verify_root)); |  362                     Verify(verify_proc_2_.get(), server.get(), &verify_root)); | 
|  363           if (expected_user2_result == net::OK) |  363           if (expected_user2_result == net::OK) | 
|  364             EXPECT_EQ("CN=E Root CA", verify_root); |  364             EXPECT_EQ("CN=E Root CA - Multi-root", verify_root); | 
|  365           break; |  365           break; | 
|  366         default: |  366         default: | 
|  367           FAIL(); |  367           FAIL(); | 
|  368       } |  368       } | 
|  369     } |  369     } | 
|  370   } |  370   } | 
|  371 } |  371 } | 
|  372  |  372  | 
|  373 INSTANTIATE_TEST_CASE_P( |  373 INSTANTIATE_TEST_CASE_P( | 
|  374     Variations, |  374     Variations, | 
|  375     CertVerifyProcChromeOSOrderingTest, |  375     CertVerifyProcChromeOSOrderingTest, | 
|  376     ::testing::Combine( |  376     ::testing::Combine( | 
|  377         ::testing::Bool(), |  377         ::testing::Bool(), | 
|  378         ::testing::Range(0, 1 << 2), |  378         ::testing::Range(0, 1 << 2), | 
|  379         ::testing::Values("d12", "d21", "1d2", "12d", "2d1", "21d"))); |  379         ::testing::Values("d12", "d21", "1d2", "12d", "2d1", "21d"))); | 
|  380  |  380  | 
|  381 }  // namespace chromeos |  381 }  // namespace chromeos | 
| OLD | NEW |