| Index: net/cert/internal/verify_signed_data_unittest.cc
|
| diff --git a/net/cert/internal/verify_signed_data_unittest.cc b/net/cert/internal/verify_signed_data_unittest.cc
|
| index bf7c1727bd3803598d82e8aa06532e3c03bd25c7..99e449c26a2dd077276a4772e81f800d9374169e 100644
|
| --- a/net/cert/internal/verify_signed_data_unittest.cc
|
| +++ b/net/cert/internal/verify_signed_data_unittest.cc
|
| @@ -6,12 +6,9 @@
|
|
|
| #include <set>
|
|
|
| -#include "base/base_paths.h"
|
| -#include "base/files/file_util.h"
|
| -#include "base/path_service.h"
|
| #include "net/cert/internal/signature_algorithm.h"
|
| #include "net/cert/internal/signature_policy.h"
|
| -#include "net/cert/pem_tokenizer.h"
|
| +#include "net/cert/internal/test_helpers.h"
|
| #include "net/der/input.h"
|
| #include "net/der/parse_values.h"
|
| #include "net/der/parser.h"
|
| @@ -25,85 +22,6 @@ namespace net {
|
|
|
| namespace {
|
|
|
| -// Creates a der::Input from an std::string. The lifetimes are a bit subtle
|
| -// when using this function:
|
| -//
|
| -// The returned der::Input() is only valid so long as the input string is alive
|
| -// and is not mutated.
|
| -//
|
| -// Note that the input parameter has been made a pointer to prevent callers
|
| -// from accidentally passing an r-value.
|
| -der::Input InputFromString(const std::string* s) {
|
| - return der::Input(reinterpret_cast<const uint8_t*>(s->data()), s->size());
|
| -}
|
| -
|
| -// Reads a signature verification test file.
|
| -//
|
| -// The test file is a series of PEM blocks (PEM is just base64 data) with
|
| -// headings of:
|
| -//
|
| -// "PUBLIC KEY" - DER encoding of the SubjectPublicKeyInfo
|
| -// "ALGORITHM" - DER encoding of the AlgorithmIdentifier for the signature
|
| -// algorithm (signatureAlgorithm in X.509)
|
| -// "DATA" - The data that was signed (tbsCertificate in X.509)
|
| -// "SIGNATURE" - The result of signing DATA.
|
| -::testing::AssertionResult ParseTestDataFile(const std::string& file_data,
|
| - std::string* public_key,
|
| - std::string* algorithm,
|
| - std::string* signed_data,
|
| - std::string* signature_value) {
|
| - const char kPublicKeyBlock[] = "PUBLIC KEY";
|
| - const char kAlgorithmBlock[] = "ALGORITHM";
|
| - const char kSignedDataBlock[] = "DATA";
|
| - const char kSignatureBlock[] = "SIGNATURE";
|
| -
|
| - std::vector<std::string> pem_headers;
|
| - pem_headers.push_back(kPublicKeyBlock);
|
| - pem_headers.push_back(kAlgorithmBlock);
|
| - pem_headers.push_back(kSignedDataBlock);
|
| - pem_headers.push_back(kSignatureBlock);
|
| -
|
| - // Keep track of which blocks have been encountered (by elimination).
|
| - std::set<std::string> remaining_blocks(pem_headers.begin(),
|
| - pem_headers.end());
|
| -
|
| - PEMTokenizer pem_tokenizer(file_data, pem_headers);
|
| - while (pem_tokenizer.GetNext()) {
|
| - const std::string& block_type = pem_tokenizer.block_type();
|
| - if (block_type == kPublicKeyBlock) {
|
| - public_key->assign(pem_tokenizer.data());
|
| - } else if (block_type == kAlgorithmBlock) {
|
| - algorithm->assign(pem_tokenizer.data());
|
| - } else if (block_type == kSignedDataBlock) {
|
| - signed_data->assign(pem_tokenizer.data());
|
| - } else if (block_type == kSignatureBlock) {
|
| - signature_value->assign(pem_tokenizer.data());
|
| - }
|
| -
|
| - if (remaining_blocks.erase(block_type) != 1u) {
|
| - return ::testing::AssertionFailure()
|
| - << "PEM block defined multiple times: " << block_type;
|
| - }
|
| - }
|
| -
|
| - if (!remaining_blocks.empty()) {
|
| - // Print one of the missing PEM blocks.
|
| - return ::testing::AssertionFailure() << "PEM block missing: "
|
| - << *remaining_blocks.begin();
|
| - }
|
| -
|
| - return ::testing::AssertionSuccess();
|
| -}
|
| -
|
| -// Returns a path to the file |file_name| within the unittest data directory.
|
| -base::FilePath GetTestFilePath(const char* file_name) {
|
| - base::FilePath src_root;
|
| - PathService::Get(base::DIR_SOURCE_ROOT, &src_root);
|
| - return src_root.Append(
|
| - FILE_PATH_LITERAL("net/data/verify_signed_data_unittest"))
|
| - .AppendASCII(file_name);
|
| -}
|
| -
|
| enum VerifyResult {
|
| SUCCESS,
|
| FAILURE,
|
| @@ -125,19 +43,22 @@ void RunTestCaseUsingPolicy(VerifyResult expected_result,
|
| return;
|
| #endif
|
|
|
| - base::FilePath test_file_path = GetTestFilePath(file_name);
|
| -
|
| - std::string file_data;
|
| - ASSERT_TRUE(base::ReadFileToString(test_file_path, &file_data))
|
| - << "Couldn't read file: " << test_file_path.value();
|
| + std::string path =
|
| + std::string("net/data/verify_signed_data_unittest/") + file_name;
|
|
|
| std::string public_key;
|
| std::string algorithm;
|
| std::string signed_data;
|
| std::string signature_value;
|
|
|
| - ASSERT_TRUE(ParseTestDataFile(file_data, &public_key, &algorithm,
|
| - &signed_data, &signature_value));
|
| + const PemBlockMapping mappings[] = {
|
| + {"PUBLIC KEY", &public_key},
|
| + {"ALGORITHM", &algorithm},
|
| + {"DATA", &signed_data},
|
| + {"SIGNATURE", &signature_value},
|
| + };
|
| +
|
| + ASSERT_TRUE(ReadTestDataFromPemFile(path, mappings));
|
|
|
| scoped_ptr<SignatureAlgorithm> signature_algorithm =
|
| SignatureAlgorithm::CreateFromDer(InputFromString(&algorithm));
|
|
|