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

Side by Side Diff: content/child/webcrypto/algorithm_dispatch.cc

Issue 778543004: Add sanity check to generateKey to make sure usages aren't empty (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 | « no previous file | no next file » | 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/algorithm_dispatch.h" 5 #include "content/child/webcrypto/algorithm_dispatch.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/child/webcrypto/algorithm_implementation.h" 8 #include "content/child/webcrypto/algorithm_implementation.h"
9 #include "content/child/webcrypto/algorithm_registry.h" 9 #include "content/child/webcrypto/algorithm_registry.h"
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/platform_crypto.h" 12 #include "content/child/webcrypto/platform_crypto.h"
12 #include "content/child/webcrypto/status.h" 13 #include "content/child/webcrypto/status.h"
13 #include "content/child/webcrypto/webcrypto_util.h" 14 #include "content/child/webcrypto/webcrypto_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 namespace { 21 namespace {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 105
105 Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm, 106 Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm,
106 bool extractable, 107 bool extractable,
107 blink::WebCryptoKeyUsageMask usages, 108 blink::WebCryptoKeyUsageMask usages,
108 GenerateKeyResult* result) { 109 GenerateKeyResult* result) {
109 const AlgorithmImplementation* impl = NULL; 110 const AlgorithmImplementation* impl = NULL;
110 Status status = GetAlgorithmImplementation(algorithm.id(), &impl); 111 Status status = GetAlgorithmImplementation(algorithm.id(), &impl);
111 if (status.IsError()) 112 if (status.IsError())
112 return status; 113 return status;
113 114
114 return impl->GenerateKey(algorithm, extractable, usages, result); 115 status = impl->GenerateKey(algorithm, extractable, usages, result);
116 if (status.IsError())
117 return status;
118
119 const blink::WebCryptoKey* key = NULL;
120 if (result->type() == GenerateKeyResult::TYPE_SECRET_KEY)
121 key = &result->secret_key();
122 if (result->type() == GenerateKeyResult::TYPE_PUBLIC_PRIVATE_KEY_PAIR)
123 key = &result->private_key();
124 if (key == NULL)
125 return Status::ErrorUnexpected();
126
127 // This should only fail if an algorithm is implemented incorrectly and
128 // does not do its own check of the usages.
129 if (key->usages() == 0) {
130 DCHECK(false) << "Key usages for generateKey() must not be empty";
131 return Status::ErrorCreateKeyEmptyUsages();
132 }
133 return status;
115 } 134 }
116 135
117 Status ImportKey(blink::WebCryptoKeyFormat format, 136 Status ImportKey(blink::WebCryptoKeyFormat format,
118 const CryptoData& key_data, 137 const CryptoData& key_data,
119 const blink::WebCryptoAlgorithm& algorithm, 138 const blink::WebCryptoAlgorithm& algorithm,
120 bool extractable, 139 bool extractable,
121 blink::WebCryptoKeyUsageMask usages, 140 blink::WebCryptoKeyUsageMask usages,
122 blink::WebCryptoKey* key) { 141 blink::WebCryptoKey* key) {
123 const AlgorithmImplementation* impl = NULL; 142 const AlgorithmImplementation* impl = NULL;
124 Status status = GetAlgorithmImplementation(algorithm.id(), &impl); 143 Status status = GetAlgorithmImplementation(algorithm.id(), &impl);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 return false; 307 return false;
289 308
290 status = impl->DeserializeKeyForClone(algorithm, type, extractable, usages, 309 status = impl->DeserializeKeyForClone(algorithm, type, extractable, usages,
291 key_data, key); 310 key_data, key);
292 return status.IsSuccess(); 311 return status.IsSuccess();
293 } 312 }
294 313
295 } // namespace webcrypto 314 } // namespace webcrypto
296 315
297 } // namespace content 316 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698