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

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

Issue 182073002: [webcrypto] Remove code conditional on !defined(WEBCRYPTO_HAS_KEY_ALGORITHM). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 9 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" 21 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h"
23 #endif
24 22
25 namespace content { 23 namespace content {
26 24
27 namespace webcrypto { 25 namespace webcrypto {
28 26
29 namespace platform { 27 namespace platform {
30 28
31 class SymKey : public Key { 29 class SymKey : public Key {
32 public: 30 public:
33 explicit SymKey(const CryptoData& key_data) 31 explicit SymKey(const CryptoData& key_data)
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // TODO(eroman): Is this right? 215 // TODO(eroman): Is this right?
218 if (keylen_bytes == 0) 216 if (keylen_bytes == 0)
219 return Status::ErrorGenerateKeyLength(); 217 return Status::ErrorGenerateKeyLength();
220 218
221 crypto::OpenSSLErrStackTracer(FROM_HERE); 219 crypto::OpenSSLErrStackTracer(FROM_HERE);
222 220
223 std::vector<unsigned char> random_bytes(keylen_bytes, 0); 221 std::vector<unsigned char> random_bytes(keylen_bytes, 0);
224 if (!(RAND_bytes(&random_bytes[0], keylen_bytes))) 222 if (!(RAND_bytes(&random_bytes[0], keylen_bytes)))
225 return Status::Error(); 223 return Status::Error();
226 224
227 #ifdef WEBCRYPTO_HAS_KEY_ALGORITHM
228 blink::WebCryptoKeyAlgorithm key_algorithm; 225 blink::WebCryptoKeyAlgorithm key_algorithm;
229 if (!CreateSecretKeyAlgorithm(algorithm, keylen_bytes, &key_algorithm)) 226 if (!CreateSecretKeyAlgorithm(algorithm, keylen_bytes, &key_algorithm))
230 return Status::ErrorUnexpected(); 227 return Status::ErrorUnexpected();
231 #else
232 const blink::WebCryptoAlgorithm key_algorithm = algorithm;
233 #endif
234 228
235 *key = blink::WebCryptoKey::create(new SymKey(CryptoData(random_bytes)), 229 *key = blink::WebCryptoKey::create(new SymKey(CryptoData(random_bytes)),
236 blink::WebCryptoKeyTypeSecret, 230 blink::WebCryptoKeyTypeSecret,
237 extractable, 231 extractable,
238 key_algorithm, 232 key_algorithm,
239 usage_mask); 233 usage_mask);
240 234
241 return Status::Success(); 235 return Status::Success();
242 } 236 }
243 237
244 Status GenerateRsaKeyPair(const blink::WebCryptoAlgorithm& algorithm, 238 Status GenerateRsaKeyPair(const blink::WebCryptoAlgorithm& algorithm,
245 bool extractable, 239 bool extractable,
246 blink::WebCryptoKeyUsageMask usage_mask, 240 blink::WebCryptoKeyUsageMask usage_mask,
247 unsigned int modulus_length_bits, 241 unsigned int modulus_length_bits,
248 const CryptoData& public_exponent, 242 const CryptoData& public_exponent,
249 const blink::WebCryptoAlgorithm& hash, 243 const blink::WebCryptoAlgorithm& hash,
250 blink::WebCryptoKey* public_key, 244 blink::WebCryptoKey* public_key,
251 blink::WebCryptoKey* private_key) { 245 blink::WebCryptoKey* private_key) {
252 // TODO(padolph): Placeholder for OpenSSL implementation. 246 // TODO(padolph): Placeholder for OpenSSL implementation.
253 // Issue http://crbug.com/267888. 247 // Issue http://crbug.com/267888.
254 return Status::ErrorUnsupported(); 248 return Status::ErrorUnsupported();
255 } 249 }
256 250
257 Status ImportKeyRaw(const blink::WebCryptoAlgorithm& algorithm, 251 Status ImportKeyRaw(const blink::WebCryptoAlgorithm& algorithm,
258 const CryptoData& key_data, 252 const CryptoData& key_data,
259 bool extractable, 253 bool extractable,
260 blink::WebCryptoKeyUsageMask usage_mask, 254 blink::WebCryptoKeyUsageMask usage_mask,
261 blink::WebCryptoKey* key) { 255 blink::WebCryptoKey* key) {
262 256
263 #ifdef WEBCRYPTO_HAS_KEY_ALGORITHM
264 blink::WebCryptoKeyAlgorithm key_algorithm; 257 blink::WebCryptoKeyAlgorithm key_algorithm;
265 if (!CreateSecretKeyAlgorithm( 258 if (!CreateSecretKeyAlgorithm(
266 algorithm, key_data.byte_length(), &key_algorithm)) 259 algorithm, key_data.byte_length(), &key_algorithm))
267 return Status::ErrorUnexpected(); 260 return Status::ErrorUnexpected();
268 #else
269 const blink::WebCryptoAlgorithm key_algorithm = algorithm;
270 #endif
271 261
272 *key = blink::WebCryptoKey::create(new SymKey(key_data), 262 *key = blink::WebCryptoKey::create(new SymKey(key_data),
273 blink::WebCryptoKeyTypeSecret, 263 blink::WebCryptoKeyTypeSecret,
274 extractable, 264 extractable,
275 key_algorithm, 265 key_algorithm,
276 usage_mask); 266 usage_mask);
277 267
278 return Status::Success(); 268 return Status::Success();
279 } 269 }
280 270
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 Status ExportKeySpki(PublicKey* key, blink::WebArrayBuffer* buffer) { 386 Status ExportKeySpki(PublicKey* key, blink::WebArrayBuffer* buffer) {
397 // TODO(eroman): http://crbug.com/267888 387 // TODO(eroman): http://crbug.com/267888
398 return Status::ErrorUnsupported(); 388 return Status::ErrorUnsupported();
399 } 389 }
400 390
401 } // namespace platform 391 } // namespace platform
402 392
403 } // namespace webcrypto 393 } // namespace webcrypto
404 394
405 } // namespace content 395 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/webcrypto/platform_crypto_nss.cc ('k') | content/renderer/webcrypto/shared_crypto.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698