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

Side by Side Diff: chrome/browser/ui/crypto_module_delegate_nss.cc

Issue 61643007: Update keygen to use correct NSS slot on ChromeOS multiprofile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sky review changes Created 7 years 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) 2012 The Chromium Authors. All rights reserved.
sky 2013/12/11 14:20:42 2013?
mattm 2013/12/11 23:12:09 Done.
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/ui/crypto_module_delegate_nss.h"
6
7 #include "base/basictypes.h"
8 #include "base/bind.h"
9 #include "chrome/browser/net/nss_context.h"
10 #include "content/public/browser/browser_thread.h"
11
12 using content::BrowserThread;
13
14 ChromeNSSCryptoModuleDelegate::ChromeNSSCryptoModuleDelegate(
15 chrome::CryptoModulePasswordReason reason,
16 const std::string& server)
17 : reason_(reason),
18 server_(server),
19 event_(false, false),
20 cancelled_(false) {}
21
22 ChromeNSSCryptoModuleDelegate::~ChromeNSSCryptoModuleDelegate() {}
23
24 bool ChromeNSSCryptoModuleDelegate::InitializeSlot(
25 content::ResourceContext* context,
26 const base::Closure& initialization_complete_callback) {
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
28 base::Callback<void(crypto::ScopedPK11Slot)> get_slot_callback;
29 if (!initialization_complete_callback.is_null())
30 get_slot_callback = base::Bind(&ChromeNSSCryptoModuleDelegate::DidGetSlot,
31 base::Unretained(this),
sky 2013/12/11 14:20:42 How do you know its safe to use unretained here?
mattm 2013/12/11 23:12:09 It depends on the caller keeping it alive (ex by h
32 initialization_complete_callback);
33
34 slot_ = GetPrivateNSSKeySlotForResourceContext(context, get_slot_callback);
35 return slot_.get() != NULL;
36 }
37
38 // TODO(mattm): allow choosing which slot to generate and store the key.
39 crypto::ScopedPK11Slot ChromeNSSCryptoModuleDelegate::RequestSlot() {
40 return slot_.Pass();
41 }
42
43 std::string ChromeNSSCryptoModuleDelegate::RequestPassword(
44 const std::string& slot_name,
45 bool retry,
46 bool* cancelled) {
47 DCHECK(!event_.IsSignaled());
48 event_.Reset();
49
50 if (BrowserThread::PostTask(
sky 2013/12/11 14:20:42 What thread is this wrong on that is safe to block
mattm 2013/12/11 23:12:09 It is run on a WorkerPool thread.
sky 2013/12/12 00:25:13 Is it possible to convert from blocking to a callb
mattm 2013/12/12 00:28:57 Unfortunately not. NSS only supports doing a block
51 BrowserThread::UI,
52 FROM_HERE,
53 base::Bind(&ChromeNSSCryptoModuleDelegate::ShowDialog,
54 // This method blocks on |event_| until the task completes,
55 // so there's no need to ref-count.
56 base::Unretained(this),
57 slot_name,
58 retry))) {
59 event_.Wait();
60 }
61 *cancelled = cancelled_;
62 return password_;
63 }
64
65 void ChromeNSSCryptoModuleDelegate::ShowDialog(const std::string& slot_name,
66 bool retry) {
67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
68 ShowCryptoModulePasswordDialog(
69 slot_name,
70 retry,
71 reason_,
72 server_,
73 NULL, // TODO(mattm): Supply parent window.
74 base::Bind(&ChromeNSSCryptoModuleDelegate::GotPassword,
75 // RequestPassword is blocked on |event_| until GotPassword is
76 // called, so there's no need to ref-count.
77 base::Unretained(this)));
78 }
79
80 void ChromeNSSCryptoModuleDelegate::GotPassword(const char* password) {
sky 2013/12/11 14:20:42 Can this be a std::string so that I don't have to
mattm 2013/12/11 23:12:09 Done.
81 if (password)
82 password_ = password;
83 else
84 cancelled_ = true;
85 event_.Signal();
86 }
87
88 void ChromeNSSCryptoModuleDelegate::DidGetSlot(const base::Closure& callback,
89 crypto::ScopedPK11Slot slot) {
90 slot_ = slot.Pass();
91 callback.Run();
92 }
93
94 crypto::CryptoModuleBlockingPasswordDelegate*
95 CreateCryptoModuleBlockingPasswordDelegate(
96 chrome::CryptoModulePasswordReason reason,
97 const std::string& server) {
98 // Returns a ChromeNSSCryptoModuleDelegate without calling InitializeSlot.
99 // Since it is only being used as a CreateCryptoModuleBlockingDialogDelegate,
100 // initializing the slot handle is unnecessary.
101 return new ChromeNSSCryptoModuleDelegate(reason, server);
102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698