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

Unified Diff: content/browser/net/keygen_handler.cc

Issue 18121007: *WIP* Store NSS slots per profile. Move keygen to chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: certdb: handle GetCertTrust and IsUntrusted, failed attempt to handle SetCertTrust Created 7 years, 1 month 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
« no previous file with comments | « content/browser/net/keygen_handler.h ('k') | content/browser/net/nss_context.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/net/keygen_handler.cc
diff --git a/content/browser/net/keygen_handler.cc b/content/browser/net/keygen_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a5f7b17d6f93b9b514c6b4ff9e1268ac5ffe0ded
--- /dev/null
+++ b/content/browser/net/keygen_handler.cc
@@ -0,0 +1,94 @@
+// Copyright (c) 2013 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 "content/browser/net/keygen_handler.h"
+
+#include "base/bind.h"
+#include "base/task_runner_util.h"
+#include "base/threading/worker_pool.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/content_browser_client.h"
+#include "content/public/browser/resource_context.h"
+#include "content/public/common/content_client.h"
+#include "net/base/keygen_handler.h"
+
+#if defined(USE_NSS)
+#include "content/public/browser/nss_context.h"
+#endif
+
+namespace content {
+
+namespace {
+
+std::string GenerateKeyOnWorkerThread(
+ int key_size_in_bits,
+ const std::string& challenge,
+ const GURL& url
+#if defined(USE_NSS)
+ , crypto::ScopedPK11Slot slot
+#endif
+ ) {
+ // Generate a signed public key and challenge, then send it back.
+ net::KeygenHandler keygen_handler(key_size_in_bits, challenge, url);
+
+#if defined(USE_NSS)
+ // Set slot and attach password delegate so we can authenticate.
+ keygen_handler.set_key_slot(
+ slot.Pass(),
+ GetContentClient()->browser()->GetCryptoPasswordDelegate(url));
+#endif // defined(USE_NSS)
+
+ return keygen_handler.GenKeyAndSignChallenge();
+}
+
+void PostGenerateKeyTask(
+ int key_size_in_bits,
+ const std::string& challenge,
+ const GURL& url,
+ const base::Callback<void(const std::string&)>& callback
+#if defined(USE_NSS)
+ , crypto::ScopedPK11Slot slot
+#endif
+ ) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ VLOG(1) << "Dispatching keygen task to worker pool.";
+ // Dispatch to worker pool, so we do not block the IO thread.
+ if (!base::PostTaskAndReplyWithResult(base::WorkerPool::GetTaskRunner(true),
+ FROM_HERE,
+ base::Bind(GenerateKeyOnWorkerThread,
+ key_size_in_bits,
+ challenge,
+ url
+#if defined(USE_NSS)
+ , base::Passed(&slot)
+#endif
+ ),
+ callback)) {
+ NOTREACHED() << "Failed to dispatch keygen task to worker pool";
+ callback.Run(NULL);
+ }
+}
+
+} // namespace
+
+void GenerateKey(ResourceContext* context,
+ int key_size_in_bits,
+ const std::string& challenge,
+ const GURL& url,
+ const base::Callback<void(const std::string&)>& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+#if defined(USE_NSS)
+ // TODO(mattm): allow choosing which slot to generate and store the key.
+ OnPrivateNSSKeySlotForResourceContextReady(context,
+ base::Bind(&PostGenerateKeyTask,
+ key_size_in_bits,
+ challenge,
+ url,
+ callback));
+#else
+ PostGenerateKeyTask(key_size_in_bits, challenge, url, stores_key, callback);
+#endif
+}
+
+} // namespace content
« no previous file with comments | « content/browser/net/keygen_handler.h ('k') | content/browser/net/nss_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698