Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Side by Side Diff: net/cert/internal/test_helpers.cc

Issue 2245643004: Support trust anchor constraints, by specifying them as a certificate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update gypi Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | net/cert/internal/trust_store.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/internal/test_helpers.h" 5 #include "net/cert/internal/test_helpers.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/base_paths.h" 8 #include "base/base_paths.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 110
111 std::string file_data = ReadTestFileToString( 111 std::string file_data = ReadTestFileToString(
112 std::string("net/data/verify_certificate_chain_unittest/") + file_name); 112 std::string("net/data/verify_certificate_chain_unittest/") + file_name);
113 113
114 std::vector<std::string> pem_headers; 114 std::vector<std::string> pem_headers;
115 115
116 // For details on the file format refer to: 116 // For details on the file format refer to:
117 // net/data/verify_certificate_chain_unittest/README. 117 // net/data/verify_certificate_chain_unittest/README.
118 const char kCertificateHeader[] = "CERTIFICATE"; 118 const char kCertificateHeader[] = "CERTIFICATE";
119 const char kTrustAnchorUnconstrained[] = "TRUST_ANCHOR_UNCONSTRAINED"; 119 const char kTrustAnchorUnconstrained[] = "TRUST_ANCHOR_UNCONSTRAINED";
120 const char kTrustAnchorConstrained[] = "TRUST_ANCHOR_CONSTRAINED";
120 const char kTimeHeader[] = "TIME"; 121 const char kTimeHeader[] = "TIME";
121 const char kResultHeader[] = "VERIFY_RESULT"; 122 const char kResultHeader[] = "VERIFY_RESULT";
122 123
123 pem_headers.push_back(kCertificateHeader); 124 pem_headers.push_back(kCertificateHeader);
124 pem_headers.push_back(kTrustAnchorUnconstrained); 125 pem_headers.push_back(kTrustAnchorUnconstrained);
126 pem_headers.push_back(kTrustAnchorConstrained);
125 pem_headers.push_back(kTimeHeader); 127 pem_headers.push_back(kTimeHeader);
126 pem_headers.push_back(kResultHeader); 128 pem_headers.push_back(kResultHeader);
127 129
128 bool has_time = false; 130 bool has_time = false;
129 bool has_result = false; 131 bool has_result = false;
130 132
131 PEMTokenizer pem_tokenizer(file_data, pem_headers); 133 PEMTokenizer pem_tokenizer(file_data, pem_headers);
132 while (pem_tokenizer.GetNext()) { 134 while (pem_tokenizer.GetNext()) {
133 const std::string& block_type = pem_tokenizer.block_type(); 135 const std::string& block_type = pem_tokenizer.block_type();
134 const std::string& block_data = pem_tokenizer.data(); 136 const std::string& block_data = pem_tokenizer.data();
135 137
136 if (block_type == kCertificateHeader) { 138 if (block_type == kCertificateHeader) {
137 ASSERT_TRUE(net::ParsedCertificate::CreateAndAddToVector( 139 ASSERT_TRUE(net::ParsedCertificate::CreateAndAddToVector(
138 reinterpret_cast<const uint8_t*>(block_data.data()), 140 reinterpret_cast<const uint8_t*>(block_data.data()),
139 block_data.size(), net::ParsedCertificate::DataSource::INTERNAL_COPY, 141 block_data.size(), net::ParsedCertificate::DataSource::INTERNAL_COPY,
140 {}, chain)); 142 {}, chain));
141 } else if (block_type == kTrustAnchorUnconstrained) { 143 } else if (block_type == kTrustAnchorUnconstrained ||
144 block_type == kTrustAnchorConstrained) {
142 ASSERT_FALSE(*trust_anchor) << "Duplicate trust anchor"; 145 ASSERT_FALSE(*trust_anchor) << "Duplicate trust anchor";
143 scoped_refptr<ParsedCertificate> root = 146 scoped_refptr<ParsedCertificate> root =
144 net::ParsedCertificate::CreateFromCertificateData( 147 net::ParsedCertificate::CreateFromCertificateData(
145 reinterpret_cast<const uint8_t*>(block_data.data()), 148 reinterpret_cast<const uint8_t*>(block_data.data()),
146 block_data.size(), 149 block_data.size(),
147 net::ParsedCertificate::DataSource::INTERNAL_COPY, {}); 150 net::ParsedCertificate::DataSource::INTERNAL_COPY, {});
148 ASSERT_TRUE(root); 151 ASSERT_TRUE(root);
149 *trust_anchor = 152 *trust_anchor =
150 TrustAnchor::CreateFromCertificateNoConstraints(std::move(root)); 153 block_type == kTrustAnchorUnconstrained
154 ? TrustAnchor::CreateFromCertificateNoConstraints(std::move(root))
155 : TrustAnchor::CreateFromCertificateWithConstraints(
156 std::move(root));
151 } else if (block_type == kTimeHeader) { 157 } else if (block_type == kTimeHeader) {
152 ASSERT_FALSE(has_time) << "Duplicate " << kTimeHeader; 158 ASSERT_FALSE(has_time) << "Duplicate " << kTimeHeader;
153 has_time = true; 159 has_time = true;
154 ASSERT_TRUE(der::ParseUTCTime(der::Input(&block_data), time)); 160 ASSERT_TRUE(der::ParseUTCTime(der::Input(&block_data), time));
155 } else if (block_type == kResultHeader) { 161 } else if (block_type == kResultHeader) {
156 ASSERT_FALSE(has_result) << "Duplicate " << kResultHeader; 162 ASSERT_FALSE(has_result) << "Duplicate " << kResultHeader;
157 ASSERT_TRUE(block_data == "SUCCESS" || block_data == "FAIL") 163 ASSERT_TRUE(block_data == "SUCCESS" || block_data == "FAIL")
158 << "Unrecognized result: " << block_data; 164 << "Unrecognized result: " << block_data;
159 has_result = true; 165 has_result = true;
160 *verify_result = block_data == "SUCCESS"; 166 *verify_result = block_data == "SUCCESS";
(...skipping 15 matching lines...) Expand all
176 std::string file_data; 182 std::string file_data;
177 if (!base::ReadFileToString(filepath, &file_data)) { 183 if (!base::ReadFileToString(filepath, &file_data)) {
178 ADD_FAILURE() << "Couldn't read file: " << filepath.value(); 184 ADD_FAILURE() << "Couldn't read file: " << filepath.value();
179 return std::string(); 185 return std::string();
180 } 186 }
181 187
182 return file_data; 188 return file_data;
183 } 189 }
184 190
185 } // namespace net 191 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/cert/internal/trust_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698