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/verify_signed_data.h" | 5 #include "net/cert/internal/verify_signed_data.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "net/cert/internal/cert_errors.h" | 10 #include "net/cert/internal/cert_errors.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 const PemBlockMapping mappings[] = { | 49 const PemBlockMapping mappings[] = { |
50 {"PUBLIC KEY", &public_key}, | 50 {"PUBLIC KEY", &public_key}, |
51 {"ALGORITHM", &algorithm}, | 51 {"ALGORITHM", &algorithm}, |
52 {"DATA", &signed_data}, | 52 {"DATA", &signed_data}, |
53 {"SIGNATURE", &signature_value}, | 53 {"SIGNATURE", &signature_value}, |
54 }; | 54 }; |
55 | 55 |
56 ASSERT_TRUE(ReadTestDataFromPemFile(path, mappings)); | 56 ASSERT_TRUE(ReadTestDataFromPemFile(path, mappings)); |
57 | 57 |
| 58 CertErrors algorithm_errors; |
58 std::unique_ptr<SignatureAlgorithm> signature_algorithm = | 59 std::unique_ptr<SignatureAlgorithm> signature_algorithm = |
59 SignatureAlgorithm::CreateFromDer(der::Input(&algorithm)); | 60 SignatureAlgorithm::Create(der::Input(&algorithm), &algorithm_errors); |
60 ASSERT_TRUE(signature_algorithm); | 61 ASSERT_TRUE(signature_algorithm) << algorithm_errors.ToDebugString(); |
61 | 62 |
62 der::BitString signature_value_bit_string; | 63 der::BitString signature_value_bit_string; |
63 der::Parser signature_value_parser((der::Input(&signature_value))); | 64 der::Parser signature_value_parser((der::Input(&signature_value))); |
64 ASSERT_TRUE(signature_value_parser.ReadBitString(&signature_value_bit_string)) | 65 ASSERT_TRUE(signature_value_parser.ReadBitString(&signature_value_bit_string)) |
65 << "The signature value is not a valid BIT STRING"; | 66 << "The signature value is not a valid BIT STRING"; |
66 | 67 |
67 bool expected_result_bool = expected_result == SUCCESS; | 68 bool expected_result_bool = expected_result == SUCCESS; |
68 | 69 |
69 // TODO(crbug.com/634443): Verify the returned errors. | 70 // TODO(crbug.com/634443): Verify the returned errors. |
70 CertErrors errors; | 71 CertErrors verify_errors; |
71 EXPECT_EQ(expected_result_bool, | 72 EXPECT_EQ(expected_result_bool, |
72 VerifySignedData(*signature_algorithm, der::Input(&signed_data), | 73 VerifySignedData(*signature_algorithm, der::Input(&signed_data), |
73 signature_value_bit_string, | 74 signature_value_bit_string, |
74 der::Input(&public_key), policy, &errors)); | 75 der::Input(&public_key), policy, &verify_errors)); |
75 } | 76 } |
76 | 77 |
77 // RunTestCase() is the same as RunTestCaseUsingPolicy(), only it uses a | 78 // RunTestCase() is the same as RunTestCaseUsingPolicy(), only it uses a |
78 // default policy. This policy will accept a basic profile of signature | 79 // default policy. This policy will accept a basic profile of signature |
79 // algorithms (including ANY sized RSA key >= 1024). | 80 // algorithms (including ANY sized RSA key >= 1024). |
80 void RunTestCase(VerifyResult expected_result, const char* file_name) { | 81 void RunTestCase(VerifyResult expected_result, const char* file_name) { |
81 SimpleSignaturePolicy policy(1024); | 82 SimpleSignaturePolicy policy(1024); |
82 return RunTestCaseUsingPolicy(expected_result, file_name, &policy); | 83 return RunTestCaseUsingPolicy(expected_result, file_name, &policy); |
83 } | 84 } |
84 | 85 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 RunTestCaseUsingPolicy(SUCCESS, "ecdsa-secp384r1-sha256.pem", &policy); | 293 RunTestCaseUsingPolicy(SUCCESS, "ecdsa-secp384r1-sha256.pem", &policy); |
293 RunTestCaseUsingPolicy(SUCCESS, "rsa-pkcs1-sha256.pem", &policy); | 294 RunTestCaseUsingPolicy(SUCCESS, "rsa-pkcs1-sha256.pem", &policy); |
294 RunTestCaseUsingPolicy(SUCCESS, "rsa-pss-sha256-salt10.pem", &policy); | 295 RunTestCaseUsingPolicy(SUCCESS, "rsa-pss-sha256-salt10.pem", &policy); |
295 RunTestCaseUsingPolicy(FAILURE, "rsa-pss-sha256-mgf1-sha512-salt33.pem", | 296 RunTestCaseUsingPolicy(FAILURE, "rsa-pss-sha256-mgf1-sha512-salt33.pem", |
296 &policy); | 297 &policy); |
297 } | 298 } |
298 | 299 |
299 } // namespace | 300 } // namespace |
300 | 301 |
301 } // namespace net | 302 } // namespace net |
OLD | NEW |