OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/quic/crypto/proof_source.h" | 5 #include "net/quic/crypto/proof_source.h" |
6 #include "net/quic/crypto/proof_verifier.h" | 6 #include "net/quic/crypto/proof_verifier.h" |
7 #include "net/quic/test_tools/crypto_test_utils.h" | 7 #include "net/quic/test_tools/crypto_test_utils.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 using std::string; | 10 using std::string; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 vector<string> wrong_certs; | 48 vector<string> wrong_certs; |
49 for (size_t i = 1; i < certs->size(); i++) { | 49 for (size_t i = 1; i < certs->size(); i++) { |
50 wrong_certs.push_back((*certs)[i]); | 50 wrong_certs.push_back((*certs)[i]); |
51 } | 51 } |
52 ASSERT_FALSE(verifier->VerifyProof("foo.com", server_config, wrong_certs, | 52 ASSERT_FALSE(verifier->VerifyProof("foo.com", server_config, wrong_certs, |
53 signature, &error_details)); | 53 signature, &error_details)); |
54 #endif // 0 | 54 #endif // 0 |
55 } | 55 } |
56 | 56 |
| 57 static const unsigned char cert_data_0[] = { |
| 58 0x30, 0x82, 0x01, 0xdc, 0x30, 0x82, 0x01, 0x47, 0xa0, 0x03, |
| 59 0x02, 0x01, 0x02, 0x02, 0x01, 0x04, 0x30, 0x0b, 0x06, 0x09, |
| 60 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x30, |
| 61 0x2c, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, |
| 62 0x13, 0x07, 0x41, 0x63, 0x6d, 0x65, 0x20, 0x43, 0x6f, 0x31, |
| 63 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x0f, |
| 64 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6d, 0x65, 0x64, 0x69, 0x61, |
| 65 0x74, 0x65, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, |
| 66 0x33, 0x30, 0x31, 0x30, 0x31, 0x31, 0x30, 0x30, 0x30, 0x30, |
| 67 0x30, 0x5a, 0x17, 0x0d, 0x32, 0x33, 0x31, 0x32, 0x33, 0x31, |
| 68 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5a, 0x30, 0x33, 0x31, |
| 69 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x07, |
| 70 0x41, 0x63, 0x6d, 0x65, 0x20, 0x43, 0x6f, 0x31, 0x1f, 0x30, |
| 71 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x16, 0x45, 0x43, |
| 72 0x44, 0x53, 0x41, 0x20, 0x4c, 0x65, 0x61, 0x66, 0x20, 0x63, |
| 73 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, |
| 74 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, |
| 75 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, |
| 76 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x6d, 0x48, 0xd0, |
| 77 0x30, 0x76, 0xbb, 0xbf, 0x91, 0xb1, 0xd7, 0x03, 0xc2, 0xfc, |
| 78 0x95, 0x9b, 0xe0, 0xea, 0x42, 0xed, 0x43, 0x2c, 0xa6, 0xb2, |
| 79 0x23, 0xc4, 0x52, 0x33, 0x93, 0x95, 0x25, 0xfc, 0x16, 0x75, |
| 80 0x83, 0x9e, 0x0f, 0x0f, 0x91, 0xa5, 0x47, 0xb1, 0x21, 0x91, |
| 81 0xd4, 0x94, 0x94, 0x30, 0xb8, 0x00, 0xdc, 0x1c, 0x79, 0x2c, |
| 82 0xfa, 0x72, 0x99, 0x62, 0xb2, 0xfa, 0xaf, 0xb0, 0xca, 0xf2, |
| 83 0x42, 0xa3, 0x52, 0x30, 0x50, 0x30, 0x0e, 0x06, 0x03, 0x55, |
| 84 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x00, |
| 85 0x80, 0x30, 0x13, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x0c, |
| 86 0x30, 0x0a, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, |
| 87 0x03, 0x01, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, |
| 88 0x01, 0xff, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1b, 0x06, 0x03, |
| 89 0x55, 0x1d, 0x11, 0x04, 0x14, 0x30, 0x12, 0x82, 0x10, 0x74, |
| 90 0x65, 0x73, 0x74, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, |
| 91 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x0b, 0x06, 0x09, 0x2a, |
| 92 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x03, 0x81, |
| 93 0x81, 0x00, 0x5d, 0x23, 0x47, 0xb4, 0xb5, 0x0f, 0x38, 0x18, |
| 94 0xcd, 0x63, 0x90, 0x24, 0x37, 0xf1, 0xda, 0x67, 0x66, 0xa4, |
| 95 0xfe, 0x8d, 0x53, 0x3f, 0xc5, 0xa7, 0x10, 0xe6, 0x21, 0xa3, |
| 96 0x1d, 0xb7, 0x42, 0xb0, 0x1a, 0xe7, 0xd7, 0x83, 0x3d, 0xea, |
| 97 0x7b, 0x6b, 0x89, 0x85, 0xbb, 0x13, 0x77, 0x4d, 0x45, 0xab, |
| 98 0xb2, 0xe7, 0x1e, 0xac, 0x6e, 0x74, 0xb6, 0x9f, 0xc4, 0xe0, |
| 99 0x76, 0x1c, 0xe4, 0x13, 0xe9, 0x6c, 0xb1, 0x20, 0xa3, 0x34, |
| 100 0xe8, 0x1e, 0x8a, 0x71, 0x51, 0xcb, 0x00, 0x44, 0x71, 0x64, |
| 101 0xf6, 0x4b, 0x9e, 0x9a, 0x2d, 0xd9, 0x9a, 0x44, 0x62, 0xf5, |
| 102 0x8c, 0x3c, 0xc5, 0xec, 0xc1, 0x1c, 0xd5, 0xbb, 0x05, 0x53, |
| 103 0x33, 0xaf, 0x70, 0x44, 0x1d, 0x5b, 0xaa, 0x23, 0x67, 0x30, |
| 104 0x3e, 0xd3, 0xa9, 0x5e, 0xa2, 0x57, 0x84, 0x86, 0xaa, 0xbe, |
| 105 0xbd, 0x7b, 0x4f, 0x74, 0xd9, 0x3b, 0xcd, 0x2e, 0x7e, 0xd1, |
| 106 }; |
| 107 |
| 108 static const unsigned char cert_data_1[] = { |
| 109 0x30, 0x82, 0x01, 0xf8, 0x30, 0x82, 0x01, 0x63, 0xa0, 0x03, |
| 110 0x02, 0x01, 0x02, 0x02, 0x01, 0x02, 0x30, 0x0b, 0x06, 0x09, |
| 111 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x30, |
| 112 0x24, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, |
| 113 0x13, 0x07, 0x41, 0x63, 0x6d, 0x65, 0x20, 0x43, 0x6f, 0x31, |
| 114 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x07, |
| 115 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, |
| 116 0x0d, 0x31, 0x33, 0x30, 0x31, 0x30, 0x31, 0x31, 0x30, 0x30, |
| 117 0x30, 0x30, 0x30, 0x5a, 0x17, 0x0d, 0x32, 0x33, 0x31, 0x32, |
| 118 0x33, 0x31, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5a, 0x30, |
| 119 0x2c, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, |
| 120 0x13, 0x07, 0x41, 0x63, 0x6d, 0x65, 0x20, 0x43, 0x6f, 0x31, |
| 121 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x0f, |
| 122 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6d, 0x65, 0x64, 0x69, 0x61, |
| 123 0x74, 0x65, 0x20, 0x43, 0x41, 0x30, 0x81, 0x9d, 0x30, 0x0b, |
| 124 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, |
| 125 0x01, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, |
| 126 0x81, 0x00, 0xaf, 0x95, 0xdd, 0xa0, 0xeb, 0xd7, 0xc3, 0xba, |
| 127 0xa6, 0xae, 0xdb, 0x6e, 0x05, 0x68, 0xa0, 0x00, 0x15, 0xa1, |
| 128 0x85, 0xd1, 0x89, 0xba, 0xbe, 0x3a, 0x7a, 0x3b, 0x8c, 0x3b, |
| 129 0x41, 0x07, 0x76, 0x63, 0x71, 0x28, 0xf7, 0xbf, 0xa5, 0xfb, |
| 130 0xb3, 0x28, 0x94, 0xf9, 0x9a, 0xde, 0x1d, 0x03, 0x00, 0xce, |
| 131 0x5e, 0x25, 0x06, 0x6a, 0xe6, 0xc7, 0x0a, 0x6b, 0x6d, 0xd3, |
| 132 0x76, 0x95, 0x57, 0xf5, 0x16, 0xf8, 0xf0, 0x43, 0xde, 0xb7, |
| 133 0xc7, 0x1b, 0x0b, 0x83, 0xf4, 0x70, 0xe6, 0x29, 0xa1, 0x8d, |
| 134 0x22, 0x12, 0x9a, 0xdf, 0x4b, 0x31, 0xe8, 0x9b, 0x86, 0x7d, |
| 135 0x95, 0x29, 0x97, 0x18, 0xc1, 0x34, 0x2f, 0xb6, 0xa7, 0xc1, |
| 136 0xc7, 0x46, 0xd6, 0x9c, 0xc6, 0xa6, 0xae, 0x6e, 0xdd, 0x8f, |
| 137 0xbe, 0xc2, 0xec, 0x02, 0x00, 0xd2, 0x54, 0xf6, 0x0f, 0xa0, |
| 138 0xcc, 0xaf, 0x04, 0x85, 0x65, 0x98, 0xa1, 0xea, 0x73, 0xf1, |
| 139 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x38, 0x30, 0x36, 0x30, |
| 140 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, |
| 141 0x04, 0x03, 0x02, 0x00, 0x04, 0x30, 0x13, 0x06, 0x03, 0x55, |
| 142 0x1d, 0x25, 0x04, 0x0c, 0x30, 0x0a, 0x06, 0x08, 0x2b, 0x06, |
| 143 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x30, 0x0f, 0x06, 0x03, |
| 144 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05, 0x30, 0x03, |
| 145 0x01, 0x01, 0xff, 0x30, 0x0b, 0x06, 0x09, 0x2a, 0x86, 0x48, |
| 146 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x03, 0x81, 0x81, 0x00, |
| 147 0x9a, 0x68, 0x79, 0x17, 0x6c, 0x13, 0x20, 0xb3, 0x5f, 0x01, |
| 148 0xca, 0xae, 0xc0, 0xbf, 0xd2, 0x7b, 0x98, 0xbf, 0xdd, 0x4d, |
| 149 0xd1, 0xc3, 0xa5, 0xab, 0x01, 0x47, 0x2e, 0xc8, 0x61, 0xb4, |
| 150 0xf5, 0x1d, 0x55, 0x04, 0xf0, 0xeb, 0x5d, 0x84, 0x5a, 0x78, |
| 151 0x09, 0xb0, 0xf1, 0x42, 0x64, 0x14, 0xe8, 0x9e, 0xba, 0xc3, |
| 152 0x38, 0x32, 0xd3, 0x16, 0xfe, 0xe1, 0x65, 0x1f, 0x76, 0xda, |
| 153 0xe4, 0xc0, 0x83, 0x62, 0x4a, 0xae, 0xd0, 0x4e, 0x00, 0x2e, |
| 154 0x38, 0x52, 0x91, 0x81, 0x62, 0x94, 0xb0, 0x3d, 0x69, 0xb3, |
| 155 0x87, 0x72, 0x39, 0x55, 0x94, 0x9e, 0xca, 0x2c, 0xca, 0x51, |
| 156 0x3c, 0xd3, 0x3f, 0xd2, 0x1c, 0x92, 0xd3, 0xde, 0xdf, 0xba, |
| 157 0xbc, 0x45, 0x9b, 0x30, 0x99, 0xb4, 0x39, 0xf8, 0x17, 0x55, |
| 158 0x94, 0x7d, 0x3a, 0xba, 0x0e, 0xe9, 0x3f, 0x2d, 0xbc, 0xf0, |
| 159 0xea, 0x6d, 0x17, 0x85, 0x23, 0xe4, 0xca, 0x94, |
| 160 }; |
| 161 |
| 162 static const unsigned char signature_data_0[] = { |
| 163 0x30, 0x45, 0x02, 0x20, 0x15, 0xb7, 0x9f, 0xe3, 0xd9, 0x7a, |
| 164 0x3c, 0x3b, 0x18, 0xb0, 0xdb, 0x60, 0x23, 0x56, 0xa0, 0x06, |
| 165 0x4e, 0x70, 0xa3, 0xf7, 0x4b, 0xe5, 0x0d, 0x69, 0xf0, 0x35, |
| 166 0x8c, 0xae, 0xb5, 0x54, 0x32, 0xe9, 0x02, 0x21, 0x00, 0xf7, |
| 167 0xe3, 0x06, 0x99, 0x16, 0x56, 0x7e, 0xab, 0x33, 0x53, 0x0d, |
| 168 0xde, 0xbe, 0xef, 0x6d, 0xb0, 0xc7, 0xa6, 0x63, 0xaf, 0x8d, |
| 169 0xab, 0x34, 0xa9, 0xc0, 0x63, 0x88, 0x47, 0x17, 0x4c, 0x4c, |
| 170 0x04, |
| 171 }; |
| 172 |
| 173 static const unsigned char signature_data_1[] = { |
| 174 0x30, 0x44, 0x02, 0x20, 0x69, 0x60, 0x55, 0xbb, 0x11, 0x93, |
| 175 0x6a, 0xdc, 0x9b, 0x61, 0x2c, 0x60, 0x19, 0xbc, 0x15, 0x55, |
| 176 0xcf, 0xf2, 0x8e, 0x2e, 0x27, 0x0b, 0x69, 0xef, 0x33, 0x25, |
| 177 0x1e, 0x5d, 0x8c, 0x00, 0x11, 0xef, 0x02, 0x20, 0x0c, 0x26, |
| 178 0xfe, 0x0b, 0x06, 0x8f, 0xe8, 0xe2, 0x02, 0x63, 0xe5, 0x43, |
| 179 0x0d, 0xc9, 0x80, 0x4d, 0xe9, 0x6f, 0x6e, 0x18, 0xdb, 0xb0, |
| 180 0x04, 0x2a, 0x45, 0x37, 0x1a, 0x60, 0x0e, 0xc6, 0xc4, 0x8f, |
| 181 }; |
| 182 |
| 183 static const unsigned char signature_data_2[] = { |
| 184 0x30, 0x45, 0x02, 0x21, 0x00, 0xd5, 0x43, 0x36, 0x60, 0x50, |
| 185 0xce, 0xe0, 0x00, 0x51, 0x02, 0x84, 0x95, 0x51, 0x47, 0xaf, |
| 186 0xe4, 0xf9, 0xe1, 0x23, 0xae, 0x21, 0xb4, 0x98, 0xd1, 0xa3, |
| 187 0x5f, 0x3b, 0xf3, 0x6a, 0x65, 0x44, 0x6b, 0x02, 0x20, 0x30, |
| 188 0x7e, 0xb4, 0xea, 0xf0, 0xda, 0xdb, 0xbd, 0x38, 0xb9, 0x7a, |
| 189 0x5d, 0x12, 0x04, 0x0e, 0xc2, 0xf0, 0xb1, 0x0e, 0x25, 0xf8, |
| 190 0x0a, 0x27, 0xa3, 0x16, 0x94, 0xac, 0x1e, 0xb8, 0x6e, 0x00, |
| 191 0x05, |
| 192 }; |
| 193 |
| 194 TEST(Proof, VerifyECDSAKnownAnswerTest) { |
| 195 scoped_ptr<ProofVerifier> verifier( |
| 196 CryptoTestUtils::ProofVerifierForTesting()); |
| 197 |
| 198 const string server_config = "server config bytes"; |
| 199 const string hostname = "test.example.com"; |
| 200 |
| 201 vector<string> certs(2); |
| 202 certs[0].assign(reinterpret_cast<const char*>(cert_data_0), |
| 203 sizeof(cert_data_0)); |
| 204 certs[1].assign(reinterpret_cast<const char*>(cert_data_1), |
| 205 sizeof(cert_data_1)); |
| 206 |
| 207 /* Signatures are nondeterministic, so we test multiple signatures |
| 208 * on the same server_config. */ |
| 209 vector<string> signatures(3); |
| 210 signatures[0].assign(reinterpret_cast<const char*>(signature_data_0), |
| 211 sizeof(signature_data_0)); |
| 212 signatures[1].assign(reinterpret_cast<const char*>(signature_data_1), |
| 213 sizeof(signature_data_1)); |
| 214 signatures[2].assign(reinterpret_cast<const char*>(signature_data_2), |
| 215 sizeof(signature_data_2)); |
| 216 |
| 217 for (size_t i = 0; i < signatures.size(); i++) { |
| 218 const string& signature = signatures[i]; |
| 219 string error_details; |
| 220 ASSERT_TRUE(verifier->VerifyProof(hostname, server_config, certs, signature, |
| 221 &error_details)); |
| 222 ASSERT_FALSE(verifier->VerifyProof("foo.com", server_config, certs, |
| 223 signature, &error_details)); |
| 224 ASSERT_FALSE( |
| 225 verifier->VerifyProof(hostname, server_config.substr(1, string::npos), |
| 226 certs, signature, &error_details)); |
| 227 const string corrupt_signature = "1" + signature; |
| 228 ASSERT_FALSE(verifier->VerifyProof(hostname, server_config, certs, |
| 229 corrupt_signature, &error_details)); |
| 230 |
| 231 vector<string> wrong_certs; |
| 232 for (size_t i = 1; i < certs.size(); i++) { |
| 233 wrong_certs.push_back(certs[i]); |
| 234 } |
| 235 ASSERT_FALSE(verifier->VerifyProof("foo.com", server_config, wrong_certs, |
| 236 signature, &error_details)); |
| 237 } |
| 238 } |
| 239 |
57 } // namespace test | 240 } // namespace test |
58 } // namespace net | 241 } // namespace net |
OLD | NEW |