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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/net/keygen_handler.h ('k') | content/browser/net/nss_context.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013 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 "content/browser/net/keygen_handler.h"
6
7 #include "base/bind.h"
8 #include "base/task_runner_util.h"
9 #include "base/threading/worker_pool.h"
10 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/content_browser_client.h"
12 #include "content/public/browser/resource_context.h"
13 #include "content/public/common/content_client.h"
14 #include "net/base/keygen_handler.h"
15
16 #if defined(USE_NSS)
17 #include "content/public/browser/nss_context.h"
18 #endif
19
20 namespace content {
21
22 namespace {
23
24 std::string GenerateKeyOnWorkerThread(
25 int key_size_in_bits,
26 const std::string& challenge,
27 const GURL& url
28 #if defined(USE_NSS)
29 , crypto::ScopedPK11Slot slot
30 #endif
31 ) {
32 // Generate a signed public key and challenge, then send it back.
33 net::KeygenHandler keygen_handler(key_size_in_bits, challenge, url);
34
35 #if defined(USE_NSS)
36 // Set slot and attach password delegate so we can authenticate.
37 keygen_handler.set_key_slot(
38 slot.Pass(),
39 GetContentClient()->browser()->GetCryptoPasswordDelegate(url));
40 #endif // defined(USE_NSS)
41
42 return keygen_handler.GenKeyAndSignChallenge();
43 }
44
45 void PostGenerateKeyTask(
46 int key_size_in_bits,
47 const std::string& challenge,
48 const GURL& url,
49 const base::Callback<void(const std::string&)>& callback
50 #if defined(USE_NSS)
51 , crypto::ScopedPK11Slot slot
52 #endif
53 ) {
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
55 VLOG(1) << "Dispatching keygen task to worker pool.";
56 // Dispatch to worker pool, so we do not block the IO thread.
57 if (!base::PostTaskAndReplyWithResult(base::WorkerPool::GetTaskRunner(true),
58 FROM_HERE,
59 base::Bind(GenerateKeyOnWorkerThread,
60 key_size_in_bits,
61 challenge,
62 url
63 #if defined(USE_NSS)
64 , base::Passed(&slot)
65 #endif
66 ),
67 callback)) {
68 NOTREACHED() << "Failed to dispatch keygen task to worker pool";
69 callback.Run(NULL);
70 }
71 }
72
73 } // namespace
74
75 void GenerateKey(ResourceContext* context,
76 int key_size_in_bits,
77 const std::string& challenge,
78 const GURL& url,
79 const base::Callback<void(const std::string&)>& callback) {
80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
81 #if defined(USE_NSS)
82 // TODO(mattm): allow choosing which slot to generate and store the key.
83 OnPrivateNSSKeySlotForResourceContextReady(context,
84 base::Bind(&PostGenerateKeyTask,
85 key_size_in_bits,
86 challenge,
87 url,
88 callback));
89 #else
90 PostGenerateKeyTask(key_size_in_bits, challenge, url, stores_key, callback);
91 #endif
92 }
93
94 } // namespace content
OLDNEW
« 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