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

Side by Side Diff: content/renderer/webcrypto/platform_crypto_openssl.cc

Issue 178073007: [webcrypto] Update to use the KeyAlgorithm. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unrelated change that makes public keys extractable Created 6 years, 10 months 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 | Annotate | Revision Log
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/renderer/webcrypto/platform_crypto.h" 5 #include "content/renderer/webcrypto/platform_crypto.h"
6 6
7 #include <vector> 7 #include <vector>
8 #include <openssl/aes.h> 8 #include <openssl/aes.h>
9 #include <openssl/evp.h> 9 #include <openssl/evp.h>
10 #include <openssl/hmac.h> 10 #include <openssl/hmac.h>
11 #include <openssl/rand.h> 11 #include <openssl/rand.h>
12 #include <openssl/sha.h> 12 #include <openssl/sha.h>
13 13
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "content/renderer/webcrypto/crypto_data.h" 15 #include "content/renderer/webcrypto/crypto_data.h"
16 #include "content/renderer/webcrypto/webcrypto_util.h" 16 #include "content/renderer/webcrypto/webcrypto_util.h"
17 #include "crypto/openssl_util.h" 17 #include "crypto/openssl_util.h"
18 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" 18 #include "third_party/WebKit/public/platform/WebArrayBuffer.h"
19 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" 19 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h"
20 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" 20 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h"
21 #ifdef WEBCRYPTO_HAS_KEY_ALGORITHM
22 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h"
23 #endif
21 24
22 namespace content { 25 namespace content {
23 26
24 namespace webcrypto { 27 namespace webcrypto {
25 28
26 namespace platform { 29 namespace platform {
27 30
28 class SymKey : public Key { 31 class SymKey : public Key {
29 public: 32 public:
30 explicit SymKey(const CryptoData& key_data) 33 explicit SymKey(const CryptoData& key_data)
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 // TODO(eroman): Is this right? 218 // TODO(eroman): Is this right?
216 if (keylen_bytes == 0) 219 if (keylen_bytes == 0)
217 return Status::ErrorGenerateKeyLength(); 220 return Status::ErrorGenerateKeyLength();
218 221
219 crypto::OpenSSLErrStackTracer(FROM_HERE); 222 crypto::OpenSSLErrStackTracer(FROM_HERE);
220 223
221 std::vector<unsigned char> random_bytes(keylen_bytes, 0); 224 std::vector<unsigned char> random_bytes(keylen_bytes, 0);
222 if (!(RAND_bytes(&random_bytes[0], keylen_bytes))) 225 if (!(RAND_bytes(&random_bytes[0], keylen_bytes)))
223 return Status::Error(); 226 return Status::Error();
224 227
228 #ifdef WEBCRYPTO_HAS_KEY_ALGORITHM
229 blink::WebCryptoKeyAlgorithm key_algorithm;
230 if (!CreateSecretKeyAlgorithm(algorithm, keylen_bytes, &key_algorithm))
231 return Status::ErrorUnexpected();
232 #else
233 const blink::WebCryptoAlgorithm key_algorithm = algorithm;
234 #endif
235
225 *key = blink::WebCryptoKey::create(new SymKey(CryptoData(random_bytes)), 236 *key = blink::WebCryptoKey::create(new SymKey(CryptoData(random_bytes)),
226 blink::WebCryptoKeyTypeSecret, 237 blink::WebCryptoKeyTypeSecret,
227 extractable, 238 extractable,
228 algorithm, 239 key_algorithm,
229 usage_mask); 240 usage_mask);
230 241
231 return Status::Success(); 242 return Status::Success();
232 } 243 }
233 244
234 Status GenerateRsaKeyPair(const blink::WebCryptoAlgorithm& algorithm, 245 Status GenerateRsaKeyPair(const blink::WebCryptoAlgorithm& algorithm,
235 bool extractable, 246 bool extractable,
236 blink::WebCryptoKeyUsageMask usage_mask, 247 blink::WebCryptoKeyUsageMask usage_mask,
248 unsigned int modulus_length_bits,
249 const CryptoData& public_exponent,
250 const blink::WebCryptoAlgorithm& hash,
237 blink::WebCryptoKey* public_key, 251 blink::WebCryptoKey* public_key,
238 blink::WebCryptoKey* private_key) { 252 blink::WebCryptoKey* private_key) {
239 // TODO(padolph): Placeholder for OpenSSL implementation. 253 // TODO(padolph): Placeholder for OpenSSL implementation.
240 // Issue http://crbug.com/267888. 254 // Issue http://crbug.com/267888.
241 return Status::ErrorUnsupported(); 255 return Status::ErrorUnsupported();
242 } 256 }
243 257
244 Status ImportKeyRaw(const blink::WebCryptoAlgorithm& algorithm, 258 Status ImportKeyRaw(const blink::WebCryptoAlgorithm& algorithm,
245 const CryptoData& key_data, 259 const CryptoData& key_data,
246 bool extractable, 260 bool extractable,
247 blink::WebCryptoKeyUsageMask usage_mask, 261 blink::WebCryptoKeyUsageMask usage_mask,
248 blink::WebCryptoKey* key) { 262 blink::WebCryptoKey* key) {
263
264 #ifdef WEBCRYPTO_HAS_KEY_ALGORITHM
265 blink::WebCryptoKeyAlgorithm key_algorithm;
266 if (!CreateSecretKeyAlgorithm(
267 algorithm, key_data.byte_length(), &key_algorithm))
268 return Status::ErrorUnexpected();
269 #else
270 const blink::WebCryptoAlgorithm key_algorithm = algorithm;
271 #endif
272
249 *key = blink::WebCryptoKey::create(new SymKey(key_data), 273 *key = blink::WebCryptoKey::create(new SymKey(key_data),
250 blink::WebCryptoKeyTypeSecret, 274 blink::WebCryptoKeyTypeSecret,
251 extractable, 275 extractable,
252 algorithm, 276 key_algorithm,
253 usage_mask); 277 usage_mask);
254 278
255 return Status::Success(); 279 return Status::Success();
256 } 280 }
257 281
258 Status SignHmac(SymKey* key, 282 Status SignHmac(SymKey* key,
259 const blink::WebCryptoAlgorithm& hash, 283 const blink::WebCryptoAlgorithm& hash,
260 const CryptoData& data, 284 const CryptoData& data,
261 blink::WebArrayBuffer* buffer) { 285 blink::WebArrayBuffer* buffer) {
262 blink::WebArrayBuffer result; 286 blink::WebArrayBuffer result;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 Status ExportKeySpki(PublicKey* key, blink::WebArrayBuffer* buffer) { 421 Status ExportKeySpki(PublicKey* key, blink::WebArrayBuffer* buffer) {
398 // TODO(eroman): http://crbug.com/267888 422 // TODO(eroman): http://crbug.com/267888
399 return Status::ErrorUnsupported(); 423 return Status::ErrorUnsupported();
400 } 424 }
401 425
402 } // namespace platform 426 } // namespace platform
403 427
404 } // namespace webcrypto 428 } // namespace webcrypto
405 429
406 } // namespace content 430 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/webcrypto/platform_crypto_nss.cc ('k') | content/renderer/webcrypto/shared_crypto.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698