Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Unified Diff: net/quic/crypto/proof_test.cc

Issue 17385010: OpenSSL/NSS implementation of ProofVerfifier. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compiler error Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/quic/crypto/proof_test.cc
diff --git a/net/quic/crypto/proof_test.cc b/net/quic/crypto/proof_test.cc
index 3423b50fcc293e411ff265ab42af3ff00e099fea..63013c512e6964964cfd78fc4e2c9b48f512765d 100644
--- a/net/quic/crypto/proof_test.cc
+++ b/net/quic/crypto/proof_test.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "net/base/net_errors.h"
+#include "net/base/test_completion_callback.h"
#include "net/quic/crypto/proof_source.h"
#include "net/quic/crypto/proof_verifier.h"
#include "net/quic/test_tools/crypto_test_utils.h"
@@ -34,25 +36,250 @@ TEST(Proof, Verify) {
ASSERT_EQ(first_certs, certs);
ASSERT_EQ(signature, first_signature);
- ASSERT_TRUE(verifier->VerifyProof(hostname, server_config, *certs, signature,
- &error_details));
- ASSERT_FALSE(verifier->VerifyProof("foo.com", server_config, *certs,
- signature, &error_details));
- ASSERT_FALSE(
- verifier->VerifyProof(hostname, server_config.substr(1, string::npos),
- *certs, signature, &error_details));
+ int rv;
+ TestCompletionCallback callback;
+ rv = verifier->VerifyProof(hostname, server_config, *certs, signature,
+ callback.callback(), &error_details);
+ if (rv == ERR_IO_PENDING)
+ rv = callback.WaitForResult();
+ ASSERT_EQ(OK, rv);
+
+ rv = verifier->VerifyProof("foo.com", server_config, *certs,
+ signature, callback.callback(), &error_details);
+ if (rv == ERR_IO_PENDING)
+ rv = callback.WaitForResult();
+ ASSERT_EQ(ERR_FAILED, rv);
+
+ rv = verifier->VerifyProof(hostname, server_config.substr(1, string::npos),
+ *certs, signature, callback.callback(),
+ &error_details);
+ if (rv == ERR_IO_PENDING)
+ rv = callback.WaitForResult();
+ ASSERT_EQ(ERR_FAILED, rv);
+
const string corrupt_signature = "1" + signature;
- ASSERT_FALSE(verifier->VerifyProof(hostname, server_config, *certs,
- corrupt_signature, &error_details));
+ rv = verifier->VerifyProof(hostname, server_config, *certs,
+ corrupt_signature, callback.callback(),
+ &error_details);
+ if (rv == ERR_IO_PENDING)
+ rv = callback.WaitForResult();
+ ASSERT_EQ(ERR_FAILED, rv);
vector<string> wrong_certs;
for (size_t i = 1; i < certs->size(); i++) {
wrong_certs.push_back((*certs)[i]);
}
- ASSERT_FALSE(verifier->VerifyProof("foo.com", server_config, wrong_certs,
- signature, &error_details));
+ rv = verifier->VerifyProof("foo.com", server_config, wrong_certs,
+ signature, callback.callback(), &error_details);
+ if (rv == ERR_IO_PENDING)
+ rv = callback.WaitForResult();
+ ASSERT_EQ(ERR_FAILED, rv);
#endif // 0
}
+static const unsigned char cert_data_0[] = {
+ 0x30, 0x82, 0x01, 0xdc, 0x30, 0x82, 0x01, 0x47, 0xa0, 0x03,
+ 0x02, 0x01, 0x02, 0x02, 0x01, 0x04, 0x30, 0x0b, 0x06, 0x09,
+ 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x30,
+ 0x2c, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a,
+ 0x13, 0x07, 0x41, 0x63, 0x6d, 0x65, 0x20, 0x43, 0x6f, 0x31,
+ 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x0f,
+ 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6d, 0x65, 0x64, 0x69, 0x61,
+ 0x74, 0x65, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31,
+ 0x33, 0x30, 0x31, 0x30, 0x31, 0x31, 0x30, 0x30, 0x30, 0x30,
+ 0x30, 0x5a, 0x17, 0x0d, 0x32, 0x33, 0x31, 0x32, 0x33, 0x31,
+ 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5a, 0x30, 0x33, 0x31,
+ 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x07,
+ 0x41, 0x63, 0x6d, 0x65, 0x20, 0x43, 0x6f, 0x31, 0x1f, 0x30,
+ 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x16, 0x45, 0x43,
+ 0x44, 0x53, 0x41, 0x20, 0x4c, 0x65, 0x61, 0x66, 0x20, 0x63,
+ 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65,
+ 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce,
+ 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
+ 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x6d, 0x48, 0xd0,
+ 0x30, 0x76, 0xbb, 0xbf, 0x91, 0xb1, 0xd7, 0x03, 0xc2, 0xfc,
+ 0x95, 0x9b, 0xe0, 0xea, 0x42, 0xed, 0x43, 0x2c, 0xa6, 0xb2,
+ 0x23, 0xc4, 0x52, 0x33, 0x93, 0x95, 0x25, 0xfc, 0x16, 0x75,
+ 0x83, 0x9e, 0x0f, 0x0f, 0x91, 0xa5, 0x47, 0xb1, 0x21, 0x91,
+ 0xd4, 0x94, 0x94, 0x30, 0xb8, 0x00, 0xdc, 0x1c, 0x79, 0x2c,
+ 0xfa, 0x72, 0x99, 0x62, 0xb2, 0xfa, 0xaf, 0xb0, 0xca, 0xf2,
+ 0x42, 0xa3, 0x52, 0x30, 0x50, 0x30, 0x0e, 0x06, 0x03, 0x55,
+ 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04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 0xd5, 0xbb, 0x05, 0x53,
+ 0x33, 0xaf, 0x70, 0x44, 0x1d, 0x5b, 0xaa, 0x23, 0x67, 0x30,
+ 0x3e, 0xd3, 0xa9, 0x5e, 0xa2, 0x57, 0x84, 0x86, 0xaa, 0xbe,
+ 0xbd, 0x7b, 0x4f, 0x74, 0xd9, 0x3b, 0xcd, 0x2e, 0x7e, 0xd1,
+};
+
+static const unsigned char cert_data_1[] = {
+ 0x30, 0x82, 0x01, 0xf8, 0x30, 0x82, 0x01, 0x63, 0xa0, 0x03,
+ 0x02, 0x01, 0x02, 0x02, 0x01, 0x02, 0x30, 0x0b, 0x06, 0x09,
+ 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x30,
+ 0x24, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a,
+ 0x13, 0x07, 0x41, 0x63, 0x6d, 0x65, 0x20, 0x43, 0x6f, 0x31,
+ 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x07,
+ 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17,
+ 0x0d, 0x31, 0x33, 0x30, 0x31, 0x30, 0x31, 0x31, 0x30, 0x30,
+ 0x30, 0x30, 0x30, 0x5a, 0x17, 0x0d, 0x32, 0x33, 0x31, 0x32,
+ 0x33, 0x31, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5a, 0x30,
+ 0x2c, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a,
+ 0x13, 0x07, 0x41, 0x63, 0x6d, 0x65, 0x20, 0x43, 0x6f, 0x31,
+ 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x0f,
+ 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6d, 0x65, 0x64, 0x69, 0x61,
+ 0x74, 0x65, 0x20, 0x43, 0x41, 0x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0x17, 0x85, 0x23, 0xe4, 0xca, 0x94,
+};
+
+static const unsigned char signature_data_0[] = {
+ 0x30, 0x45, 0x02, 0x20, 0x15, 0xb7, 0x9f, 0xe3, 0xd9, 0x7a,
+ 0x3c, 0x3b, 0x18, 0xb0, 0xdb, 0x60, 0x23, 0x56, 0xa0, 0x06,
+ 0x4e, 0x70, 0xa3, 0xf7, 0x4b, 0xe5, 0x0d, 0x69, 0xf0, 0x35,
+ 0x8c, 0xae, 0xb5, 0x54, 0x32, 0xe9, 0x02, 0x21, 0x00, 0xf7,
+ 0xe3, 0x06, 0x99, 0x16, 0x56, 0x7e, 0xab, 0x33, 0x53, 0x0d,
+ 0xde, 0xbe, 0xef, 0x6d, 0xb0, 0xc7, 0xa6, 0x63, 0xaf, 0x8d,
+ 0xab, 0x34, 0xa9, 0xc0, 0x63, 0x88, 0x47, 0x17, 0x4c, 0x4c,
+ 0x04,
+};
+
+static const unsigned char signature_data_1[] = {
+ 0x30, 0x44, 0x02, 0x20, 0x69, 0x60, 0x55, 0xbb, 0x11, 0x93,
+ 0x6a, 0xdc, 0x9b, 0x61, 0x2c, 0x60, 0x19, 0xbc, 0x15, 0x55,
+ 0xcf, 0xf2, 0x8e, 0x2e, 0x27, 0x0b, 0x69, 0xef, 0x33, 0x25,
+ 0x1e, 0x5d, 0x8c, 0x00, 0x11, 0xef, 0x02, 0x20, 0x0c, 0x26,
+ 0xfe, 0x0b, 0x06, 0x8f, 0xe8, 0xe2, 0x02, 0x63, 0xe5, 0x43,
+ 0x0d, 0xc9, 0x80, 0x4d, 0xe9, 0x6f, 0x6e, 0x18, 0xdb, 0xb0,
+ 0x04, 0x2a, 0x45, 0x37, 0x1a, 0x60, 0x0e, 0xc6, 0xc4, 0x8f,
+};
+
+static const unsigned char signature_data_2[] = {
+ 0x30, 0x45, 0x02, 0x21, 0x00, 0xd5, 0x43, 0x36, 0x60, 0x50,
+ 0xce, 0xe0, 0x00, 0x51, 0x02, 0x84, 0x95, 0x51, 0x47, 0xaf,
+ 0xe4, 0xf9, 0xe1, 0x23, 0xae, 0x21, 0xb4, 0x98, 0xd1, 0xa3,
+ 0x5f, 0x3b, 0xf3, 0x6a, 0x65, 0x44, 0x6b, 0x02, 0x20, 0x30,
+ 0x7e, 0xb4, 0xea, 0xf0, 0xda, 0xdb, 0xbd, 0x38, 0xb9, 0x7a,
+ 0x5d, 0x12, 0x04, 0x0e, 0xc2, 0xf0, 0xb1, 0x0e, 0x25, 0xf8,
+ 0x0a, 0x27, 0xa3, 0x16, 0x94, 0xac, 0x1e, 0xb8, 0x6e, 0x00,
+ 0x05,
+};
+
+TEST(Proof, VerifyECDSAKnownAnswerTest) {
+ TestCompletionCallback callback;
+ scoped_ptr<ProofVerifier> verifier(
+ CryptoTestUtils::ProofVerifierForTesting());
+
+ const string server_config = "server config bytes";
+ const string hostname = "test.example.com";
+
+ vector<string> certs(2);
+ certs[0].assign(reinterpret_cast<const char*>(cert_data_0),
+ sizeof(cert_data_0));
+ certs[1].assign(reinterpret_cast<const char*>(cert_data_1),
+ sizeof(cert_data_1));
+
+ // Signatures are nondeterministic, so we test multiple signatures
+ // on the same server_config.
+ vector<string> signatures(3);
+ signatures[0].assign(reinterpret_cast<const char*>(signature_data_0),
+ sizeof(signature_data_0));
+ signatures[1].assign(reinterpret_cast<const char*>(signature_data_1),
+ sizeof(signature_data_1));
+ signatures[2].assign(reinterpret_cast<const char*>(signature_data_2),
+ sizeof(signature_data_2));
+
+ int rv;
+ for (size_t i = 0; i < signatures.size(); i++) {
+ const string& signature = signatures[i];
+ string error_details;
+ rv = verifier->VerifyProof(hostname, server_config, certs, signature,
+ callback.callback(), &error_details);
+ if (rv == ERR_IO_PENDING)
+ rv = callback.WaitForResult();
+ EXPECT_EQ(OK, rv);
+
+ rv = verifier->VerifyProof("foo.com", server_config, certs, signature,
+ callback.callback(), &error_details);
+ if (rv == ERR_IO_PENDING)
+ rv = callback.WaitForResult();
+ EXPECT_EQ(ERR_FAILED, rv);
+
+ rv = verifier->VerifyProof(hostname, server_config.substr(1, string::npos),
+ certs, signature, callback.callback(),
+ &error_details);
+ if (rv == ERR_IO_PENDING)
+ rv = callback.WaitForResult();
+ EXPECT_EQ(ERR_FAILED, rv);
+
+ const string corrupt_signature = "1" + signature;
+ rv = verifier->VerifyProof(hostname, server_config, certs,
+ corrupt_signature, callback.callback(),
+ &error_details);
+ if (rv == ERR_IO_PENDING)
+ rv = callback.WaitForResult();
+ EXPECT_EQ(ERR_FAILED, rv);
+
+ vector<string> wrong_certs;
+ for (size_t i = 1; i < certs.size(); i++) {
+ wrong_certs.push_back(certs[i]);
+ }
+ rv = verifier->VerifyProof("foo.com", server_config, wrong_certs, signature,
+ callback.callback(), &error_details);
+ if (rv == ERR_IO_PENDING)
+ rv = callback.WaitForResult();
+ EXPECT_EQ(ERR_FAILED, rv);
+ }
+}
wtc 2013/06/24 22:36:56 Please use the following code for this new unit te
ramant (doing other things) 2013/06/28 19:16:56 I have used the latest code from you for the above
+
} // namespace test
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698