Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(804)

Side by Side Diff: content/child/webcrypto/openssl/sym_key_openssl.cc

Issue 777403004: [WebCrypto] Throw syntaxError if keyUsage is empty in ImportKey (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated issues in ecdh tests and other review comments. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/generate_key_result.h"
12 #include "content/child/webcrypto/openssl/key_openssl.h" 12 #include "content/child/webcrypto/openssl/key_openssl.h"
13 #include "content/child/webcrypto/status.h" 13 #include "content/child/webcrypto/status.h"
14 #include "content/child/webcrypto/webcrypto_util.h" 14 #include "content/child/webcrypto/webcrypto_util.h"
15 #include "crypto/openssl_util.h" 15 #include "crypto/openssl_util.h"
16 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" 16 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h"
17 17
18 namespace content { 18 namespace content {
19 19
20 namespace webcrypto { 20 namespace webcrypto {
21 21
22 Status GenerateSecretKeyOpenSsl(const blink::WebCryptoKeyAlgorithm& algorithm, 22 Status GenerateSecretKeyOpenSsl(const blink::WebCryptoKeyAlgorithm& algorithm,
23 bool extractable, 23 bool extractable,
24 blink::WebCryptoKeyUsageMask usages, 24 blink::WebCryptoKeyUsageMask usages,
25 unsigned int keylen_bits, 25 unsigned int keylen_bits,
26 GenerateKeyResult* result) { 26 GenerateKeyResult* result) {
27 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); 27 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE);
28 28
29 if (usages == 0)
30 return Status::ErrorCreateKeyEmptyUsages();
31
32 unsigned int keylen_bytes = NumBitsToBytes(keylen_bits); 29 unsigned int keylen_bytes = NumBitsToBytes(keylen_bits);
33 std::vector<unsigned char> random_bytes(keylen_bytes, 0); 30 std::vector<unsigned char> random_bytes(keylen_bytes, 0);
34 31
35 if (keylen_bytes > 0) { 32 if (keylen_bytes > 0) {
36 if (!(RAND_bytes(&random_bytes[0], keylen_bytes))) 33 if (!(RAND_bytes(&random_bytes[0], keylen_bytes)))
37 return Status::OperationError(); 34 return Status::OperationError();
38 TruncateToBitLength(keylen_bits, &random_bytes); 35 TruncateToBitLength(keylen_bits, &random_bytes);
39 } 36 }
40 37
41 result->AssignSecretKey(blink::WebCryptoKey::create( 38 result->AssignSecretKey(blink::WebCryptoKey::create(
(...skipping 10 matching lines...) Expand all
52 blink::WebCryptoKey* key) { 49 blink::WebCryptoKey* key) {
53 *key = blink::WebCryptoKey::create(new SymKeyOpenSsl(key_data), 50 *key = blink::WebCryptoKey::create(new SymKeyOpenSsl(key_data),
54 blink::WebCryptoKeyTypeSecret, extractable, 51 blink::WebCryptoKeyTypeSecret, extractable,
55 algorithm, usages); 52 algorithm, usages);
56 return Status::Success(); 53 return Status::Success();
57 } 54 }
58 55
59 } // namespace webcrypto 56 } // namespace webcrypto
60 57
61 } // namespace content 58 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698