OLD | NEW |
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 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 | 338 |
339 // Export the key as PKCS8 | 339 // Export the key as PKCS8 |
340 ASSERT_EQ(Status::Success(), | 340 ASSERT_EQ(Status::Success(), |
341 ExportKey(blink::WebCryptoKeyFormatPkcs8, key, &exported_bytes)); | 341 ExportKey(blink::WebCryptoKeyFormatPkcs8, key, &exported_bytes)); |
342 EXPECT_EQ(CryptoData(pkcs8_bytes), CryptoData(exported_bytes)); | 342 EXPECT_EQ(CryptoData(pkcs8_bytes), CryptoData(exported_bytes)); |
343 | 343 |
344 // ------------------------------------------------- | 344 // ------------------------------------------------- |
345 // Test from PKCS8, and then export to {JWK, PKCS8} | 345 // Test from PKCS8, and then export to {JWK, PKCS8} |
346 // ------------------------------------------------- | 346 // ------------------------------------------------- |
347 | 347 |
| 348 // The imported PKCS8 bytes may differ from the exported bytes (in the case |
| 349 // where the publicKey was missing, it will be synthesized and written back |
| 350 // during export). |
| 351 std::vector<uint8_t> pkcs8_input_bytes; |
| 352 if (test->HasKey("pkcs8_input")) |
| 353 pkcs8_input_bytes = GetBytesFromHexString(test, "pkcs8_input"); |
| 354 CryptoData pkcs8_input_data(pkcs8_input_bytes.empty() ? pkcs8_bytes |
| 355 : pkcs8_input_bytes); |
| 356 |
348 // Import the key using PKCS8 | 357 // Import the key using PKCS8 |
349 ASSERT_EQ(Status::Success(), | 358 ASSERT_EQ(Status::Success(), |
350 ImportKey(blink::WebCryptoKeyFormatPkcs8, CryptoData(pkcs8_bytes), | 359 ImportKey(blink::WebCryptoKeyFormatPkcs8, pkcs8_input_data, |
351 CreateEcdsaImportAlgorithm(curve), true, | 360 CreateEcdsaImportAlgorithm(curve), true, |
352 blink::WebCryptoKeyUsageSign, &key)); | 361 blink::WebCryptoKeyUsageSign, &key)); |
353 | 362 |
354 // Export the key as PKCS8 | 363 // Export the key as PKCS8 |
355 ASSERT_EQ(Status::Success(), | 364 ASSERT_EQ(Status::Success(), |
356 ExportKey(blink::WebCryptoKeyFormatPkcs8, key, &exported_bytes)); | 365 ExportKey(blink::WebCryptoKeyFormatPkcs8, key, &exported_bytes)); |
357 EXPECT_EQ(CryptoData(pkcs8_bytes), CryptoData(exported_bytes)); | 366 EXPECT_EQ(CryptoData(pkcs8_bytes), CryptoData(exported_bytes)); |
358 | 367 |
359 // Export the key as JWK | 368 // Export the key as JWK |
360 ASSERT_EQ(Status::Success(), | 369 ASSERT_EQ(Status::Success(), |
361 ExportKey(blink::WebCryptoKeyFormatJwk, key, &exported_bytes)); | 370 ExportKey(blink::WebCryptoKeyFormatJwk, key, &exported_bytes)); |
362 EXPECT_EQ(CryptoData(jwk_bytes), CryptoData(exported_bytes)); | 371 EXPECT_EQ(CryptoData(jwk_bytes), CryptoData(exported_bytes)); |
363 } | 372 } |
364 } | 373 } |
365 | 374 |
366 } // namespace | 375 } // namespace |
367 | 376 |
368 } // namespace webcrypto | 377 } // namespace webcrypto |
369 | 378 |
370 } // namespace content | 379 } // namespace content |
OLD | NEW |