| OLD | NEW | 
|---|
| 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/renderer/webcrypto/shared_crypto.h" | 5 #include "content/renderer/webcrypto/shared_crypto.h" | 
| 6 | 6 | 
| 7 #include "base/logging.h" | 7 #include "base/logging.h" | 
| 8 #include "content/renderer/webcrypto/crypto_data.h" | 8 #include "content/renderer/webcrypto/crypto_data.h" | 
| 9 #include "content/renderer/webcrypto/platform_crypto.h" | 9 #include "content/renderer/webcrypto/platform_crypto.h" | 
| 10 #include "content/renderer/webcrypto/webcrypto_util.h" | 10 #include "content/renderer/webcrypto/webcrypto_util.h" | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 43 | 43 | 
| 44 Status ToPlatformPublicKey(const blink::WebCryptoKey& key, | 44 Status ToPlatformPublicKey(const blink::WebCryptoKey& key, | 
| 45                            platform::PublicKey** out) { | 45                            platform::PublicKey** out) { | 
| 46   *out = static_cast<platform::Key*>(key.handle())->AsPublicKey(); | 46   *out = static_cast<platform::Key*>(key.handle())->AsPublicKey(); | 
| 47   if (!*out) | 47   if (!*out) | 
| 48     return Status::ErrorUnexpectedKeyType(); | 48     return Status::ErrorUnexpectedKeyType(); | 
| 49   return Status::Success(); | 49   return Status::Success(); | 
| 50 } | 50 } | 
| 51 | 51 | 
| 52 Status ToPlatformPrivateKey(const blink::WebCryptoKey& key, | 52 Status ToPlatformPrivateKey(const blink::WebCryptoKey& key, | 
| 53                            platform::PrivateKey** out) { | 53                             platform::PrivateKey** out) { | 
| 54   *out = static_cast<platform::Key*>(key.handle())->AsPrivateKey(); | 54   *out = static_cast<platform::Key*>(key.handle())->AsPrivateKey(); | 
| 55   if (!*out) | 55   if (!*out) | 
| 56     return Status::ErrorUnexpectedKeyType(); | 56     return Status::ErrorUnexpectedKeyType(); | 
| 57   return Status::Success(); | 57   return Status::Success(); | 
| 58 } | 58 } | 
| 59 | 59 | 
| 60 const size_t kAesBlockSizeBytes = 16; | 60 const size_t kAesBlockSizeBytes = 16; | 
| 61 | 61 | 
| 62 Status EncryptDecryptAesCbc(EncryptOrDecrypt mode, | 62 Status EncryptDecryptAesCbc(EncryptOrDecrypt mode, | 
| 63                             const blink::WebCryptoAlgorithm& algorithm, | 63                             const blink::WebCryptoAlgorithm& algorithm, | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 96 | 96 | 
| 97   // TODO(eroman): The spec doesn't define the default value. Assume 128 for now | 97   // TODO(eroman): The spec doesn't define the default value. Assume 128 for now | 
| 98   // since that is the maximum tag length: | 98   // since that is the maximum tag length: | 
| 99   // http://www.w3.org/2012/webcrypto/track/issues/46 | 99   // http://www.w3.org/2012/webcrypto/track/issues/46 | 
| 100   unsigned int tag_length_bits = 128; | 100   unsigned int tag_length_bits = 128; | 
| 101   if (params->hasTagLengthBits()) | 101   if (params->hasTagLengthBits()) | 
| 102     tag_length_bits = params->optionalTagLengthBits(); | 102     tag_length_bits = params->optionalTagLengthBits(); | 
| 103   if (tag_length_bits > 128) | 103   if (tag_length_bits > 128) | 
| 104     return Status::ErrorInvalidAesGcmTagLength(); | 104     return Status::ErrorInvalidAesGcmTagLength(); | 
| 105 | 105 | 
| 106   return platform::EncryptDecryptAesGcm(mode, sym_key, data, | 106   return platform::EncryptDecryptAesGcm( | 
| 107       CryptoData(params->iv()), CryptoData(params->optionalAdditionalData()), | 107       mode, | 
| 108       tag_length_bits, buffer); | 108       sym_key, | 
|  | 109       data, | 
|  | 110       CryptoData(params->iv()), | 
|  | 111       CryptoData(params->optionalAdditionalData()), | 
|  | 112       tag_length_bits, | 
|  | 113       buffer); | 
| 109 } | 114 } | 
| 110 | 115 | 
| 111 Status EncryptRsaEsPkcs1v1_5(const blink::WebCryptoAlgorithm& algorithm, | 116 Status EncryptRsaEsPkcs1v1_5(const blink::WebCryptoAlgorithm& algorithm, | 
| 112                              const blink::WebCryptoKey& key, | 117                              const blink::WebCryptoKey& key, | 
| 113                              const CryptoData& data, | 118                              const CryptoData& data, | 
| 114                              blink::WebArrayBuffer* buffer) { | 119                              blink::WebArrayBuffer* buffer) { | 
| 115   platform::PublicKey* public_key; | 120   platform::PublicKey* public_key; | 
| 116   Status status = ToPlatformPublicKey(key, &public_key); | 121   Status status = ToPlatformPublicKey(key, &public_key); | 
| 117   if (status.IsError()) | 122   if (status.IsError()) | 
| 118     return status; | 123     return status; | 
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 245       return platform::ImportKeyRaw( | 250       return platform::ImportKeyRaw( | 
| 246           algorithm_or_null, key_data, extractable, usage_mask, key); | 251           algorithm_or_null, key_data, extractable, usage_mask, key); | 
| 247 | 252 | 
| 248     default: | 253     default: | 
| 249       return Status::ErrorUnsupported(); | 254       return Status::ErrorUnsupported(); | 
| 250   } | 255   } | 
| 251 } | 256 } | 
| 252 | 257 | 
| 253 }  // namespace | 258 }  // namespace | 
| 254 | 259 | 
| 255 void Init() { | 260 void Init() { platform::Init(); } | 
| 256   platform::Init(); |  | 
| 257 } |  | 
| 258 | 261 | 
| 259 Status Encrypt(const blink::WebCryptoAlgorithm& algorithm, | 262 Status Encrypt(const blink::WebCryptoAlgorithm& algorithm, | 
| 260                const blink::WebCryptoKey& key, | 263                const blink::WebCryptoKey& key, | 
| 261                const CryptoData& data, | 264                const CryptoData& data, | 
| 262                blink::WebArrayBuffer* buffer) { | 265                blink::WebArrayBuffer* buffer) { | 
| 263   if (!KeyUsageAllows(key, blink::WebCryptoKeyUsageEncrypt)) | 266   if (!KeyUsageAllows(key, blink::WebCryptoKeyUsageEncrypt)) | 
| 264     return Status::ErrorUnexpected(); | 267     return Status::ErrorUnexpected(); | 
| 265   if (algorithm.id() != key.algorithm().id()) | 268   if (algorithm.id() != key.algorithm().id()) | 
| 266     return Status::ErrorUnexpected(); | 269     return Status::ErrorUnexpected(); | 
| 267 | 270 | 
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 475       return VerifyRsaSsaPkcs1v1_5( | 478       return VerifyRsaSsaPkcs1v1_5( | 
| 476           algorithm, key, signature, data, signature_match); | 479           algorithm, key, signature, data, signature_match); | 
| 477     default: | 480     default: | 
| 478       return Status::ErrorUnsupported(); | 481       return Status::ErrorUnsupported(); | 
| 479   } | 482   } | 
| 480 } | 483 } | 
| 481 | 484 | 
| 482 }  // namespace webcrypto | 485 }  // namespace webcrypto | 
| 483 | 486 | 
| 484 }  // namespace content | 487 }  // namespace content | 
| OLD | NEW | 
|---|