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

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

Issue 757873003: Check that usage isn't empty when generateKey() is called (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase and fix bad merges 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
« no previous file with comments | « content/child/webcrypto/openssl/rsa_key_openssl.cc ('k') | content/child/webcrypto/status.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "crypto/openssl_util.h" 14 #include "crypto/openssl_util.h"
15 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" 15 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h"
16 16
17 namespace content { 17 namespace content {
18 18
19 namespace webcrypto { 19 namespace webcrypto {
20 20
21 Status GenerateSecretKeyOpenSsl(const blink::WebCryptoKeyAlgorithm& algorithm, 21 Status GenerateSecretKeyOpenSsl(const blink::WebCryptoKeyAlgorithm& algorithm,
22 bool extractable, 22 bool extractable,
23 blink::WebCryptoKeyUsageMask usages, 23 blink::WebCryptoKeyUsageMask usages,
24 unsigned keylen_bytes, 24 unsigned keylen_bytes,
25 GenerateKeyResult* result) { 25 GenerateKeyResult* result) {
26 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); 26 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE);
27 27
28 if (usages == 0)
29 return Status::ErrorCreateKeyEmptyUsages();
30
28 std::vector<unsigned char> random_bytes(keylen_bytes, 0); 31 std::vector<unsigned char> random_bytes(keylen_bytes, 0);
29 32
30 if (keylen_bytes > 0) { 33 if (keylen_bytes > 0) {
31 if (!(RAND_bytes(&random_bytes[0], keylen_bytes))) 34 if (!(RAND_bytes(&random_bytes[0], keylen_bytes)))
32 return Status::OperationError(); 35 return Status::OperationError();
33 } 36 }
34 37
35 result->AssignSecretKey(blink::WebCryptoKey::create( 38 result->AssignSecretKey(
36 new SymKeyOpenSsl(CryptoData(random_bytes)), 39 blink::WebCryptoKey::create(new SymKeyOpenSsl(CryptoData(random_bytes)),
37 blink::WebCryptoKeyTypeSecret, extractable, algorithm, usages)); 40 blink::WebCryptoKeyTypeSecret,
41 extractable,
42 algorithm,
43 usages));
38 44
39 return Status::Success(); 45 return Status::Success();
40 } 46 }
41 47
42 Status ImportKeyRawOpenSsl(const CryptoData& key_data, 48 Status ImportKeyRawOpenSsl(const CryptoData& key_data,
43 const blink::WebCryptoKeyAlgorithm& algorithm, 49 const blink::WebCryptoKeyAlgorithm& algorithm,
44 bool extractable, 50 bool extractable,
45 blink::WebCryptoKeyUsageMask usages, 51 blink::WebCryptoKeyUsageMask usages,
46 blink::WebCryptoKey* key) { 52 blink::WebCryptoKey* key) {
47 *key = blink::WebCryptoKey::create(new SymKeyOpenSsl(key_data), 53 *key = blink::WebCryptoKey::create(new SymKeyOpenSsl(key_data),
48 blink::WebCryptoKeyTypeSecret, extractable, 54 blink::WebCryptoKeyTypeSecret, extractable,
49 algorithm, usages); 55 algorithm, usages);
50 return Status::Success(); 56 return Status::Success();
51 } 57 }
52 58
53 } // namespace webcrypto 59 } // namespace webcrypto
54 60
55 } // namespace content 61 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webcrypto/openssl/rsa_key_openssl.cc ('k') | content/child/webcrypto/status.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698