| OLD | NEW |
| 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 <vector> | 7 #include <vector> |
| 8 #include <openssl/aes.h> | 8 #include <openssl/aes.h> |
| 9 #include <openssl/evp.h> | 9 #include <openssl/evp.h> |
| 10 #include <openssl/hmac.h> | 10 #include <openssl/hmac.h> |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 if (algorithm_or_null.isNull()) | 323 if (algorithm_or_null.isNull()) |
| 324 return false; | 324 return false; |
| 325 const WebKit::WebCryptoAlgorithm& algorithm = algorithm_or_null; | 325 const WebKit::WebCryptoAlgorithm& algorithm = algorithm_or_null; |
| 326 | 326 |
| 327 // TODO(padolph): Support all relevant alg types and then remove this gate. | 327 // TODO(padolph): Support all relevant alg types and then remove this gate. |
| 328 if (algorithm.id() != WebKit::WebCryptoAlgorithmIdHmac && | 328 if (algorithm.id() != WebKit::WebCryptoAlgorithmIdHmac && |
| 329 algorithm.id() != WebKit::WebCryptoAlgorithmIdAesCbc) { | 329 algorithm.id() != WebKit::WebCryptoAlgorithmIdAesCbc) { |
| 330 return false; | 330 return false; |
| 331 } | 331 } |
| 332 | 332 |
| 333 // TODO(padolph): Need to split handling for symmetric (raw or jwk format) and | 333 // TODO(padolph): Need to split handling for symmetric |
| 334 // asymmetric (jwk, spki, or pkcs8 format) keys. | |
| 335 // Currently only supporting symmetric. | 334 // Currently only supporting symmetric. |
| 336 | 335 |
| 337 // TODO(padolph): jwk handling. Define precedence between jwk contents and | |
| 338 // this method's parameters, e.g. 'alg' in jwk vs algorithm.id(). Who wins if | |
| 339 // they differ? (jwk, probably) | |
| 340 | |
| 341 // Symmetric keys are always type secret | 336 // Symmetric keys are always type secret |
| 342 WebKit::WebCryptoKeyType type = WebKit::WebCryptoKeyTypeSecret; | 337 WebKit::WebCryptoKeyType type = WebKit::WebCryptoKeyTypeSecret; |
| 343 | 338 |
| 344 const unsigned char* raw_key_data; | 339 const unsigned char* raw_key_data; |
| 345 unsigned raw_key_data_size; | 340 unsigned raw_key_data_size; |
| 346 switch (format) { | 341 switch (format) { |
| 347 case WebKit::WebCryptoKeyFormatRaw: | 342 case WebKit::WebCryptoKeyFormatRaw: |
| 348 raw_key_data = key_data; | 343 raw_key_data = key_data; |
| 349 raw_key_data_size = key_data_size; | 344 raw_key_data_size = key_data_size; |
| 350 // The NSS implementation fails when importing a raw AES key with a length | 345 // The NSS implementation fails when importing a raw AES key with a length |
| (...skipping 11 matching lines...) Expand all Loading... |
| 362 return false; | 357 return false; |
| 363 } | 358 } |
| 364 | 359 |
| 365 *key = WebKit::WebCryptoKey::create( | 360 *key = WebKit::WebCryptoKey::create( |
| 366 new SymKeyHandle(raw_key_data, raw_key_data_size), | 361 new SymKeyHandle(raw_key_data, raw_key_data_size), |
| 367 type, extractable, algorithm, usage_mask); | 362 type, extractable, algorithm, usage_mask); |
| 368 | 363 |
| 369 return true; | 364 return true; |
| 370 } | 365 } |
| 371 | 366 |
| 367 bool WebCryptoImpl::ExportKeyInternal( |
| 368 WebKit::WebCryptoKeyFormat format, |
| 369 const WebKit::WebCryptoKey& key, |
| 370 WebKit::WebArrayBuffer* buffer) { |
| 371 // TODO(padolph): Implement raw export |
| 372 // TODO(padolph): Implement spki export |
| 373 // TODO(padolph): Implement pkcs8 export |
| 374 // TODO(padolph): Implement jwk export |
| 375 return false; |
| 376 } |
| 377 |
| 372 bool WebCryptoImpl::SignInternal( | 378 bool WebCryptoImpl::SignInternal( |
| 373 const WebKit::WebCryptoAlgorithm& algorithm, | 379 const WebKit::WebCryptoAlgorithm& algorithm, |
| 374 const WebKit::WebCryptoKey& key, | 380 const WebKit::WebCryptoKey& key, |
| 375 const unsigned char* data, | 381 const unsigned char* data, |
| 376 unsigned data_size, | 382 unsigned data_size, |
| 377 WebKit::WebArrayBuffer* buffer) { | 383 WebKit::WebArrayBuffer* buffer) { |
| 378 | 384 |
| 379 WebKit::WebArrayBuffer result; | 385 WebKit::WebArrayBuffer result; |
| 380 | 386 |
| 381 switch (algorithm.id()) { | 387 switch (algorithm.id()) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 | 488 |
| 483 break; | 489 break; |
| 484 } | 490 } |
| 485 default: | 491 default: |
| 486 return false; | 492 return false; |
| 487 } | 493 } |
| 488 return true; | 494 return true; |
| 489 } | 495 } |
| 490 | 496 |
| 491 } // namespace content | 497 } // namespace content |
| OLD | NEW |