Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 const unsigned final_output_len = | 149 const unsigned final_output_len = |
| 150 static_cast<unsigned>(output_len) + | 150 static_cast<unsigned>(output_len) + |
| 151 static_cast<unsigned>(final_output_chunk_len); | 151 static_cast<unsigned>(final_output_chunk_len); |
| 152 DCHECK_LE(final_output_len, output_max_len); | 152 DCHECK_LE(final_output_len, output_max_len); |
| 153 | 153 |
| 154 WebCryptoImpl::ShrinkBuffer(buffer, final_output_len); | 154 WebCryptoImpl::ShrinkBuffer(buffer, final_output_len); |
| 155 | 155 |
| 156 return true; | 156 return true; |
| 157 } | 157 } |
| 158 | 158 |
| 159 bool ExportKeyInternalRaw( | |
| 160 const blink::WebCryptoKey& key, | |
| 161 blink::WebArrayBuffer* buffer) { | |
| 162 | |
| 163 DCHECK(key.handle()); | |
| 164 DCHECK(buffer); | |
| 165 | |
| 166 if (key.type() != blink::WebCryptoKeyTypeSecret || !key.extractable()) | |
| 167 return false; | |
| 168 | |
| 169 SymKeyHandle* const sym_key = reinterpret_cast<SymKeyHandle*>(key.handle()); | |
| 170 | |
| 171 *buffer = blink::WebArrayBuffer::create(sym_key->key().size(), 1); | |
|
eroman
2013/12/04 19:04:00
[optional] Consider extracting this to a helper in
padolph
2013/12/04 22:22:13
Done.
| |
| 172 memcpy(buffer->data(), &sym_key->key()[0], sym_key->key().size()); | |
| 173 | |
| 174 return true; | |
| 175 } | |
| 176 | |
| 159 } // namespace | 177 } // namespace |
| 160 | 178 |
| 161 void WebCryptoImpl::Init() { crypto::EnsureOpenSSLInit(); } | 179 void WebCryptoImpl::Init() { crypto::EnsureOpenSSLInit(); } |
| 162 | 180 |
| 163 bool WebCryptoImpl::EncryptInternal(const blink::WebCryptoAlgorithm& algorithm, | 181 bool WebCryptoImpl::EncryptInternal(const blink::WebCryptoAlgorithm& algorithm, |
| 164 const blink::WebCryptoKey& key, | 182 const blink::WebCryptoKey& key, |
| 165 const unsigned char* data, | 183 const unsigned char* data, |
| 166 unsigned data_size, | 184 unsigned data_size, |
| 167 blink::WebArrayBuffer* buffer) { | 185 blink::WebArrayBuffer* buffer) { |
| 168 if (algorithm.id() == blink::WebCryptoAlgorithmIdAesCbc) { | 186 if (algorithm.id() == blink::WebCryptoAlgorithmIdAesCbc) { |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 new SymKeyHandle(raw_key_data, raw_key_data_size), | 379 new SymKeyHandle(raw_key_data, raw_key_data_size), |
| 362 type, extractable, algorithm, usage_mask); | 380 type, extractable, algorithm, usage_mask); |
| 363 | 381 |
| 364 return true; | 382 return true; |
| 365 } | 383 } |
| 366 | 384 |
| 367 bool WebCryptoImpl::ExportKeyInternal( | 385 bool WebCryptoImpl::ExportKeyInternal( |
| 368 blink::WebCryptoKeyFormat format, | 386 blink::WebCryptoKeyFormat format, |
| 369 const blink::WebCryptoKey& key, | 387 const blink::WebCryptoKey& key, |
| 370 blink::WebArrayBuffer* buffer) { | 388 blink::WebArrayBuffer* buffer) { |
| 371 // TODO(padolph): Implement raw export | 389 switch (format) { |
| 372 // TODO(padolph): Implement spki export | 390 case blink::WebCryptoKeyFormatRaw: |
| 373 // TODO(padolph): Implement pkcs8 export | 391 return ExportKeyInternalRaw(key, buffer); |
| 374 // TODO(padolph): Implement jwk export | 392 case blink::WebCryptoKeyFormatSpki: |
| 393 // TODO(padolph): Implement spki export | |
| 394 return false; | |
| 395 case blink::WebCryptoKeyFormatPkcs8: | |
| 396 // TODO(padolph): Implement pkcs8 export | |
| 397 return false; | |
| 398 default: | |
| 399 return false; | |
| 400 } | |
| 375 return false; | 401 return false; |
| 376 } | 402 } |
| 377 | 403 |
| 378 bool WebCryptoImpl::SignInternal( | 404 bool WebCryptoImpl::SignInternal( |
| 379 const blink::WebCryptoAlgorithm& algorithm, | 405 const blink::WebCryptoAlgorithm& algorithm, |
| 380 const blink::WebCryptoKey& key, | 406 const blink::WebCryptoKey& key, |
| 381 const unsigned char* data, | 407 const unsigned char* data, |
| 382 unsigned data_size, | 408 unsigned data_size, |
| 383 blink::WebArrayBuffer* buffer) { | 409 blink::WebArrayBuffer* buffer) { |
| 384 | 410 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 488 | 514 |
| 489 break; | 515 break; |
| 490 } | 516 } |
| 491 default: | 517 default: |
| 492 return false; | 518 return false; |
| 493 } | 519 } |
| 494 return true; | 520 return true; |
| 495 } | 521 } |
| 496 | 522 |
| 497 } // namespace content | 523 } // namespace content |
| OLD | NEW |