OLD | NEW |
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" |
| 11 #include "net/cert/internal/cert_errors.h" |
11 #include "net/cert/pem_tokenizer.h" | 12 #include "net/cert/pem_tokenizer.h" |
12 #include "net/der/parser.h" | 13 #include "net/der/parser.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 namespace net { | 16 namespace net { |
16 | 17 |
17 namespace der { | 18 namespace der { |
18 | 19 |
19 void PrintTo(const Input& data, ::std::ostream* os) { | 20 void PrintTo(const Input& data, ::std::ostream* os) { |
20 std::string b64; | 21 std::string b64; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 bool has_time = false; | 135 bool has_time = false; |
135 bool has_result = false; | 136 bool has_result = false; |
136 bool has_errors = false; | 137 bool has_errors = false; |
137 | 138 |
138 PEMTokenizer pem_tokenizer(file_data, pem_headers); | 139 PEMTokenizer pem_tokenizer(file_data, pem_headers); |
139 while (pem_tokenizer.GetNext()) { | 140 while (pem_tokenizer.GetNext()) { |
140 const std::string& block_type = pem_tokenizer.block_type(); | 141 const std::string& block_type = pem_tokenizer.block_type(); |
141 const std::string& block_data = pem_tokenizer.data(); | 142 const std::string& block_data = pem_tokenizer.data(); |
142 | 143 |
143 if (block_type == kCertificateHeader) { | 144 if (block_type == kCertificateHeader) { |
144 ASSERT_TRUE(net::ParsedCertificate::CreateAndAddToVector( | 145 CertErrors errors; |
145 reinterpret_cast<const uint8_t*>(block_data.data()), | 146 ASSERT_TRUE(net::ParsedCertificate::CreateAndAddToVector(block_data, {}, |
146 block_data.size(), net::ParsedCertificate::DataSource::INTERNAL_COPY, | 147 chain, &errors)) |
147 {}, chain)); | 148 << errors.ToDebugString(); |
148 } else if (block_type == kTrustAnchorUnconstrained || | 149 } else if (block_type == kTrustAnchorUnconstrained || |
149 block_type == kTrustAnchorConstrained) { | 150 block_type == kTrustAnchorConstrained) { |
150 ASSERT_FALSE(*trust_anchor) << "Duplicate trust anchor"; | 151 ASSERT_FALSE(*trust_anchor) << "Duplicate trust anchor"; |
| 152 CertErrors errors; |
151 scoped_refptr<ParsedCertificate> root = | 153 scoped_refptr<ParsedCertificate> root = |
152 net::ParsedCertificate::CreateFromCertificateData( | 154 net::ParsedCertificate::Create(block_data, {}, &errors); |
153 reinterpret_cast<const uint8_t*>(block_data.data()), | 155 ASSERT_TRUE(root) << errors.ToDebugString(); |
154 block_data.size(), | |
155 net::ParsedCertificate::DataSource::INTERNAL_COPY, {}); | |
156 ASSERT_TRUE(root); | |
157 *trust_anchor = | 156 *trust_anchor = |
158 block_type == kTrustAnchorUnconstrained | 157 block_type == kTrustAnchorUnconstrained |
159 ? TrustAnchor::CreateFromCertificateNoConstraints(std::move(root)) | 158 ? TrustAnchor::CreateFromCertificateNoConstraints(std::move(root)) |
160 : TrustAnchor::CreateFromCertificateWithConstraints( | 159 : TrustAnchor::CreateFromCertificateWithConstraints( |
161 std::move(root)); | 160 std::move(root)); |
162 } else if (block_type == kTimeHeader) { | 161 } else if (block_type == kTimeHeader) { |
163 ASSERT_FALSE(has_time) << "Duplicate " << kTimeHeader; | 162 ASSERT_FALSE(has_time) << "Duplicate " << kTimeHeader; |
164 has_time = true; | 163 has_time = true; |
165 ASSERT_TRUE(der::ParseUTCTime(der::Input(&block_data), time)); | 164 ASSERT_TRUE(der::ParseUTCTime(der::Input(&block_data), time)); |
166 } else if (block_type == kResultHeader) { | 165 } else if (block_type == kResultHeader) { |
(...skipping 24 matching lines...) Expand all Loading... |
191 std::string file_data; | 190 std::string file_data; |
192 if (!base::ReadFileToString(filepath, &file_data)) { | 191 if (!base::ReadFileToString(filepath, &file_data)) { |
193 ADD_FAILURE() << "Couldn't read file: " << filepath.value(); | 192 ADD_FAILURE() << "Couldn't read file: " << filepath.value(); |
194 return std::string(); | 193 return std::string(); |
195 } | 194 } |
196 | 195 |
197 return file_data; | 196 return file_data; |
198 } | 197 } |
199 | 198 |
200 } // namespace net | 199 } // namespace net |
OLD | NEW |