| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "components/webcrypto/algorithm_implementation.h" | 9 #include "components/webcrypto/algorithm_implementation.h" |
| 10 #include "components/webcrypto/algorithms/secret_key_util.h" | 10 #include "components/webcrypto/algorithms/secret_key_util.h" |
| 11 #include "components/webcrypto/algorithms/util.h" | 11 #include "components/webcrypto/algorithms/util.h" |
| 12 #include "components/webcrypto/blink_key_handle.h" | 12 #include "components/webcrypto/blink_key_handle.h" |
| 13 #include "components/webcrypto/crypto_data.h" | 13 #include "components/webcrypto/crypto_data.h" |
| 14 #include "components/webcrypto/status.h" | 14 #include "components/webcrypto/status.h" |
| 15 #include "crypto/openssl_util.h" | 15 #include "crypto/openssl_util.h" |
| 16 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 16 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
| 17 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" | 17 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" |
| 18 | 18 |
| 19 namespace webcrypto { | 19 namespace webcrypto { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 const blink::WebCryptoKeyUsageMask kAllKeyUsages = | 23 const blink::WebCryptoKeyUsageMask kAllKeyUsages = |
| 24 blink::WebCryptoKeyUsageDeriveKey | blink::WebCryptoKeyUsageDeriveBits; | 24 blink::WebCryptoKeyUsageDeriveKey | blink::WebCryptoKeyUsageDeriveBits; |
| 25 | 25 |
| 26 class Pbkdf2Implementation : public AlgorithmImplementation { | 26 class Pbkdf2Implementation : public AlgorithmImplementation { |
| 27 public: | 27 public: |
| 28 Pbkdf2Implementation() {} | 28 Pbkdf2Implementation() {} |
| 29 | 29 |
| 30 Status VerifyKeyUsagesBeforeImportKey( | 30 Status ImportKey(blink::WebCryptoKeyFormat format, |
| 31 blink::WebCryptoKeyFormat format, | 31 const CryptoData& key_data, |
| 32 blink::WebCryptoKeyUsageMask usages) const override { | 32 const blink::WebCryptoAlgorithm& algorithm, |
| 33 bool extractable, |
| 34 blink::WebCryptoKeyUsageMask usages, |
| 35 blink::WebCryptoKey* key) const override { |
| 33 switch (format) { | 36 switch (format) { |
| 34 case blink::WebCryptoKeyFormatRaw: | 37 case blink::WebCryptoKeyFormatRaw: |
| 35 return CheckSecretKeyCreationUsages(kAllKeyUsages, usages); | 38 return ImportKeyRaw(key_data, algorithm, extractable, usages, key); |
| 36 default: | 39 default: |
| 37 return Status::ErrorUnsupportedImportKeyFormat(); | 40 return Status::ErrorUnsupportedImportKeyFormat(); |
| 38 } | 41 } |
| 39 } | 42 } |
| 40 | 43 |
| 41 Status ImportKeyRaw(const CryptoData& key_data, | 44 Status ImportKeyRaw(const CryptoData& key_data, |
| 42 const blink::WebCryptoAlgorithm& algorithm, | 45 const blink::WebCryptoAlgorithm& algorithm, |
| 43 bool extractable, | 46 bool extractable, |
| 44 blink::WebCryptoKeyUsageMask usages, | 47 blink::WebCryptoKeyUsageMask usages, |
| 45 blink::WebCryptoKey* key) const override { | 48 blink::WebCryptoKey* key) const { |
| 49 Status status = CheckKeyCreationUsages(kAllKeyUsages, usages); |
| 50 if (status.IsError()) |
| 51 return status; |
| 52 |
| 46 const blink::WebCryptoKeyAlgorithm key_algorithm = | 53 const blink::WebCryptoKeyAlgorithm key_algorithm = |
| 47 blink::WebCryptoKeyAlgorithm::createWithoutParams( | 54 blink::WebCryptoKeyAlgorithm::createWithoutParams( |
| 48 blink::WebCryptoAlgorithmIdPbkdf2); | 55 blink::WebCryptoAlgorithmIdPbkdf2); |
| 49 | 56 |
| 50 return CreateWebCryptoSecretKey(key_data, key_algorithm, extractable, | 57 return CreateWebCryptoSecretKey(key_data, key_algorithm, extractable, |
| 51 usages, key); | 58 usages, key); |
| 52 } | 59 } |
| 53 | 60 |
| 54 Status DeriveBits(const blink::WebCryptoAlgorithm& algorithm, | 61 Status DeriveBits(const blink::WebCryptoAlgorithm& algorithm, |
| 55 const blink::WebCryptoKey& base_key, | 62 const blink::WebCryptoKey& base_key, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 118 } |
| 112 }; | 119 }; |
| 113 | 120 |
| 114 } // namespace | 121 } // namespace |
| 115 | 122 |
| 116 std::unique_ptr<AlgorithmImplementation> CreatePbkdf2Implementation() { | 123 std::unique_ptr<AlgorithmImplementation> CreatePbkdf2Implementation() { |
| 117 return base::WrapUnique(new Pbkdf2Implementation); | 124 return base::WrapUnique(new Pbkdf2Implementation); |
| 118 } | 125 } |
| 119 | 126 |
| 120 } // namespace webcrypto | 127 } // namespace webcrypto |
| OLD | NEW |