| 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/child/webcrypto/openssl/sym_key_openssl.h" | 5 #include "content/child/webcrypto/openssl/sym_key_openssl.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 #include <openssl/rand.h> | 8 #include <openssl/rand.h> |
| 9 | 9 |
| 10 #include "content/child/webcrypto/crypto_data.h" | 10 #include "content/child/webcrypto/crypto_data.h" |
| 11 #include "content/child/webcrypto/generate_key_result.h" |
| 11 #include "content/child/webcrypto/openssl/key_openssl.h" | 12 #include "content/child/webcrypto/openssl/key_openssl.h" |
| 12 #include "content/child/webcrypto/status.h" | 13 #include "content/child/webcrypto/status.h" |
| 13 #include "crypto/openssl_util.h" | 14 #include "crypto/openssl_util.h" |
| 14 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" | 15 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 | 18 |
| 18 namespace webcrypto { | 19 namespace webcrypto { |
| 19 | 20 |
| 20 Status GenerateSecretKeyOpenSsl(const blink::WebCryptoKeyAlgorithm& algorithm, | 21 Status GenerateSecretKeyOpenSsl(const blink::WebCryptoKeyAlgorithm& algorithm, |
| 21 bool extractable, | 22 bool extractable, |
| 22 blink::WebCryptoKeyUsageMask usage_mask, | 23 blink::WebCryptoKeyUsageMask usage_mask, |
| 23 unsigned keylen_bytes, | 24 unsigned keylen_bytes, |
| 24 blink::WebCryptoKey* key) { | 25 GenerateKeyResult* result) { |
| 25 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 26 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); |
| 26 | 27 |
| 27 std::vector<unsigned char> random_bytes(keylen_bytes, 0); | 28 std::vector<unsigned char> random_bytes(keylen_bytes, 0); |
| 28 | 29 |
| 29 if (keylen_bytes > 0) { | 30 if (keylen_bytes > 0) { |
| 30 if (!(RAND_bytes(&random_bytes[0], keylen_bytes))) | 31 if (!(RAND_bytes(&random_bytes[0], keylen_bytes))) |
| 31 return Status::OperationError(); | 32 return Status::OperationError(); |
| 32 } | 33 } |
| 33 | 34 |
| 34 *key = | 35 result->set_type(GenerateKeyResult::TYPE_SECRET_KEY); |
| 36 *result->mutable_secret_key() = |
| 35 blink::WebCryptoKey::create(new SymKeyOpenSsl(CryptoData(random_bytes)), | 37 blink::WebCryptoKey::create(new SymKeyOpenSsl(CryptoData(random_bytes)), |
| 36 blink::WebCryptoKeyTypeSecret, | 38 blink::WebCryptoKeyTypeSecret, |
| 37 extractable, | 39 extractable, |
| 38 algorithm, | 40 algorithm, |
| 39 usage_mask); | 41 usage_mask); |
| 40 return Status::Success(); | 42 return Status::Success(); |
| 41 } | 43 } |
| 42 | 44 |
| 43 Status ImportKeyRawOpenSsl(const CryptoData& key_data, | 45 Status ImportKeyRawOpenSsl(const CryptoData& key_data, |
| 44 const blink::WebCryptoKeyAlgorithm& algorithm, | 46 const blink::WebCryptoKeyAlgorithm& algorithm, |
| 45 bool extractable, | 47 bool extractable, |
| 46 blink::WebCryptoKeyUsageMask usage_mask, | 48 blink::WebCryptoKeyUsageMask usage_mask, |
| 47 blink::WebCryptoKey* key) { | 49 blink::WebCryptoKey* key) { |
| 48 *key = blink::WebCryptoKey::create(new SymKeyOpenSsl(key_data), | 50 *key = blink::WebCryptoKey::create(new SymKeyOpenSsl(key_data), |
| 49 blink::WebCryptoKeyTypeSecret, | 51 blink::WebCryptoKeyTypeSecret, |
| 50 extractable, | 52 extractable, |
| 51 algorithm, | 53 algorithm, |
| 52 usage_mask); | 54 usage_mask); |
| 53 return Status::Success(); | 55 return Status::Success(); |
| 54 } | 56 } |
| 55 | 57 |
| 56 } // namespace webcrypto | 58 } // namespace webcrypto |
| 57 | 59 |
| 58 } // namespace content | 60 } // namespace content |
| OLD | NEW |