summaryrefslogtreecommitdiffstats
path: root/content/child/webcrypto/platform_crypto_nss.cc
diff options
context:
space:
mode:
authorpadolph@netflix.com <padolph@netflix.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-11 10:18:27 +0000
committerpadolph@netflix.com <padolph@netflix.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-11 10:18:27 +0000
commit421fae27a8db394255b8bb8c2962c9e7f2a49f9d (patch)
tree11f41464d4b12e6e3263725b06cc8a5732f9706b /content/child/webcrypto/platform_crypto_nss.cc
parent871ec2eacbe2e8ad18e0e893a92d7e017055eb7b (diff)
downloadchromium_src-421fae27a8db394255b8bb8c2962c9e7f2a49f9d.zip
chromium_src-421fae27a8db394255b8bb8c2962c9e7f2a49f9d.tar.gz
chromium_src-421fae27a8db394255b8bb8c2962c9e7f2a49f9d.tar.bz2
[webcrypto] Workaround for NSS AES-KW unwrap bug 981170
See https://bugzilla.mozilla.org/show_bug.cgi?id=981170 BUG=349939 TEST=content_unittests --gtest_filter="SharedCryptoTest*" Review URL: https://codereview.chromium.org/190633008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@256181 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/child/webcrypto/platform_crypto_nss.cc')
-rw-r--r--content/child/webcrypto/platform_crypto_nss.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/content/child/webcrypto/platform_crypto_nss.cc b/content/child/webcrypto/platform_crypto_nss.cc
index 4cc6cb1..be6d0b0 100644
--- a/content/child/webcrypto/platform_crypto_nss.cc
+++ b/content/child/webcrypto/platform_crypto_nss.cc
@@ -1191,6 +1191,35 @@ Status UnwrapSymKeyAesKw(const CryptoData& wrapped_key_data,
if (!unwrapped_key)
return Status::Error();
+// TODO(padolph): Change to "defined(USE_NSS)" once the NSS fix for
+// https://bugzilla.mozilla.org/show_bug.cgi?id=981170 rolls into chromium.
+#if 1
+ // ------- Start NSS bug workaround
+ // Workaround for https://code.google.com/p/chromium/issues/detail?id=349939
+ // If unwrap fails, NSS nevertheless returns a valid-looking PK11SymKey, with
+ // a reasonable length but with key data pointing to uninitialized memory.
+ // This workaround re-wraps the key and compares the result with the incoming
+ // data, and fails if there is a difference. This prevents returning a bad key
+ // to the caller.
+ const unsigned int output_length = wrapped_key_data.byte_length();
+ std::vector<unsigned char> buffer(output_length, 0);
+ SECItem wrapped_key_item = MakeSECItemForBuffer(CryptoData(buffer));
+ if (SECSuccess != PK11_WrapSymKey(CKM_NSS_AES_KEY_WRAP,
+ param_item.get(),
+ wrapping_key->key(),
+ unwrapped_key.get(),
+ &wrapped_key_item)) {
+ return Status::Error();
+ }
+ if (wrapped_key_item.len != wrapped_key_data.byte_length() ||
+ memcmp(wrapped_key_item.data,
+ wrapped_key_data.bytes(),
+ wrapped_key_item.len) != 0) {
+ return Status::Error();
+ }
+ // ------- End NSS bug workaround
+#endif
+
blink::WebCryptoKeyAlgorithm key_algorithm;
if (!CreateSecretKeyAlgorithm(algorithm, plaintext_length, &key_algorithm))
return Status::ErrorUnexpected();