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

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

Issue 100593002: [webcrypto] Add symmetric key export for NSS and OpenSSL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/webcrypto_impl.h" 5 #include "content/renderer/webcrypto/webcrypto_impl.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>
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 const unsigned final_output_len = 150 const unsigned final_output_len =
151 static_cast<unsigned>(output_len) + 151 static_cast<unsigned>(output_len) +
152 static_cast<unsigned>(final_output_chunk_len); 152 static_cast<unsigned>(final_output_chunk_len);
153 DCHECK_LE(final_output_len, output_max_len); 153 DCHECK_LE(final_output_len, output_max_len);
154 154
155 webcrypto::ShrinkBuffer(buffer, final_output_len); 155 webcrypto::ShrinkBuffer(buffer, final_output_len);
156 156
157 return true; 157 return true;
158 } 158 }
159 159
160 bool ExportKeyInternalRaw(
161 const blink::WebCryptoKey& key,
162 blink::WebArrayBuffer* buffer) {
163
164 DCHECK(key.handle());
165 DCHECK(buffer);
166
167 if (key.type() != blink::WebCryptoKeyTypeSecret || !key.extractable())
168 return false;
169
170 SymKeyHandle* const sym_key = reinterpret_cast<SymKeyHandle*>(key.handle());
171
172 *buffer =
173 webcrypto::CreateArrayBuffer(&sym_key->key()[0], sym_key->key().size());
eroman 2013/12/05 01:47:53 Is it ever possible for the key length to be 0?
padolph 2013/12/05 02:45:57 Yes. Empty symmetric keys are supported and alread
eroman 2013/12/05 02:53:58 If the key is empty, then I don't think we should
padolph 2013/12/05 03:34:16 Done.
174
175 return true;
176 }
177
160 } // namespace 178 } // namespace
161 179
162 void WebCryptoImpl::Init() { crypto::EnsureOpenSSLInit(); } 180 void WebCryptoImpl::Init() { crypto::EnsureOpenSSLInit(); }
163 181
164 bool WebCryptoImpl::EncryptInternal(const blink::WebCryptoAlgorithm& algorithm, 182 bool WebCryptoImpl::EncryptInternal(const blink::WebCryptoAlgorithm& algorithm,
165 const blink::WebCryptoKey& key, 183 const blink::WebCryptoKey& key,
166 const unsigned char* data, 184 const unsigned char* data,
167 unsigned data_size, 185 unsigned data_size,
168 blink::WebArrayBuffer* buffer) { 186 blink::WebArrayBuffer* buffer) {
169 if (algorithm.id() == blink::WebCryptoAlgorithmIdAesCbc) { 187 if (algorithm.id() == blink::WebCryptoAlgorithmIdAesCbc) {
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 new SymKeyHandle(raw_key_data, raw_key_data_size), 381 new SymKeyHandle(raw_key_data, raw_key_data_size),
364 type, extractable, algorithm, usage_mask); 382 type, extractable, algorithm, usage_mask);
365 383
366 return true; 384 return true;
367 } 385 }
368 386
369 bool WebCryptoImpl::ExportKeyInternal( 387 bool WebCryptoImpl::ExportKeyInternal(
370 blink::WebCryptoKeyFormat format, 388 blink::WebCryptoKeyFormat format,
371 const blink::WebCryptoKey& key, 389 const blink::WebCryptoKey& key,
372 blink::WebArrayBuffer* buffer) { 390 blink::WebArrayBuffer* buffer) {
373 // TODO(padolph): Implement raw export 391 switch (format) {
374 // TODO(padolph): Implement spki export 392 case blink::WebCryptoKeyFormatRaw:
375 // TODO(padolph): Implement pkcs8 export 393 return ExportKeyInternalRaw(key, buffer);
376 // TODO(padolph): Implement jwk export 394 case blink::WebCryptoKeyFormatSpki:
395 // TODO(padolph): Implement spki export
396 return false;
397 case blink::WebCryptoKeyFormatPkcs8:
398 // TODO(padolph): Implement pkcs8 export
399 return false;
400 default:
401 return false;
402 }
377 return false; 403 return false;
378 } 404 }
379 405
380 bool WebCryptoImpl::SignInternal( 406 bool WebCryptoImpl::SignInternal(
381 const blink::WebCryptoAlgorithm& algorithm, 407 const blink::WebCryptoAlgorithm& algorithm,
382 const blink::WebCryptoKey& key, 408 const blink::WebCryptoKey& key,
383 const unsigned char* data, 409 const unsigned char* data,
384 unsigned data_size, 410 unsigned data_size,
385 blink::WebArrayBuffer* buffer) { 411 blink::WebArrayBuffer* buffer) {
386 412
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 const blink::WebCryptoAlgorithm& algorithm, 530 const blink::WebCryptoAlgorithm& algorithm,
505 bool extractable, 531 bool extractable,
506 blink::WebCryptoKeyUsageMask usage_mask, 532 blink::WebCryptoKeyUsageMask usage_mask,
507 blink::WebCryptoKey* key) { 533 blink::WebCryptoKey* key) {
508 // TODO(padolph): Placeholder for OpenSSL implementation. 534 // TODO(padolph): Placeholder for OpenSSL implementation.
509 // Issue http://crbug.com/267888. 535 // Issue http://crbug.com/267888.
510 return false; 536 return false;
511 } 537 }
512 538
513 } // namespace content 539 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698