Chromium Code Reviews| 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" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 GenerateKeyResult* result) { | 25 GenerateKeyResult* result) { |
| 26 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 26 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); |
| 27 | 27 |
| 28 std::vector<unsigned char> random_bytes(keylen_bytes, 0); | 28 std::vector<unsigned char> random_bytes(keylen_bytes, 0); |
| 29 | 29 |
| 30 if (keylen_bytes > 0) { | 30 if (keylen_bytes > 0) { |
| 31 if (!(RAND_bytes(&random_bytes[0], keylen_bytes))) | 31 if (!(RAND_bytes(&random_bytes[0], keylen_bytes))) |
| 32 return Status::OperationError(); | 32 return Status::OperationError(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 if (usages == 0) { | |
|
eroman
2014/11/20 23:40:10
Move this higher up -- should fail fast before doi
nharper
2014/11/21 22:12:01
Done.
| |
| 36 return Status::ErrorCreateKeyBadUsages(); | |
| 37 } | |
| 38 | |
| 35 result->AssignSecretKey( | 39 result->AssignSecretKey( |
| 36 blink::WebCryptoKey::create(new SymKeyOpenSsl(CryptoData(random_bytes)), | 40 blink::WebCryptoKey::create(new SymKeyOpenSsl(CryptoData(random_bytes)), |
| 37 blink::WebCryptoKeyTypeSecret, | 41 blink::WebCryptoKeyTypeSecret, |
| 38 extractable, | 42 extractable, |
| 39 algorithm, | 43 algorithm, |
| 40 usages)); | 44 usages)); |
| 41 | 45 |
| 42 return Status::Success(); | 46 return Status::Success(); |
| 43 } | 47 } |
| 44 | 48 |
| 45 Status ImportKeyRawOpenSsl(const CryptoData& key_data, | 49 Status ImportKeyRawOpenSsl(const CryptoData& key_data, |
| 46 const blink::WebCryptoKeyAlgorithm& algorithm, | 50 const blink::WebCryptoKeyAlgorithm& algorithm, |
| 47 bool extractable, | 51 bool extractable, |
| 48 blink::WebCryptoKeyUsageMask usages, | 52 blink::WebCryptoKeyUsageMask usages, |
| 49 blink::WebCryptoKey* key) { | 53 blink::WebCryptoKey* key) { |
| 50 *key = blink::WebCryptoKey::create(new SymKeyOpenSsl(key_data), | 54 *key = blink::WebCryptoKey::create(new SymKeyOpenSsl(key_data), |
| 51 blink::WebCryptoKeyTypeSecret, | 55 blink::WebCryptoKeyTypeSecret, |
| 52 extractable, | 56 extractable, |
| 53 algorithm, | 57 algorithm, |
| 54 usages); | 58 usages); |
| 55 return Status::Success(); | 59 return Status::Success(); |
| 56 } | 60 } |
| 57 | 61 |
| 58 } // namespace webcrypto | 62 } // namespace webcrypto |
| 59 | 63 |
| 60 } // namespace content | 64 } // namespace content |
| OLD | NEW |