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

Side by Side Diff: chrome/browser/net/keygen_handler_nss.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: Created 7 years, 5 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 (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 "chrome/browser/net/keygen_handler.h"
6
7 #include "base/logging.h"
8 #include "base/threading/worker_pool.h"
9 #include "chrome/browser/profiles/profile_io_data.h"
10 #include "chrome/browser/ui/crypto_module_password_dialog.h"
11 #include "crypto/crypto_module_blocking_password_delegate.h"
12 #include "crypto/nss_util.h"
13 #include "crypto/nss_util_internal.h"
14 #include "crypto/scoped_nss_types.h"
15 #include "net/base/keygen_handler.h"
16
17 namespace {
18
19 void KeygenOnWorkerThread(
20 int key_size_in_bits,
21 const std::string& challenge,
22 const GURL& url,
23 bool stores_key,
24 crypto::ScopedPK11Slot slot,
25 std::string* result) {
26
27 // XXX simplify this
28 scoped_ptr<crypto::CryptoModuleBlockingPasswordDelegate>
29 crypto_module_password_delegate(
30 chrome::NewCryptoModuleBlockingDialogDelegate(
31 chrome::kCryptoModulePasswordKeygen, url.host()));
32 // Authenticate to the token.
33 if (SECSuccess != PK11_Authenticate(slot.get(), PR_TRUE,
34 crypto_module_password_delegate.get())) {
35 LOG(ERROR) << "Couldn't authenticate to private key slot!";
36 }
37
38 net::KeygenHandler handler(key_size_in_bits, challenge, url);
39 handler.set_stores_key(stores_key);
40 handler.set_key_slot(slot.Pass());
41 *result = handler.GenKeyAndSignChallenge();
42 }
43
44 } // namespace
45
46 namespace chrome {
47
48 void Keygen(content::ResourceContext* context,
49 int key_size_in_bits,
50 const std::string& challenge,
51 const GURL& url,
52 bool stores_key,
53 const base::Callback<void(const std::string*)>& callback) {
54 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
55
56 // Ensure NSS is initialized.
57 //crypto::EnsureNSSInit();
58
59 // TODO(mattm): allow choosing which slot to generate and store the key.
60 crypto::ScopedPK11Slot slot(io_data->GetPrivateNSSKeySlot());
61 if (!slot.get()) {
62 LOG(ERROR) << "Couldn't get private key slot from NSS!";
63 callback.Run(NULL);
64 return;
65 }
66
67 VLOG(1) << "Dispatching keygen task to worker pool.";
68 std::string* result(new std::string());
69 // Dispatch to worker pool, so we do not block the IO thread.
70 if (!base::WorkerPool::PostTaskAndReply(
71 FROM_HERE,
72 base::Bind(&KeygenOnWorkerThread,
73 key_size_in_bits,
74 challenge,
75 url,
76 stores_key,
77 base::Passed(&slot),
78 result),
79 base::Bind(callback, base::Owned(result)),
80 true)) {
81 NOTREACHED() << "Failed to dispatch keygen task to worker pool";
82 callback.Run(NULL);
83 return;
84 }
85 }
86
87 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698