Commit 82ca1533 authored by eroman@chromium.org's avatar eroman@chromium.org

[refactor] Change ordering of wrapkey parameters

crypto.subtle.wrapKey() orders the key to be wrapped before the wrapping key. Use the same convention throughout webcrypto code to avoid confusion.

BUG=245025

Review URL: https://codereview.chromium.org/272033003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269478 0039d316-1c4b-4281-b951-d872f2087c98
parent 991229a3
...@@ -229,10 +229,10 @@ Status ExportKeyPkcs8(PrivateKey* key, ...@@ -229,10 +229,10 @@ Status ExportKeyPkcs8(PrivateKey* key,
std::vector<uint8>* buffer); std::vector<uint8>* buffer);
// Preconditions: // Preconditions:
// * |wrapping_key| is non-null
// * |key| is non-null // * |key| is non-null
Status WrapSymKeyAesKw(SymKey* wrapping_key, // * |wrapping_key| is non-null
SymKey* key, Status WrapSymKeyAesKw(SymKey* key,
SymKey* wrapping_key,
std::vector<uint8>* buffer); std::vector<uint8>* buffer);
// Unwraps (decrypts) |wrapped_key_data| using AES-KW and places the results in // Unwraps (decrypts) |wrapped_key_data| using AES-KW and places the results in
...@@ -263,10 +263,10 @@ Status DecryptAesKw(SymKey* key, ...@@ -263,10 +263,10 @@ Status DecryptAesKw(SymKey* key,
std::vector<uint8>* buffer); std::vector<uint8>* buffer);
// Preconditions: // Preconditions:
// * |wrapping_key| is non-null
// * |key| is non-null // * |key| is non-null
Status WrapSymKeyRsaEs(PublicKey* wrapping_key, // * |wrapping_key| is non-null
SymKey* key, Status WrapSymKeyRsaEs(SymKey* key,
PublicKey* wrapping_key,
std::vector<uint8>* buffer); std::vector<uint8>* buffer);
// Preconditions: // Preconditions:
......
...@@ -1494,8 +1494,8 @@ Status ImportRsaPublicKey(const blink::WebCryptoAlgorithm& algorithm, ...@@ -1494,8 +1494,8 @@ Status ImportRsaPublicKey(const blink::WebCryptoAlgorithm& algorithm,
return Status::Success(); return Status::Success();
} }
Status WrapSymKeyAesKw(SymKey* wrapping_key, Status WrapSymKeyAesKw(SymKey* key,
SymKey* key, SymKey* wrapping_key,
std::vector<uint8>* buffer) { std::vector<uint8>* buffer) {
// The data size must be at least 16 bytes and a multiple of 8 bytes. // The data size must be at least 16 bytes and a multiple of 8 bytes.
// RFC 3394 does not specify a maximum allowed data length, but since only // RFC 3394 does not specify a maximum allowed data length, but since only
...@@ -1594,8 +1594,8 @@ Status DecryptAesKw(SymKey* wrapping_key, ...@@ -1594,8 +1594,8 @@ Status DecryptAesKw(SymKey* wrapping_key,
return Status::Success(); return Status::Success();
} }
Status WrapSymKeyRsaEs(PublicKey* wrapping_key, Status WrapSymKeyRsaEs(SymKey* key,
SymKey* key, PublicKey* wrapping_key,
std::vector<uint8>* buffer) { std::vector<uint8>* buffer) {
// Check the raw length of the key to be wrapped against the max size allowed // Check the raw length of the key to be wrapped against the max size allowed
// by the RSA wrapping key. With PKCS#1 v1.5 padding used in this function, // by the RSA wrapping key. With PKCS#1 v1.5 padding used in this function,
......
...@@ -462,8 +462,8 @@ Status ExportRsaPublicKey(PublicKey* key, ...@@ -462,8 +462,8 @@ Status ExportRsaPublicKey(PublicKey* key,
return Status::ErrorUnsupported(); return Status::ErrorUnsupported();
} }
Status WrapSymKeyAesKw(SymKey* wrapping_key, Status WrapSymKeyAesKw(SymKey* key,
SymKey* key, SymKey* wrapping_key,
std::vector<uint8>* buffer) { std::vector<uint8>* buffer) {
// TODO(eroman): http://crbug.com/267888 // TODO(eroman): http://crbug.com/267888
return Status::ErrorUnsupported(); return Status::ErrorUnsupported();
...@@ -486,8 +486,8 @@ Status DecryptAesKw(SymKey* key, ...@@ -486,8 +486,8 @@ Status DecryptAesKw(SymKey* key,
return Status::ErrorUnsupported(); return Status::ErrorUnsupported();
} }
Status WrapSymKeyRsaEs(PublicKey* wrapping_key, Status WrapSymKeyRsaEs(SymKey* key,
SymKey* key, PublicKey* wrapping_key,
std::vector<uint8>* buffer) { std::vector<uint8>* buffer) {
// TODO(eroman): http://crbug.com/267888 // TODO(eroman): http://crbug.com/267888
return Status::ErrorUnsupported(); return Status::ErrorUnsupported();
......
...@@ -375,8 +375,8 @@ Status UnwrapKeyRaw(const CryptoData& wrapped_key_data, ...@@ -375,8 +375,8 @@ Status UnwrapKeyRaw(const CryptoData& wrapped_key_data,
} }
} }
Status WrapKeyRaw(const blink::WebCryptoKey& wrapping_key, Status WrapKeyRaw(const blink::WebCryptoKey& key_to_wrap,
const blink::WebCryptoKey& key_to_wrap, const blink::WebCryptoKey& wrapping_key,
const blink::WebCryptoAlgorithm& wrapping_algorithm, const blink::WebCryptoAlgorithm& wrapping_algorithm,
std::vector<uint8>* buffer) { std::vector<uint8>* buffer) {
// A raw key is always a symmetric key. // A raw key is always a symmetric key.
...@@ -393,7 +393,7 @@ Status WrapKeyRaw(const blink::WebCryptoKey& wrapping_key, ...@@ -393,7 +393,7 @@ Status WrapKeyRaw(const blink::WebCryptoKey& wrapping_key,
if (status.IsError()) if (status.IsError())
return status; return status;
return platform::WrapSymKeyAesKw( return platform::WrapSymKeyAesKw(
platform_wrapping_key, platform_key, buffer); platform_key, platform_wrapping_key, buffer);
} }
case blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5: { case blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5: {
platform::PublicKey* platform_wrapping_key; platform::PublicKey* platform_wrapping_key;
...@@ -401,7 +401,7 @@ Status WrapKeyRaw(const blink::WebCryptoKey& wrapping_key, ...@@ -401,7 +401,7 @@ Status WrapKeyRaw(const blink::WebCryptoKey& wrapping_key,
if (status.IsError()) if (status.IsError())
return status; return status;
return platform::WrapSymKeyRsaEs( return platform::WrapSymKeyRsaEs(
platform_wrapping_key, platform_key, buffer); platform_key, platform_wrapping_key, buffer);
} }
default: default:
return Status::ErrorUnsupported(); return Status::ErrorUnsupported();
...@@ -484,8 +484,8 @@ Status UnwrapKeyDecryptAndImport( ...@@ -484,8 +484,8 @@ Status UnwrapKeyDecryptAndImport(
Status WrapKeyExportAndEncrypt( Status WrapKeyExportAndEncrypt(
blink::WebCryptoKeyFormat format, blink::WebCryptoKeyFormat format,
const blink::WebCryptoKey& wrapping_key,
const blink::WebCryptoKey& key_to_wrap, const blink::WebCryptoKey& key_to_wrap,
const blink::WebCryptoKey& wrapping_key,
const blink::WebCryptoAlgorithm& wrapping_algorithm, const blink::WebCryptoAlgorithm& wrapping_algorithm,
std::vector<uint8>* buffer) { std::vector<uint8>* buffer) {
std::vector<uint8> exported_data; std::vector<uint8> exported_data;
...@@ -751,8 +751,8 @@ Status VerifySignature(const blink::WebCryptoAlgorithm& algorithm, ...@@ -751,8 +751,8 @@ Status VerifySignature(const blink::WebCryptoAlgorithm& algorithm,
} }
Status WrapKey(blink::WebCryptoKeyFormat format, Status WrapKey(blink::WebCryptoKeyFormat format,
const blink::WebCryptoKey& wrapping_key,
const blink::WebCryptoKey& key_to_wrap, const blink::WebCryptoKey& key_to_wrap,
const blink::WebCryptoKey& wrapping_key,
const blink::WebCryptoAlgorithm& wrapping_algorithm, const blink::WebCryptoAlgorithm& wrapping_algorithm,
std::vector<uint8>* buffer) { std::vector<uint8>* buffer) {
if (!KeyUsageAllows(wrapping_key, blink::WebCryptoKeyUsageWrapKey)) if (!KeyUsageAllows(wrapping_key, blink::WebCryptoKeyUsageWrapKey))
...@@ -762,10 +762,10 @@ Status WrapKey(blink::WebCryptoKeyFormat format, ...@@ -762,10 +762,10 @@ Status WrapKey(blink::WebCryptoKeyFormat format,
switch (format) { switch (format) {
case blink::WebCryptoKeyFormatRaw: case blink::WebCryptoKeyFormatRaw:
return WrapKeyRaw(wrapping_key, key_to_wrap, wrapping_algorithm, buffer); return WrapKeyRaw(key_to_wrap, wrapping_key, wrapping_algorithm, buffer);
case blink::WebCryptoKeyFormatJwk: case blink::WebCryptoKeyFormatJwk:
return WrapKeyExportAndEncrypt( return WrapKeyExportAndEncrypt(
format, wrapping_key, key_to_wrap, wrapping_algorithm, buffer); format, key_to_wrap, wrapping_key, wrapping_algorithm, buffer);
case blink::WebCryptoKeyFormatSpki: case blink::WebCryptoKeyFormatSpki:
case blink::WebCryptoKeyFormatPkcs8: case blink::WebCryptoKeyFormatPkcs8:
return Status::ErrorUnsupported(); // TODO(padolph) return Status::ErrorUnsupported(); // TODO(padolph)
......
...@@ -131,8 +131,8 @@ CONTENT_EXPORT Status ...@@ -131,8 +131,8 @@ CONTENT_EXPORT Status
CONTENT_EXPORT Status CONTENT_EXPORT Status
WrapKey(blink::WebCryptoKeyFormat format, WrapKey(blink::WebCryptoKeyFormat format,
const blink::WebCryptoKey& wrapping_key,
const blink::WebCryptoKey& key_to_wrap, const blink::WebCryptoKey& key_to_wrap,
const blink::WebCryptoKey& wrapping_key,
const blink::WebCryptoAlgorithm& wrapping_algorithm, const blink::WebCryptoAlgorithm& wrapping_algorithm,
std::vector<uint8>* buffer); std::vector<uint8>* buffer);
......
...@@ -2764,8 +2764,8 @@ TEST_F(SharedCryptoTest, MAYBE(AesKwRawSymkeyWrapUnwrapKnownAnswer)) { ...@@ -2764,8 +2764,8 @@ TEST_F(SharedCryptoTest, MAYBE(AesKwRawSymkeyWrapUnwrapKnownAnswer)) {
std::vector<uint8> wrapped_key; std::vector<uint8> wrapped_key;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
WrapKey(blink::WebCryptoKeyFormatRaw, WrapKey(blink::WebCryptoKeyFormatRaw,
wrapping_key,
key, key,
wrapping_key,
wrapping_algorithm, wrapping_algorithm,
&wrapped_key)); &wrapped_key));
EXPECT_BYTES_EQ(test_ciphertext, wrapped_key); EXPECT_BYTES_EQ(test_ciphertext, wrapped_key);
...@@ -3163,8 +3163,8 @@ TEST_F(SharedCryptoTest, MAYBE(RsaEsRawSymkeyWrapUnwrapKnownAnswer)) { ...@@ -3163,8 +3163,8 @@ TEST_F(SharedCryptoTest, MAYBE(RsaEsRawSymkeyWrapUnwrapKnownAnswer)) {
std::vector<uint8> wrapped_key; std::vector<uint8> wrapped_key;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
WrapKey(blink::WebCryptoKeyFormatRaw, WrapKey(blink::WebCryptoKeyFormatRaw,
public_key,
key, key,
public_key,
algorithm, algorithm,
&wrapped_key)); &wrapped_key));
...@@ -3240,8 +3240,8 @@ TEST_F(SharedCryptoTest, MAYBE(RsaEsRawSymkeyWrapUnwrapErrors)) { ...@@ -3240,8 +3240,8 @@ TEST_F(SharedCryptoTest, MAYBE(RsaEsRawSymkeyWrapUnwrapErrors)) {
std::vector<uint8> wrapped_key; std::vector<uint8> wrapped_key;
EXPECT_EQ(Status::ErrorUnexpectedKeyType(), EXPECT_EQ(Status::ErrorUnexpectedKeyType(),
WrapKey(blink::WebCryptoKeyFormatRaw, WrapKey(blink::WebCryptoKeyFormatRaw,
private_key,
key, key,
private_key,
wrapping_algorithm, wrapping_algorithm,
&wrapped_key)); &wrapped_key));
...@@ -3262,8 +3262,8 @@ TEST_F(SharedCryptoTest, MAYBE(RsaEsRawSymkeyWrapUnwrapErrors)) { ...@@ -3262,8 +3262,8 @@ TEST_F(SharedCryptoTest, MAYBE(RsaEsRawSymkeyWrapUnwrapErrors)) {
&big_key)); &big_key));
EXPECT_EQ(Status::ErrorDataTooLarge(), EXPECT_EQ(Status::ErrorDataTooLarge(),
WrapKey(blink::WebCryptoKeyFormatRaw, WrapKey(blink::WebCryptoKeyFormatRaw,
public_key,
big_key, big_key,
public_key,
wrapping_algorithm, wrapping_algorithm,
&wrapped_key)); &wrapped_key));
...@@ -3383,8 +3383,8 @@ TEST_F(SharedCryptoTest, MAYBE(RsaEsJwkSymkeyWrapUnwrapRoundTrip)) { ...@@ -3383,8 +3383,8 @@ TEST_F(SharedCryptoTest, MAYBE(RsaEsJwkSymkeyWrapUnwrapRoundTrip)) {
std::vector<uint8> wrapped_data; std::vector<uint8> wrapped_data;
ASSERT_EQ(Status::Success(), ASSERT_EQ(Status::Success(),
WrapKey(blink::WebCryptoKeyFormatJwk, WrapKey(blink::WebCryptoKeyFormatJwk,
public_wrapping_key,
key_to_wrap, key_to_wrap,
public_wrapping_key,
wrapping_algorithm, wrapping_algorithm,
&wrapped_data)); &wrapped_data));
......
...@@ -519,11 +519,9 @@ void DoWrapKeyReply(scoped_ptr<WrapKeyState> state) { ...@@ -519,11 +519,9 @@ void DoWrapKeyReply(scoped_ptr<WrapKeyState> state) {
void DoWrapKey(scoped_ptr<WrapKeyState> passed_state) { void DoWrapKey(scoped_ptr<WrapKeyState> passed_state) {
WrapKeyState* state = passed_state.get(); WrapKeyState* state = passed_state.get();
// TODO(eroman): The parameter ordering of webcrypto::WrapKey() is
// inconsistent with that of blink::WebCrypto::wrapKey().
state->status = webcrypto::WrapKey(state->format, state->status = webcrypto::WrapKey(state->format,
state->wrapping_key,
state->key, state->key,
state->wrapping_key,
state->wrap_algorithm, state->wrap_algorithm,
&state->buffer); &state->buffer);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment