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

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

Issue 413523003: [webcrypto] Properly fail-fast when importing RSA key as JWK with bad usages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert patchset 5; won't generalize well for DH keys Created 6 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « content/child/webcrypto/openssl/rsa_key_openssl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/logging.h" 5 #include "base/logging.h"
6 #include "base/stl_util.h" 6 #include "base/stl_util.h"
7 #include "content/child/webcrypto/algorithm_dispatch.h" 7 #include "content/child/webcrypto/algorithm_dispatch.h"
8 #include "content/child/webcrypto/crypto_data.h" 8 #include "content/child/webcrypto/crypto_data.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 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 RestoreJwkRsaDictionary(&dict); 1193 RestoreJwkRsaDictionary(&dict);
1194 1194
1195 // Fail on empty parameter. 1195 // Fail on empty parameter.
1196 dict.SetString(kKtyParmName[idx], ""); 1196 dict.SetString(kKtyParmName[idx], "");
1197 EXPECT_EQ(Status::ErrorJwkEmptyBigInteger(kKtyParmName[idx]), 1197 EXPECT_EQ(Status::ErrorJwkEmptyBigInteger(kKtyParmName[idx]),
1198 ImportKeyJwkFromDict(dict, algorithm, false, usages, &key)); 1198 ImportKeyJwkFromDict(dict, algorithm, false, usages, &key));
1199 RestoreJwkRsaDictionary(&dict); 1199 RestoreJwkRsaDictionary(&dict);
1200 } 1200 }
1201 } 1201 }
1202 1202
1203 // Try importing an RSA-SSA key from JWK format, having specified both Sign and
1204 // Verify usage, and an invalid JWK.
1205 //
1206 // The test must fail with a usage error BEFORE attempting to read the JWK data.
1207 // Although both Sign and Verify are valid usages for RSA-SSA keys, it is
1208 // invalid to have them both at the same time for one key (since Sign applies to
1209 // private keys, whereas Verify applies to public keys).
1210 //
1211 // If the implementation does not fail fast, this test will crash dereferencing
1212 // invalid memory.
1213 TEST(WebCryptoRsaSsaTest, ImportRsaSsaJwkBadUsageFailFast) {
1214 CryptoData bad_data(NULL, 128); // Invalid buffer of length 128.
1215
1216 blink::WebCryptoKey key;
1217 ASSERT_EQ(
1218 Status::ErrorCreateKeyBadUsages(),
1219 ImportKey(blink::WebCryptoKeyFormatJwk,
1220 bad_data,
1221 CreateRsaHashedImportAlgorithm(
1222 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
1223 blink::WebCryptoAlgorithmIdSha256),
1224 true,
1225 blink::WebCryptoKeyUsageVerify | blink::WebCryptoKeyUsageSign,
1226 &key));
1227 }
1228
1203 } // namespace 1229 } // namespace
1204 1230
1205 } // namespace webcrypto 1231 } // namespace webcrypto
1206 1232
1207 } // namespace content 1233 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webcrypto/openssl/rsa_key_openssl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698