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

Unified Diff: chrome/renderer/extensions/enterprise_certificates_natives.cc

Issue 214863002: Extension API enterprise.platformKeys. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changed to OO-style API with Token object. Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/extensions/enterprise_certificates_natives.cc
diff --git a/chrome/renderer/extensions/enterprise_certificates_natives.cc b/chrome/renderer/extensions/enterprise_certificates_natives.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8ddbd52f257b165e6f1393c9064fbb5a30be7ba1
--- /dev/null
+++ b/chrome/renderer/extensions/enterprise_certificates_natives.cc
@@ -0,0 +1,97 @@
+// 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_certificates_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/Platform.h"
+#include "third_party/WebKit/public/platform/WebCrypto.h"
+#include "third_party/WebKit/public/platform/WebCryptoKey.h"
+#include "third_party/WebKit/public/web/WebScriptBindings.h"
+#include "v8/include/v8.h"
+
+namespace extensions {
+
+namespace {
+
+void ThrowException(const std::string& error_message, v8::Isolate* isolate) {
+ isolate->ThrowException(v8::Exception::Error(
+ v8::String::NewFromUtf8(isolate, error_message.c_str())));
+}
+
+} // namespace
+
+EnterpriseCertificatesNatives::EnterpriseCertificatesNatives(
+ RequestSender* request_sender,
+ ChromeV8Context* context)
+ : ObjectBackedNativeHandler(context), request_sender_(request_sender) {
+ RouteFunction("ImportNative",
+ base::Bind(&EnterpriseCertificatesNatives::ImportNative,
+ base::Unretained(this)));
+}
+
+void EnterpriseCertificatesNatives::ImportNative(
+ const v8::FunctionCallbackInfo<v8::Value>& info) {
+ v8::Isolate* isolate = info.GetIsolate();
+
+ v8::Local<v8::Array> extension_args = info[1].As<v8::Array>();
+ blink::WebCryptoKey key = blink::WebScriptBindings::toWebCryptoKey(
+ extension_args->Get(0)->ToObject(), isolate);
+
+ if (key.isNull()) {
+ ThrowException("Key is not a valid WebCrypto key.", isolate);
+ return;
+ }
+ if (key.type() != blink::WebCryptoKeyTypePrivate) {
+ ThrowException("Key is not a private key.", isolate);
+ return;
+ }
+ if (!(key.usages() & blink::WebCryptoKeyUsageSign)) {
+ ThrowException("Key usage prohibits signing.", isolate);
+ return;
+ }
+
+ blink::WebVector<unsigned char> key_data;
+ if (!blink::Platform::current()->crypto()->serializeKeyForClone(key,
Ryan Sleevi 2014/04/15 00:15:04 You'll want to add comments about why this is OK ;
+ key_data)) {
+ ThrowException("Key cannot be accessed.", isolate);
+ }
+
+ scoped_ptr<content::V8ValueConverter> converter(
+ content::V8ValueConverter::create());
+ converter->SetFunctionAllowed(false);
+ converter->SetStripNullFromObjects(true);
+
+ base::ListValue internal_args;
+ internal_args.Append(base::BinaryValue::CreateWithCopiedBuffer(
+ (char*)key_data.data(), key_data.size()));
Ryan Sleevi 2014/04/15 00:15:04 C++ casts
+ // Copy over the remaining arguments: certificate, token and callback.
+ for (size_t i = 1; i < extension_args->Length(); ++i) {
+ base::Value* arg =
+ converter->FromV8Value(extension_args->Get(i), context()->v8_context());
+ if (arg)
+ internal_args.Append(arg);
+ else
+ internal_args.Append(base::Value::CreateNullValue());
+ }
+
+ const std::string name =
+ "enterprise.certificatesInternal.importClientCertificateAndRawKey";
+ int request_id = info[2]->Int32Value();
+ bool has_callback = info[3]->BooleanValue();
+
+ LOG(ERROR) << "StartRequest";
+ request_sender_->StartRequest(context(),
+ name,
+ request_id,
+ has_callback,
+ false /* for_io_thread */,
+ &internal_args);
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698