Chromium Code Reviews| Index: chrome/renderer/extensions/enterprise_platform_keys_natives.cc |
| diff --git a/chrome/renderer/extensions/enterprise_platform_keys_natives.cc b/chrome/renderer/extensions/enterprise_platform_keys_natives.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..63c80ea49db7f7e09a1621ff0ac1bf3d3c967d43 |
| --- /dev/null |
| +++ b/chrome/renderer/extensions/enterprise_platform_keys_natives.cc |
| @@ -0,0 +1,119 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/renderer/extensions/enterprise_platform_keys_natives.h" |
| + |
| +#include <string> |
| + |
| +#include "base/values.h" |
| +#include "chrome/renderer/extensions/chrome_v8_context.h" |
| +#include "content/public/renderer/v8_value_converter.h" |
| +#include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" |
| +#include "third_party/WebKit/public/platform/WebCryptoAlgorithmOperation.h" |
| +#include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
| +#include "third_party/WebKit/public/platform/WebString.h" |
| +#include "third_party/WebKit/public/web/WebScriptBindings.h" |
| + |
| +namespace extensions { |
| + |
| +namespace { |
| + |
| +std::string AlgorithmIdToName(blink::WebCryptoAlgorithmId id) { |
| + switch (id) { |
| + case blink::WebCryptoAlgorithmIdHmac: |
| + return "HMAC"; |
| + case blink::WebCryptoAlgorithmIdSha1: |
| + return "SHA-1"; |
| + case blink::WebCryptoAlgorithmIdAesKw: |
| + return "AES-KW"; |
| + case blink::WebCryptoAlgorithmIdSha512: |
| + return "SHA-512"; |
| + case blink::WebCryptoAlgorithmIdSha384: |
| + return "SHA-384"; |
| + case blink::WebCryptoAlgorithmIdSha256: |
| + return "SHA-256"; |
| + case blink::WebCryptoAlgorithmIdAesCbc: |
| + return "AES-CBC"; |
| + case blink::WebCryptoAlgorithmIdAesGcm: |
| + return "AES-GCM"; |
| + case blink::WebCryptoAlgorithmIdAesCtr: |
| + return "AES-CTR"; |
| + case blink::WebCryptoAlgorithmIdRsaOaep: |
| + return "RSA-OAEP"; |
| + case blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5: |
| + return "RSAES-PKCS1-V1_5"; |
| + case blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5: |
| + return "RSASSA-PKCS1-V1_5"; |
| + 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.
|
| + NOTREACHED(); |
| + return ""; |
| + } |
| +} |
| + |
| +scoped_ptr<base::DictionaryValue> WebCryptoAlgorithmToBaseValue( |
| + const blink::WebCryptoAlgorithm& algorithm) { |
| + DCHECK(!algorithm.isNull()); |
| + |
| + 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
|
| + dict->SetStringWithoutPathExpansion("name", |
| + AlgorithmIdToName(algorithm.id())); |
| + switch (algorithm.id()) { |
| + case blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5: { |
| + const blink::WebCryptoRsaHashedKeyGenParams* params = |
| + algorithm.rsaHashedKeyGenParams(); |
| + dict->SetIntegerWithoutPathExpansion("modulusLength", |
| + params->modulusLengthBits()); |
| + break; |
| + } |
| + default: |
| + // Not supported yet. |
| + return scoped_ptr<base::DictionaryValue>(); |
| + } |
| + return dict.Pass(); |
| +} |
| + |
| +} // namespace |
| + |
| +EnterprisePlatformKeysNatives::EnterprisePlatformKeysNatives( |
| + ScriptContext* context) |
| + : ObjectBackedNativeHandler(context) { |
| + RouteFunction("NormalizeAlgorithm", |
| + base::Bind(&EnterprisePlatformKeysNatives::NormalizeAlgorithm, |
| + base::Unretained(this))); |
| +} |
| + |
| +void EnterprisePlatformKeysNatives::NormalizeAlgorithm( |
| + const v8::FunctionCallbackInfo<v8::Value>& call_info) { |
| + 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.
|
| + DCHECK(call_info[0]->IsObject()); |
| + DCHECK(call_info[1]->IsString()); |
| + |
| + 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.
|
| + |
| + blink::WebString error_details; |
| + int exception_code; |
| + |
| + blink::WebCryptoAlgorithm algorithm = |
| + blink::WebScriptBindings::normalizeCryptoAlgorithm( |
| + call_info[0]->ToObject(), |
| + blink::GenerateKey, |
| + &exception_code, |
| + &error_details, |
| + call_info.GetIsolate()); |
| + |
| + 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.
|
| + if (!algorithm.isNull()) |
| + algorithmDict = WebCryptoAlgorithmToBaseValue(algorithm); |
| + |
| + if (!algorithmDict) { |
| + 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
|
| + } else { |
| + scoped_ptr<content::V8ValueConverter> converter( |
| + content::V8ValueConverter::create()); |
| + call_info.GetReturnValue().Set( |
| + converter->ToV8Value(algorithmDict.get(), context()->v8_context())); |
| + } |
| +} |
| + |
| +} // namespace extensions |