summaryrefslogtreecommitdiff
path: root/chromium/net/cert/pki/test_helpers.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/net/cert/pki/test_helpers.cc')
-rw-r--r--chromium/net/cert/pki/test_helpers.cc51
1 files changed, 33 insertions, 18 deletions
diff --git a/chromium/net/cert/pki/test_helpers.cc b/chromium/net/cert/pki/test_helpers.cc
index 50cc1ba5105..151633f5e4d 100644
--- a/chromium/net/cert/pki/test_helpers.cc
+++ b/chromium/net/cert/pki/test_helpers.cc
@@ -1,18 +1,18 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
+// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/cert/pki/test_helpers.h"
-#include "base/base64.h"
#include "base/base_paths.h"
#include "base/files/file_util.h"
#include "base/path_service.h"
#include "base/strings/string_piece.h"
-#include "base/strings/string_util.h"
#include "net/cert/pem.h"
#include "net/cert/pki/cert_error_params.h"
#include "net/cert/pki/cert_errors.h"
+#include "net/cert/pki/simple_path_builder_delegate.h"
+#include "net/cert/pki/string_util.h"
#include "net/der/parser.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/boringssl/src/include/openssl/pool.h"
@@ -23,11 +23,11 @@ namespace net {
namespace {
-bool GetValue(base::StringPiece prefix,
- base::StringPiece line,
+bool GetValue(std::string_view prefix,
+ std::string_view line,
std::string* value,
bool* has_value) {
- if (!base::StartsWith(line, prefix))
+ if (!net::string_util::StartsWith(line, prefix))
return false;
if (*has_value) {
@@ -45,13 +45,16 @@ bool GetValue(base::StringPiece prefix,
namespace der {
void PrintTo(const Input& data, ::std::ostream* os) {
- std::string b64;
- base::Base64Encode(
- base::StringPiece(reinterpret_cast<const char*>(data.UnsafeData()),
- data.Length()),
- &b64);
-
- *os << "[" << b64 << "]";
+ size_t len;
+ if (!EVP_EncodedLength(&len, data.Length())) {
+ *os << "[]";
+ return;
+ }
+ std::vector<uint8_t> encoded(len);
+ len = EVP_EncodeBlock(encoded.data(), data.UnsafeData(), data.Length());
+ // Skip the trailing \0.
+ std::string b64_encoded(encoded.begin(), encoded.begin() + len);
+ *os << "[" << b64_encoded << "]";
}
} // namespace der
@@ -201,8 +204,9 @@ bool ReadVerifyCertChainTestFromFile(const std::string& file_path_ascii,
bool has_time = false;
bool has_errors = false;
bool has_key_purpose = false;
+ bool has_digest_policy = false;
- base::StringPiece kExpectedErrors = "expected_errors:";
+ std::string kExpectedErrors = "expected_errors:";
std::istringstream stream(file_data);
for (std::string line; std::getline(stream, line, '\n');) {
@@ -218,7 +222,7 @@ bool ReadVerifyCertChainTestFromFile(const std::string& file_path_ascii,
if (line.empty()) {
continue;
}
- base::StringPiece line_piece(line);
+ std::string_view line_piece(line);
std::string value;
@@ -236,7 +240,7 @@ bool ReadVerifyCertChainTestFromFile(const std::string& file_path_ascii,
ReadCertChainFromFile(chain_path, &test->chain);
} else if (GetValue("utc_time: ", line_piece, &value, &has_time)) {
if (value == "DEFAULT") {
- value = "221005120000Z";
+ value = "211005120000Z";
}
if (!der::ParseUTCTime(der::Input(&value), &test->time)) {
ADD_FAILURE() << "Failed parsing UTC time";
@@ -271,7 +275,18 @@ bool ReadVerifyCertChainTestFromFile(const std::string& file_path_ascii,
ADD_FAILURE() << "Unrecognized last_cert_trust: " << value;
return false;
}
- } else if (base::StartsWith(line_piece, "#")) {
+ } else if (GetValue("digest_policy: ", line_piece, &value,
+ &has_digest_policy)) {
+ if (value == "STRONG") {
+ test->digest_policy = SimplePathBuilderDelegate::DigestPolicy::kStrong;
+ } else if (value == "ALLOW_SHA_1") {
+ test->digest_policy =
+ SimplePathBuilderDelegate::DigestPolicy::kWeakAllowSha1;
+ } else {
+ ADD_FAILURE() << "Unrecognized digest_policy: " << value;
+ return false;
+ }
+ } else if (net::string_util::StartsWith(line_piece, "#")) {
// Skip comments.
continue;
} else if (line_piece == kExpectedErrors) {
@@ -279,7 +294,7 @@ bool ReadVerifyCertChainTestFromFile(const std::string& file_path_ascii,
// The errors start on the next line, and extend until the end of the
// file.
std::string prefix =
- std::string("\n") + std::string(kExpectedErrors) + std::string("\n");
+ std::string("\n") + kExpectedErrors + std::string("\n");
size_t errors_start = file_data.find(prefix);
if (errors_start == std::string::npos) {
ADD_FAILURE() << "expected_errors not found";