| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "crypto/signature_verifier.h" | 5 #include "crypto/signature_verifier.h" |
| 6 | 6 |
| 7 #include "base/numerics/safe_conversions.h" | 7 #include "base/numerics/safe_conversions.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 TEST(SignatureVerifierTest, BasicTest) { | 10 TEST(SignatureVerifierTest, BasicTest) { |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 bad_signature, sizeof(bad_signature), | 251 bad_signature, sizeof(bad_signature), |
| 252 public_key_info, sizeof(public_key_info)); | 252 public_key_info, sizeof(public_key_info)); |
| 253 | 253 |
| 254 // A crypto library (e.g., NSS) may detect that the signature is corrupted | 254 // A crypto library (e.g., NSS) may detect that the signature is corrupted |
| 255 // and cause VerifyInit to return false, so it is fine for 'ok' to be false. | 255 // and cause VerifyInit to return false, so it is fine for 'ok' to be false. |
| 256 if (ok) { | 256 if (ok) { |
| 257 verifier.VerifyUpdate(tbs_certificate, sizeof(tbs_certificate)); | 257 verifier.VerifyUpdate(tbs_certificate, sizeof(tbs_certificate)); |
| 258 ok = verifier.VerifyFinal(); | 258 ok = verifier.VerifyFinal(); |
| 259 EXPECT_FALSE(ok); | 259 EXPECT_FALSE(ok); |
| 260 } | 260 } |
| 261 |
| 262 // Test 5: import an invalid key. |
| 263 uint8_t bad_public_key_info[sizeof(public_key_info)]; |
| 264 memcpy(bad_public_key_info, public_key_info, sizeof(public_key_info)); |
| 265 bad_public_key_info[0] += 1; // Corrupt part of the SPKI syntax. |
| 266 ok = verifier.VerifyInit(signature_algorithm, |
| 267 sizeof(signature_algorithm), |
| 268 signature, sizeof(signature), |
| 269 bad_public_key_info, sizeof(bad_public_key_info)); |
| 270 EXPECT_FALSE(ok); |
| 271 |
| 272 // Test 6: import a key with extra data. |
| 273 uint8_t long_public_key_info[sizeof(public_key_info) + 5]; |
| 274 memset(long_public_key_info, 0, sizeof(long_public_key_info)); |
| 275 memcpy(long_public_key_info, public_key_info, sizeof(public_key_info)); |
| 276 ok = verifier.VerifyInit(signature_algorithm, |
| 277 sizeof(signature_algorithm), |
| 278 signature, sizeof(signature), |
| 279 long_public_key_info, sizeof(long_public_key_info)); |
| 280 EXPECT_FALSE(ok); |
| 261 } | 281 } |
| 262 | 282 |
| 263 ////////////////////////////////////////////////////////////////////// | 283 ////////////////////////////////////////////////////////////////////// |
| 264 // | 284 // |
| 265 // RSA-PSS signature verification known answer test | 285 // RSA-PSS signature verification known answer test |
| 266 // | 286 // |
| 267 ////////////////////////////////////////////////////////////////////// | 287 ////////////////////////////////////////////////////////////////////// |
| 268 | 288 |
| 269 // The following RSA-PSS signature test vectors come from the pss-vect.txt | 289 // The following RSA-PSS signature test vectors come from the pss-vect.txt |
| 270 // file downloaded from | 290 // file downloaded from |
| (...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1131 &public_key_info[0], | 1151 &public_key_info[0], |
| 1132 public_key_info.size()); | 1152 public_key_info.size()); |
| 1133 signature[0] -= 1; | 1153 signature[0] -= 1; |
| 1134 ASSERT_TRUE(ok); | 1154 ASSERT_TRUE(ok); |
| 1135 verifier.VerifyUpdate(&message[0], message.size()); | 1155 verifier.VerifyUpdate(&message[0], message.size()); |
| 1136 ok = verifier.VerifyFinal(); | 1156 ok = verifier.VerifyFinal(); |
| 1137 EXPECT_FALSE(ok); | 1157 EXPECT_FALSE(ok); |
| 1138 } | 1158 } |
| 1139 } | 1159 } |
| 1140 } | 1160 } |
| OLD | NEW |