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

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: sync to r235279 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/crypto_module_password_dialog.h" 5 #include "chrome/browser/ui/crypto_module_delegate_nss.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "chrome/browser/net/nss_context.h"
11 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 #include "crypto/crypto_module_blocking_password_delegate.h" 12 #include "crypto/nss_crypto_module_delegate.h"
13 #include "grit/generated_resources.h"
14 #include "ui/base/l10n/l10n_util.h"
15 #include "url/gurl.h"
16 13
17 using content::BrowserThread; 14 using content::BrowserThread;
18 15
19 namespace chrome { 16 namespace chrome {
20 17
21 namespace { 18 namespace {
22 19
23 class CryptoModuleBlockingDialogDelegate 20 class ChromeNSSCryptoModuleDelegate
24 : public crypto::CryptoModuleBlockingPasswordDelegate { 21 : public crypto::NSSCryptoModuleDelegate {
25 public: 22 public:
26 CryptoModuleBlockingDialogDelegate(CryptoModulePasswordReason reason, 23 ChromeNSSCryptoModuleDelegate(content::ResourceContext* context,
27 const std::string& server) 24 CryptoModulePasswordReason reason,
25 const std::string& server)
28 : event_(false, false), 26 : event_(false, false),
27 context_(context),
29 reason_(reason), 28 reason_(reason),
30 server_(server), 29 server_(server),
31 cancelled_(false) { 30 cancelled_(false) {}
32 }
33 31
34 virtual ~CryptoModuleBlockingDialogDelegate() { 32 virtual ~ChromeNSSCryptoModuleDelegate() {
35 // Make sure we clear the password in memory. 33 // Make sure we clear the password in memory.
36 password_.replace(0, password_.size(), password_.size(), 0); 34 password_.replace(0, password_.size(), password_.size(), 0);
Ryan Sleevi 2013/11/22 00:03:30 This seems... highly unnecessary. We should eithe
mattm 2013/11/22 00:30:31 Done.
37 } 35 }
38 36
39 // crypto::CryptoModuleBlockingDialogDelegate implementation. 37 // crypto::NSSCryptoModuleDelegate implementation.
38 virtual void Initialize(const base::Closure& callback) OVERRIDE {
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
40
41 content::ResourceContext* context = context_;
42 context_ = NULL;
43 OnPrivateNSSKeySlotForResourceContextReady(
44 context,
45 base::Bind(&ChromeNSSCryptoModuleDelegate::DidGetSlot,
46 // Caller is responsible for keeping us alive.
Ryan Sleevi 2013/11/22 00:03:30 Alive until when? How can the caller know when thi
mattm 2013/11/22 00:30:31 Until we call the callback. I'll update the commen
47 base::Unretained(this),
48 callback));
49 }
50
51 // TODO(mattm): allow choosing which slot to generate and store the key.
52 virtual crypto::ScopedPK11Slot RequestSlot() OVERRIDE {
53 return slot_.Pass();
54 }
55
56 // crypto::CryptoModuleBlockingPasswordDelegate implementation.
40 virtual std::string RequestPassword(const std::string& slot_name, 57 virtual std::string RequestPassword(const std::string& slot_name,
41 bool retry, 58 bool retry,
42 bool* cancelled) OVERRIDE { 59 bool* cancelled) OVERRIDE {
43 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); 60 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
44 DCHECK(!event_.IsSignaled()); 61 DCHECK(!event_.IsSignaled());
45 event_.Reset(); 62 event_.Reset();
46 63
47 if (BrowserThread::PostTask( 64 if (BrowserThread::PostTask(
48 BrowserThread::UI, FROM_HERE, 65 BrowserThread::UI, FROM_HERE,
49 base::Bind(&CryptoModuleBlockingDialogDelegate::ShowDialog, 66 base::Bind(&ChromeNSSCryptoModuleDelegate::ShowDialog,
50 // We block on event_ until the task completes, so 67 // We block on event_ until the task completes, so
51 // there's no need to ref-count. 68 // there's no need to ref-count.
52 base::Unretained(this), 69 base::Unretained(this),
53 slot_name, 70 slot_name,
54 retry))) { 71 retry))) {
55 event_.Wait(); 72 event_.Wait();
56 } 73 }
57 *cancelled = cancelled_; 74 *cancelled = cancelled_;
58 return password_; 75 return password_;
59 } 76 }
60 77
61 private: 78 private:
62 void ShowDialog(const std::string& slot_name, 79 void ShowDialog(const std::string& slot_name,
63 bool retry) { 80 bool retry) {
64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
65 ShowCryptoModulePasswordDialog( 82 ShowCryptoModulePasswordDialog(
66 slot_name, 83 slot_name,
67 retry, 84 retry,
68 reason_, 85 reason_,
69 server_, 86 server_,
70 NULL, // TODO(mattm): Supply parent window. 87 NULL, // TODO(mattm): Supply parent window.
71 base::Bind(&CryptoModuleBlockingDialogDelegate::GotPassword, 88 base::Bind(&ChromeNSSCryptoModuleDelegate::GotPassword,
72 // We block on event_ until the task completes, so 89 // We block on event_ until the task completes, so
73 // there's no need to ref-count. 90 // there's no need to ref-count.
74 base::Unretained(this))); 91 base::Unretained(this)));
75 } 92 }
76 93
77 void GotPassword(const char* password) { 94 void GotPassword(const char* password) {
78 if (password) 95 if (password)
79 password_ = password; 96 password_ = password;
80 else 97 else
81 cancelled_ = true; 98 cancelled_ = true;
82 event_.Signal(); 99 event_.Signal();
83 } 100 }
84 101
102 void DidGetSlot(const base::Closure& callback, crypto::ScopedPK11Slot slot) {
103 slot_ = slot.Pass();
104 callback.Run();
105 }
106
85 base::WaitableEvent event_; 107 base::WaitableEvent event_;
108 content::ResourceContext* context_;
86 CryptoModulePasswordReason reason_; 109 CryptoModulePasswordReason reason_;
87 std::string server_; 110 std::string server_;
88 std::string password_; 111 std::string password_;
112 crypto::ScopedPK11Slot slot_;
89 bool cancelled_; 113 bool cancelled_;
90 114
91 DISALLOW_COPY_AND_ASSIGN(CryptoModuleBlockingDialogDelegate); 115 DISALLOW_COPY_AND_ASSIGN(ChromeNSSCryptoModuleDelegate);
92 }; 116 };
93 117
94 } // namespace 118 } // namespace
95 119
96 crypto::CryptoModuleBlockingPasswordDelegate* 120 crypto::NSSCryptoModuleDelegate* NewNSSCryptoModuleDelegate(
97 NewCryptoModuleBlockingDialogDelegate(CryptoModulePasswordReason reason, 121 content::ResourceContext* context,
98 const std::string& server) { 122 CryptoModulePasswordReason reason,
99 return new CryptoModuleBlockingDialogDelegate(reason, server); 123 const std::string& server) {
124 return new ChromeNSSCryptoModuleDelegate(context, reason, server);
100 } 125 }
101 126
127
102 } // namespace chrome 128 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698