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

Side by Side Diff: chrome/renderer/extensions/platform_keys_natives.cc

Issue 929683002: Revert "Implement chrome.platformKeys.getKeyPair()." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
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 "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/child/v8_value_converter.h" 11 #include "content/public/child/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 }
32 if (str == "Sign") { 28 if (str == "Sign") {
33 *op = blink::WebCryptoOperationSign; 29 *op = blink::WebCryptoOperationSign;
34 return true; 30 return true;
35 } 31 }
36 if (str == "Verify") { 32 if (str == "Verify") {
37 *op = blink::WebCryptoOperationVerify; 33 *op = blink::WebCryptoOperationVerify;
38 return true; 34 return true;
39 } 35 }
40 return false; 36 return false;
41 } 37 }
42 38
43 scoped_ptr<base::DictionaryValue> WebCryptoAlgorithmToBaseValue( 39 scoped_ptr<base::DictionaryValue> WebCryptoAlgorithmToBaseValue(
44 const blink::WebCryptoAlgorithm& algorithm) { 40 const blink::WebCryptoAlgorithm& algorithm) {
45 DCHECK(!algorithm.isNull()); 41 DCHECK(!algorithm.isNull());
46 42
47 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 43 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
48 const blink::WebCryptoAlgorithmInfo* info = 44 const blink::WebCryptoAlgorithmInfo* info =
49 blink::WebCryptoAlgorithm::lookupAlgorithmInfo(algorithm.id()); 45 blink::WebCryptoAlgorithm::lookupAlgorithmInfo(algorithm.id());
50 dict->SetStringWithoutPathExpansion("name", info->name); 46 dict->SetStringWithoutPathExpansion("name", info->name);
51
52 const blink::WebCryptoAlgorithm* hash = nullptr;
53
54 const blink::WebCryptoRsaHashedKeyGenParams* rsaHashedKeyGen = 47 const blink::WebCryptoRsaHashedKeyGenParams* rsaHashedKeyGen =
55 algorithm.rsaHashedKeyGenParams(); 48 algorithm.rsaHashedKeyGenParams();
56 if (rsaHashedKeyGen) { 49 if (rsaHashedKeyGen) {
57 dict->SetIntegerWithoutPathExpansion("modulusLength", 50 dict->SetIntegerWithoutPathExpansion("modulusLength",
58 rsaHashedKeyGen->modulusLengthBits()); 51 rsaHashedKeyGen->modulusLengthBits());
59 const blink::WebVector<unsigned char>& public_exponent = 52 const blink::WebVector<unsigned char>& public_exponent =
60 rsaHashedKeyGen->publicExponent(); 53 rsaHashedKeyGen->publicExponent();
61 dict->SetWithoutPathExpansion( 54 dict->SetWithoutPathExpansion(
62 "publicExponent", 55 "publicExponent",
63 base::BinaryValue::CreateWithCopiedBuffer( 56 base::BinaryValue::CreateWithCopiedBuffer(
64 reinterpret_cast<const char*>(public_exponent.data()), 57 reinterpret_cast<const char*>(public_exponent.data()),
65 public_exponent.size())); 58 public_exponent.size()));
66 59
67 hash = &rsaHashedKeyGen->hash(); 60 const blink::WebCryptoAlgorithm& hash = rsaHashedKeyGen->hash();
68 DCHECK(!hash->isNull()); 61 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) {
79 const blink::WebCryptoAlgorithmInfo* hash_info = 62 const blink::WebCryptoAlgorithmInfo* hash_info =
80 blink::WebCryptoAlgorithm::lookupAlgorithmInfo(hash->id()); 63 blink::WebCryptoAlgorithm::lookupAlgorithmInfo(hash.id());
81 64
82 scoped_ptr<base::DictionaryValue> hash_dict(new base::DictionaryValue); 65 scoped_ptr<base::DictionaryValue> hash_dict(new base::DictionaryValue);
83 hash_dict->SetStringWithoutPathExpansion("name", hash_info->name); 66 hash_dict->SetStringWithoutPathExpansion("name", hash_info->name);
84 dict->SetWithoutPathExpansion("hash", hash_dict.release()); 67 dict->SetWithoutPathExpansion("hash", hash_dict.release());
85 } 68 }
86 // Otherwise, |algorithm| is missing support here or no parameters were 69 // Otherwise, |algorithm| is missing support here or no parameters were
87 // required. 70 // required.
88 return dict.Pass(); 71 return dict.Pass();
89 } 72 }
90 73
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 if (!algorithm_dict) 106 if (!algorithm_dict)
124 return; 107 return;
125 108
126 scoped_ptr<content::V8ValueConverter> converter( 109 scoped_ptr<content::V8ValueConverter> converter(
127 content::V8ValueConverter::create()); 110 content::V8ValueConverter::create());
128 call_info.GetReturnValue().Set( 111 call_info.GetReturnValue().Set(
129 converter->ToV8Value(algorithm_dict.get(), context()->v8_context())); 112 converter->ToV8Value(algorithm_dict.get(), context()->v8_context()));
130 } 113 }
131 114
132 } // namespace extensions 115 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698