| OLD | NEW |
| 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 "chrome/renderer/extensions/platform_keys_natives.h" | 5 #include "chrome/renderer/extensions/platform_keys_natives.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/renderer/extensions/chrome_v8_context.h" | 10 #include "chrome/renderer/extensions/chrome_v8_context.h" |
| 11 #include "content/public/renderer/v8_value_converter.h" | 11 #include "content/public/renderer/v8_value_converter.h" |
| 12 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" | 12 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" |
| 13 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 13 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
| 14 #include "third_party/WebKit/public/platform/WebString.h" | 14 #include "third_party/WebKit/public/platform/WebString.h" |
| 15 #include "third_party/WebKit/public/platform/WebVector.h" | 15 #include "third_party/WebKit/public/platform/WebVector.h" |
| 16 #include "third_party/WebKit/public/web/WebCryptoNormalize.h" | 16 #include "third_party/WebKit/public/web/WebCryptoNormalize.h" |
| 17 | 17 |
| 18 namespace extensions { | 18 namespace extensions { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 bool StringToWebCryptoOperation(const std::string& str, | 22 bool StringToWebCryptoOperation(const std::string& str, |
| 23 blink::WebCryptoOperation* op) { | 23 blink::WebCryptoOperation* op) { |
| 24 if (str == "GenerateKey") { | 24 if (str == "GenerateKey") { |
| 25 *op = blink::WebCryptoOperationGenerateKey; | 25 *op = blink::WebCryptoOperationGenerateKey; |
| 26 return true; | 26 return true; |
| 27 } | 27 } |
| 28 if (str == "ImportKey") { |
| 29 *op = blink::WebCryptoOperationImportKey; |
| 30 return true; |
| 31 } |
| 28 if (str == "Sign") { | 32 if (str == "Sign") { |
| 29 *op = blink::WebCryptoOperationSign; | 33 *op = blink::WebCryptoOperationSign; |
| 30 return true; | 34 return true; |
| 31 } | 35 } |
| 32 if (str == "Verify") { | 36 if (str == "Verify") { |
| 33 *op = blink::WebCryptoOperationVerify; | 37 *op = blink::WebCryptoOperationVerify; |
| 34 return true; | 38 return true; |
| 35 } | 39 } |
| 36 return false; | 40 return false; |
| 37 } | 41 } |
| 38 | 42 |
| 39 scoped_ptr<base::DictionaryValue> WebCryptoAlgorithmToBaseValue( | 43 scoped_ptr<base::DictionaryValue> WebCryptoAlgorithmToBaseValue( |
| 40 const blink::WebCryptoAlgorithm& algorithm) { | 44 const blink::WebCryptoAlgorithm& algorithm) { |
| 41 DCHECK(!algorithm.isNull()); | 45 DCHECK(!algorithm.isNull()); |
| 42 | 46 |
| 43 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); | 47 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
| 44 const blink::WebCryptoAlgorithmInfo* info = | 48 const blink::WebCryptoAlgorithmInfo* info = |
| 45 blink::WebCryptoAlgorithm::lookupAlgorithmInfo(algorithm.id()); | 49 blink::WebCryptoAlgorithm::lookupAlgorithmInfo(algorithm.id()); |
| 46 dict->SetStringWithoutPathExpansion("name", info->name); | 50 dict->SetStringWithoutPathExpansion("name", info->name); |
| 51 |
| 52 const blink::WebCryptoAlgorithm* hash = nullptr; |
| 53 |
| 47 const blink::WebCryptoRsaHashedKeyGenParams* rsaHashedKeyGen = | 54 const blink::WebCryptoRsaHashedKeyGenParams* rsaHashedKeyGen = |
| 48 algorithm.rsaHashedKeyGenParams(); | 55 algorithm.rsaHashedKeyGenParams(); |
| 49 if (rsaHashedKeyGen) { | 56 if (rsaHashedKeyGen) { |
| 50 dict->SetIntegerWithoutPathExpansion("modulusLength", | 57 dict->SetIntegerWithoutPathExpansion("modulusLength", |
| 51 rsaHashedKeyGen->modulusLengthBits()); | 58 rsaHashedKeyGen->modulusLengthBits()); |
| 52 const blink::WebVector<unsigned char>& public_exponent = | 59 const blink::WebVector<unsigned char>& public_exponent = |
| 53 rsaHashedKeyGen->publicExponent(); | 60 rsaHashedKeyGen->publicExponent(); |
| 54 dict->SetWithoutPathExpansion( | 61 dict->SetWithoutPathExpansion( |
| 55 "publicExponent", | 62 "publicExponent", |
| 56 base::BinaryValue::CreateWithCopiedBuffer( | 63 base::BinaryValue::CreateWithCopiedBuffer( |
| 57 reinterpret_cast<const char*>(public_exponent.data()), | 64 reinterpret_cast<const char*>(public_exponent.data()), |
| 58 public_exponent.size())); | 65 public_exponent.size())); |
| 59 | 66 |
| 60 const blink::WebCryptoAlgorithm& hash = rsaHashedKeyGen->hash(); | 67 hash = &rsaHashedKeyGen->hash(); |
| 61 DCHECK(!hash.isNull()); | 68 DCHECK(!hash->isNull()); |
| 69 } |
| 70 |
| 71 const blink::WebCryptoRsaHashedImportParams* rsaHashedImport = |
| 72 algorithm.rsaHashedImportParams(); |
| 73 if (rsaHashedImport) { |
| 74 hash = &rsaHashedImport->hash(); |
| 75 DCHECK(!hash->isNull()); |
| 76 } |
| 77 |
| 78 if (hash) { |
| 62 const blink::WebCryptoAlgorithmInfo* hash_info = | 79 const blink::WebCryptoAlgorithmInfo* hash_info = |
| 63 blink::WebCryptoAlgorithm::lookupAlgorithmInfo(hash.id()); | 80 blink::WebCryptoAlgorithm::lookupAlgorithmInfo(hash->id()); |
| 64 | 81 |
| 65 scoped_ptr<base::DictionaryValue> hash_dict(new base::DictionaryValue); | 82 scoped_ptr<base::DictionaryValue> hash_dict(new base::DictionaryValue); |
| 66 hash_dict->SetStringWithoutPathExpansion("name", hash_info->name); | 83 hash_dict->SetStringWithoutPathExpansion("name", hash_info->name); |
| 67 dict->SetWithoutPathExpansion("hash", hash_dict.release()); | 84 dict->SetWithoutPathExpansion("hash", hash_dict.release()); |
| 68 } | 85 } |
| 69 // Otherwise, |algorithm| is missing support here or no parameters were | 86 // Otherwise, |algorithm| is missing support here or no parameters were |
| 70 // required. | 87 // required. |
| 71 return dict.Pass(); | 88 return dict.Pass(); |
| 72 } | 89 } |
| 73 | 90 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 if (!algorithm_dict) | 123 if (!algorithm_dict) |
| 107 return; | 124 return; |
| 108 | 125 |
| 109 scoped_ptr<content::V8ValueConverter> converter( | 126 scoped_ptr<content::V8ValueConverter> converter( |
| 110 content::V8ValueConverter::create()); | 127 content::V8ValueConverter::create()); |
| 111 call_info.GetReturnValue().Set( | 128 call_info.GetReturnValue().Set( |
| 112 converter->ToV8Value(algorithm_dict.get(), context()->v8_context())); | 129 converter->ToV8Value(algorithm_dict.get(), context()->v8_context())); |
| 113 } | 130 } |
| 114 | 131 |
| 115 } // namespace extensions | 132 } // namespace extensions |
| OLD | NEW |