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

Side by Side Diff: content/child/webcrypto/platform_crypto_nss.cc

Issue 282133002: [webcryto] Validate key usages during key creation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
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 "content/child/webcrypto/platform_crypto.h" 5 #include "content/child/webcrypto/platform_crypto.h"
6 6
7 #include <cryptohi.h> 7 #include <cryptohi.h>
8 #include <pk11pub.h> 8 #include <pk11pub.h>
9 #include <secerr.h> 9 #include <secerr.h>
10 #include <sechash.h> 10 #include <sechash.h>
(...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 return AesGcmEncryptDecrypt( 1274 return AesGcmEncryptDecrypt(
1275 mode, key, data, iv, additional_data, tag_length_bits, buffer); 1275 mode, key, data, iv, additional_data, tag_length_bits, buffer);
1276 } 1276 }
1277 1277
1278 // ----------------------------------- 1278 // -----------------------------------
1279 // Key generation 1279 // Key generation
1280 // ----------------------------------- 1280 // -----------------------------------
1281 1281
1282 Status GenerateRsaKeyPair(const blink::WebCryptoAlgorithm& algorithm, 1282 Status GenerateRsaKeyPair(const blink::WebCryptoAlgorithm& algorithm,
1283 bool extractable, 1283 bool extractable,
1284 blink::WebCryptoKeyUsageMask usage_mask, 1284 blink::WebCryptoKeyUsageMask public_key_usage_mask,
1285 blink::WebCryptoKeyUsageMask private_key_usage_mask,
1285 unsigned int modulus_length_bits, 1286 unsigned int modulus_length_bits,
1286 const CryptoData& public_exponent, 1287 const CryptoData& public_exponent,
1287 const blink::WebCryptoAlgorithm& hash_or_null, 1288 const blink::WebCryptoAlgorithm& hash_or_null,
1288 blink::WebCryptoKey* public_key, 1289 blink::WebCryptoKey* public_key,
1289 blink::WebCryptoKey* private_key) { 1290 blink::WebCryptoKey* private_key) {
1290 crypto::ScopedPK11Slot slot(PK11_GetInternalKeySlot()); 1291 crypto::ScopedPK11Slot slot(PK11_GetInternalKeySlot());
1291 if (!slot) 1292 if (!slot)
1292 return Status::OperationError(); 1293 return Status::OperationError();
1293 1294
1294 unsigned long public_exponent_long; 1295 unsigned long public_exponent_long;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 scoped_ptr<PrivateKey> private_key_handle; 1355 scoped_ptr<PrivateKey> private_key_handle;
1355 status = PrivateKey::Create( 1356 status = PrivateKey::Create(
1356 scoped_sec_private_key.Pass(), key_algorithm, &private_key_handle); 1357 scoped_sec_private_key.Pass(), key_algorithm, &private_key_handle);
1357 if (status.IsError()) 1358 if (status.IsError())
1358 return status; 1359 return status;
1359 1360
1360 *public_key = blink::WebCryptoKey::create(public_key_handle.release(), 1361 *public_key = blink::WebCryptoKey::create(public_key_handle.release(),
1361 blink::WebCryptoKeyTypePublic, 1362 blink::WebCryptoKeyTypePublic,
1362 true, 1363 true,
1363 key_algorithm, 1364 key_algorithm,
1364 usage_mask); 1365 public_key_usage_mask);
1365 *private_key = blink::WebCryptoKey::create(private_key_handle.release(), 1366 *private_key = blink::WebCryptoKey::create(private_key_handle.release(),
1366 blink::WebCryptoKeyTypePrivate, 1367 blink::WebCryptoKeyTypePrivate,
1367 extractable, 1368 extractable,
1368 key_algorithm, 1369 key_algorithm,
1369 usage_mask); 1370 private_key_usage_mask);
1370 1371
1371 return Status::Success(); 1372 return Status::Success();
1372 } 1373 }
1373 1374
1374 void Init() { 1375 void Init() {
1375 crypto::EnsureNSSInit(); 1376 crypto::EnsureNSSInit();
1376 } 1377 }
1377 1378
1378 Status DigestSha(blink::WebCryptoAlgorithmId algorithm, 1379 Status DigestSha(blink::WebCryptoAlgorithmId algorithm,
1379 const CryptoData& data, 1380 const CryptoData& data,
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1675 key_algorithm, 1676 key_algorithm,
1676 usage_mask); 1677 usage_mask);
1677 return Status::Success(); 1678 return Status::Success();
1678 } 1679 }
1679 1680
1680 } // namespace platform 1681 } // namespace platform
1681 1682
1682 } // namespace webcrypto 1683 } // namespace webcrypto
1683 1684
1684 } // namespace content 1685 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698