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

Side by Side Diff: content/renderer/webcrypto/webcrypto_impl_nss.cc

Issue 50173002: [webcrypto] Refactor to allow for unspecified "algorithm" to importKey(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address sleevi comments and make NullKey() work in debug mode Created 7 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/renderer/webcrypto/webcrypto_impl.h" 5 #include "content/renderer/webcrypto/webcrypto_impl.h"
6 6
7 #include <cryptohi.h> 7 #include <cryptohi.h>
8 #include <pk11pub.h> 8 #include <pk11pub.h>
9 #include <sechash.h> 9 #include <sechash.h>
10 10
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 unsigned result_length = 0; 256 unsigned result_length = 0;
257 HASH_End(context, digest, &result_length, hash_result_length); 257 HASH_End(context, digest, &result_length, hash_result_length);
258 258
259 HASH_Destroy(context); 259 HASH_Destroy(context);
260 260
261 return result_length == hash_result_length; 261 return result_length == hash_result_length;
262 } 262 }
263 263
264 bool WebCryptoImpl::GenerateKeyInternal( 264 bool WebCryptoImpl::GenerateKeyInternal(
265 const WebKit::WebCryptoAlgorithm& algorithm, 265 const WebKit::WebCryptoAlgorithm& algorithm,
266 scoped_ptr<WebKit::WebCryptoKeyHandle>* key, 266 bool extractable,
267 WebKit::WebCryptoKeyType* type) { 267 WebKit::WebCryptoKeyUsageMask usage_mask,
268 WebKit::WebCryptoKey* key) {
268 269
269 CK_MECHANISM_TYPE mech = WebCryptoAlgorithmToGenMechanism(algorithm); 270 CK_MECHANISM_TYPE mech = WebCryptoAlgorithmToGenMechanism(algorithm);
270 unsigned int keylen_bytes = 0; 271 unsigned int keylen_bytes = 0;
271 WebKit::WebCryptoKeyType key_type = WebKit::WebCryptoKeyTypeSecret; 272 WebKit::WebCryptoKeyType key_type = WebKit::WebCryptoKeyTypeSecret;
272 273
273 if (mech == CKM_INVALID_MECHANISM) { 274 if (mech == CKM_INVALID_MECHANISM) {
274 return false; 275 return false;
275 } 276 }
276 277
277 switch (algorithm.id()) { 278 switch (algorithm.id()) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 return false; 311 return false;
311 } 312 }
312 313
313 crypto::ScopedPK11SymKey pk11_key( 314 crypto::ScopedPK11SymKey pk11_key(
314 PK11_KeyGen(slot.get(), mech, NULL, keylen_bytes, NULL)); 315 PK11_KeyGen(slot.get(), mech, NULL, keylen_bytes, NULL));
315 316
316 if (!pk11_key) { 317 if (!pk11_key) {
317 return false; 318 return false;
318 } 319 }
319 320
320 key->reset(new SymKeyHandle(pk11_key.Pass())); 321 *key = WebKit::WebCryptoKey::create(
321 *type = key_type; 322 new SymKeyHandle(pk11_key.Pass()),
322 323 key_type, extractable, algorithm, usage_mask);
323 return true; 324 return true;
324 } 325 }
325 326
326 327
327 bool WebCryptoImpl::ImportKeyInternal( 328 bool WebCryptoImpl::ImportKeyInternal(
328 WebKit::WebCryptoKeyFormat format, 329 WebKit::WebCryptoKeyFormat format,
329 const unsigned char* key_data, 330 const unsigned char* key_data,
330 unsigned key_data_size, 331 unsigned key_data_size,
331 const WebKit::WebCryptoAlgorithm& algorithm, 332 const WebKit::WebCryptoAlgorithm& algorithm_or_null,
333 bool extractable,
332 WebKit::WebCryptoKeyUsageMask usage_mask, 334 WebKit::WebCryptoKeyUsageMask usage_mask,
333 scoped_ptr<WebKit::WebCryptoKeyHandle>* handle, 335 WebKit::WebCryptoKey* key) {
334 WebKit::WebCryptoKeyType* type) { 336 // TODO(eroman): Currently expects algorithm to always be specified, as it is
337 // required for raw format.
338 if (algorithm_or_null.isNull())
339 return false;
340 const WebKit::WebCryptoAlgorithm& algorithm = algorithm_or_null;
341
342 WebKit::WebCryptoKeyType type;
335 switch (algorithm.id()) { 343 switch (algorithm.id()) {
336 case WebKit::WebCryptoAlgorithmIdHmac: 344 case WebKit::WebCryptoAlgorithmIdHmac:
337 case WebKit::WebCryptoAlgorithmIdAesCbc: 345 case WebKit::WebCryptoAlgorithmIdAesCbc:
338 *type = WebKit::WebCryptoKeyTypeSecret; 346 type = WebKit::WebCryptoKeyTypeSecret;
339 break; 347 break;
340 // TODO(bryaneyler): Support more key types. 348 // TODO(bryaneyler): Support more key types.
341 default: 349 default:
342 return false; 350 return false;
343 } 351 }
344 352
345 // TODO(bryaneyler): Need to split handling for symmetric and asymmetric keys. 353 // TODO(bryaneyler): Need to split handling for symmetric and asymmetric keys.
346 // Currently only supporting symmetric. 354 // Currently only supporting symmetric.
347 CK_MECHANISM_TYPE mechanism = CKM_INVALID_MECHANISM; 355 CK_MECHANISM_TYPE mechanism = CKM_INVALID_MECHANISM;
348 // Flags are verified at the Blink layer; here the flags are set to all 356 // Flags are verified at the Blink layer; here the flags are set to all
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 PK11_OriginUnwrap, 403 PK11_OriginUnwrap,
396 CKA_FLAGS_ONLY, 404 CKA_FLAGS_ONLY,
397 &key_item, 405 &key_item,
398 flags, 406 flags,
399 false, 407 false,
400 NULL)); 408 NULL));
401 if (!pk11_sym_key.get()) { 409 if (!pk11_sym_key.get()) {
402 return false; 410 return false;
403 } 411 }
404 412
405 scoped_ptr<SymKeyHandle> sym_key(new SymKeyHandle(pk11_sym_key.Pass())); 413 *key = WebKit::WebCryptoKey::create(new SymKeyHandle(pk11_sym_key.Pass()),
406 *handle = sym_key.Pass(); 414 type, extractable, algorithm, usage_mask);
407
408 return true; 415 return true;
409 } 416 }
410 417
411 bool WebCryptoImpl::SignInternal( 418 bool WebCryptoImpl::SignInternal(
412 const WebKit::WebCryptoAlgorithm& algorithm, 419 const WebKit::WebCryptoAlgorithm& algorithm,
413 const WebKit::WebCryptoKey& key, 420 const WebKit::WebCryptoKey& key,
414 const unsigned char* data, 421 const unsigned char* data,
415 unsigned data_size, 422 unsigned data_size,
416 WebKit::WebArrayBuffer* buffer) { 423 WebKit::WebArrayBuffer* buffer) {
417 WebKit::WebArrayBuffer result; 424 WebKit::WebArrayBuffer result;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 break; 506 break;
500 } 507 }
501 default: 508 default:
502 return false; 509 return false;
503 } 510 }
504 511
505 return true; 512 return true;
506 } 513 }
507 514
508 } // namespace content 515 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/webcrypto/webcrypto_impl.cc ('k') | content/renderer/webcrypto/webcrypto_impl_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698