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

Side by Side Diff: content/child/webcrypto/test/ecdsa_unittest.cc

Issue 835633002: Change the WebCrypto behavior when importing EC private keys without a public key. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@add_private_tests
Patch Set: Created 5 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/stl_util.h" 5 #include "base/stl_util.h"
6 #include "content/child/webcrypto/algorithm_dispatch.h" 6 #include "content/child/webcrypto/algorithm_dispatch.h"
7 #include "content/child/webcrypto/crypto_data.h" 7 #include "content/child/webcrypto/crypto_data.h"
8 #include "content/child/webcrypto/jwk.h" 8 #include "content/child/webcrypto/jwk.h"
9 #include "content/child/webcrypto/status.h" 9 #include "content/child/webcrypto/status.h"
10 #include "content/child/webcrypto/test/test_helpers.h" 10 #include "content/child/webcrypto/test/test_helpers.h"
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 339
340 // Export the key as PKCS8 340 // Export the key as PKCS8
341 ASSERT_EQ(Status::Success(), 341 ASSERT_EQ(Status::Success(),
342 ExportKey(blink::WebCryptoKeyFormatPkcs8, key, &exported_bytes)); 342 ExportKey(blink::WebCryptoKeyFormatPkcs8, key, &exported_bytes));
343 EXPECT_EQ(CryptoData(pkcs8_bytes), CryptoData(exported_bytes)); 343 EXPECT_EQ(CryptoData(pkcs8_bytes), CryptoData(exported_bytes));
344 344
345 // ------------------------------------------------- 345 // -------------------------------------------------
346 // Test from PKCS8, and then export to {JWK, PKCS8} 346 // Test from PKCS8, and then export to {JWK, PKCS8}
347 // ------------------------------------------------- 347 // -------------------------------------------------
348 348
349 // The imported PKCS8 bytes may differ from the exported bytes (in the case
350 // where the publicKey was missing, it will be synthesized and written back
351 // during export).
352 std::vector<uint8_t> pkcs8_input_bytes;
353 if (test->HasKey("pkcs8_input"))
354 pkcs8_input_bytes = GetBytesFromHexString(test, "pkcs8_input");
355 CryptoData pkcs8_input_data(pkcs8_input_bytes.empty() ? pkcs8_bytes
356 : pkcs8_input_bytes);
357
349 // Import the key using PKCS8 358 // Import the key using PKCS8
350 ASSERT_EQ(Status::Success(), 359 ASSERT_EQ(Status::Success(),
351 ImportKey(blink::WebCryptoKeyFormatPkcs8, CryptoData(pkcs8_bytes), 360 ImportKey(blink::WebCryptoKeyFormatPkcs8, pkcs8_input_data,
352 CreateEcdsaImportAlgorithm(curve), true, 361 CreateEcdsaImportAlgorithm(curve), true,
353 blink::WebCryptoKeyUsageSign, &key)); 362 blink::WebCryptoKeyUsageSign, &key));
354 363
355 // Export the key as PKCS8 364 // Export the key as PKCS8
356 ASSERT_EQ(Status::Success(), 365 ASSERT_EQ(Status::Success(),
357 ExportKey(blink::WebCryptoKeyFormatPkcs8, key, &exported_bytes)); 366 ExportKey(blink::WebCryptoKeyFormatPkcs8, key, &exported_bytes));
358 EXPECT_EQ(CryptoData(pkcs8_bytes), CryptoData(exported_bytes)); 367 EXPECT_EQ(CryptoData(pkcs8_bytes), CryptoData(exported_bytes));
359 368
360 // Export the key as JWK 369 // Export the key as JWK
361 ASSERT_EQ(Status::Success(), 370 ASSERT_EQ(Status::Success(),
362 ExportKey(blink::WebCryptoKeyFormatJwk, key, &exported_bytes)); 371 ExportKey(blink::WebCryptoKeyFormatJwk, key, &exported_bytes));
363 EXPECT_EQ(CryptoData(jwk_bytes), CryptoData(exported_bytes)); 372 EXPECT_EQ(CryptoData(jwk_bytes), CryptoData(exported_bytes));
364 } 373 }
365 } 374 }
366 375
367 } // namespace 376 } // namespace
368 377
369 } // namespace webcrypto 378 } // namespace webcrypto
370 379
371 } // namespace content 380 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698