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

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

Issue 298073009: Reuse WebCrypto's normalizeCryptoAlgorithm in enterprise.platformKeys. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/renderer/extensions/enterprise_platform_keys_natives.h"
6
7 #include <string>
8
9 #include "base/values.h"
10 #include "chrome/renderer/extensions/chrome_v8_context.h"
11 #include "content/public/renderer/v8_value_converter.h"
12 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h"
13 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmOperation.h"
14 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h"
15 #include "third_party/WebKit/public/platform/WebString.h"
16 #include "third_party/WebKit/public/web/WebScriptBindings.h"
17
18 namespace extensions {
19
20 namespace {
21
22 std::string AlgorithmIdToName(blink::WebCryptoAlgorithmId id) {
23 switch (id) {
24 case blink::WebCryptoAlgorithmIdHmac:
25 return "HMAC";
26 case blink::WebCryptoAlgorithmIdSha1:
27 return "SHA-1";
28 case blink::WebCryptoAlgorithmIdAesKw:
29 return "AES-KW";
30 case blink::WebCryptoAlgorithmIdSha512:
31 return "SHA-512";
32 case blink::WebCryptoAlgorithmIdSha384:
33 return "SHA-384";
34 case blink::WebCryptoAlgorithmIdSha256:
35 return "SHA-256";
36 case blink::WebCryptoAlgorithmIdAesCbc:
37 return "AES-CBC";
38 case blink::WebCryptoAlgorithmIdAesGcm:
39 return "AES-GCM";
40 case blink::WebCryptoAlgorithmIdAesCtr:
41 return "AES-CTR";
42 case blink::WebCryptoAlgorithmIdRsaOaep:
43 return "RSA-OAEP";
44 case blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5:
45 return "RSAES-PKCS1-V1_5";
46 case blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5:
47 return "RSASSA-PKCS1-V1_5";
48 default:
not at google - send to devlin 2014/05/29 15:06:57 if you leave out the default case it will be a com
pneubeck (no reviews) 2014/06/02 14:01:55 Done.
49 NOTREACHED();
50 return "";
51 }
52 }
53
54 scoped_ptr<base::DictionaryValue> WebCryptoAlgorithmToBaseValue(
55 const blink::WebCryptoAlgorithm& algorithm) {
56 DCHECK(!algorithm.isNull());
57
58 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
not at google - send to devlin 2014/05/29 15:06:57 is this method likely to get much more complicated
pneubeck (no reviews) 2014/06/02 14:01:55 I expect it to become more complicated once we hav
59 dict->SetStringWithoutPathExpansion("name",
60 AlgorithmIdToName(algorithm.id()));
61 switch (algorithm.id()) {
62 case blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5: {
63 const blink::WebCryptoRsaHashedKeyGenParams* params =
64 algorithm.rsaHashedKeyGenParams();
65 dict->SetIntegerWithoutPathExpansion("modulusLength",
66 params->modulusLengthBits());
67 break;
68 }
69 default:
70 // Not supported yet.
71 return scoped_ptr<base::DictionaryValue>();
72 }
73 return dict.Pass();
74 }
75
76 } // namespace
77
78 EnterprisePlatformKeysNatives::EnterprisePlatformKeysNatives(
79 ScriptContext* context)
80 : ObjectBackedNativeHandler(context) {
81 RouteFunction("NormalizeAlgorithm",
82 base::Bind(&EnterprisePlatformKeysNatives::NormalizeAlgorithm,
83 base::Unretained(this)));
84 }
85
86 void EnterprisePlatformKeysNatives::NormalizeAlgorithm(
87 const v8::FunctionCallbackInfo<v8::Value>& call_info) {
88 DCHECK(call_info.Length() == 2);
not at google - send to devlin 2014/05/29 15:06:57 DCHECK_EQ
pneubeck (no reviews) 2014/06/02 14:01:55 Done.
89 DCHECK(call_info[0]->IsObject());
90 DCHECK(call_info[1]->IsString());
91
92 std::string operation(*v8::String::Utf8Value(call_info[1]));
not at google - send to devlin 2014/05/29 15:06:57 not used?
pneubeck (no reviews) 2014/06/02 14:01:55 Now it is.
93
94 blink::WebString error_details;
95 int exception_code;
96
97 blink::WebCryptoAlgorithm algorithm =
98 blink::WebScriptBindings::normalizeCryptoAlgorithm(
99 call_info[0]->ToObject(),
100 blink::GenerateKey,
101 &exception_code,
102 &error_details,
103 call_info.GetIsolate());
104
105 scoped_ptr<base::DictionaryValue> algorithmDict;
not at google - send to devlin 2014/05/29 15:06:57 algorithm_dict
pneubeck (no reviews) 2014/06/02 14:01:55 Done.
106 if (!algorithm.isNull())
107 algorithmDict = WebCryptoAlgorithmToBaseValue(algorithm);
108
109 if (!algorithmDict) {
110 call_info.GetReturnValue().SetNull();
not at google - send to devlin 2014/05/29 15:06:57 there are a couple of other ways you could fail he
pneubeck (no reviews) 2014/06/02 14:01:55 changed to the simpler undefined. I have to extend
111 } else {
112 scoped_ptr<content::V8ValueConverter> converter(
113 content::V8ValueConverter::create());
114 call_info.GetReturnValue().Set(
115 converter->ToV8Value(algorithmDict.get(), context()->v8_context()));
116 }
117 }
118
119 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698