OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/pk11_password_dialog.h" | 5 #include "chrome/browser/ui/crypto_module_password_dialog.h" |
6 | 6 |
7 #include <pk11pub.h> | 7 #include <pk11pub.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "chrome/browser/browser_thread.h" | 10 #include "chrome/browser/browser_thread.h" |
11 #include "net/base/crypto_module.h" | 11 #include "net/base/crypto_module.h" |
12 #include "net/base/x509_certificate.h" | 12 #include "net/base/x509_certificate.h" |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 // Basically an asynchronous implementation of NSS's PK11_DoPassword. | 16 // Basically an asynchronous implementation of NSS's PK11_DoPassword. |
17 // Note: This currently handles only the simple case. See the TODOs in | 17 // Note: This currently handles only the simple case. See the TODOs in |
18 // GotPassword for what is yet unimplemented. | 18 // GotPassword for what is yet unimplemented. |
19 class SlotUnlocker { | 19 class SlotUnlocker { |
20 public: | 20 public: |
21 SlotUnlocker(net::CryptoModule* module, | 21 SlotUnlocker(net::CryptoModule* module, |
22 browser::PK11PasswordReason reason, | 22 browser::CryptoModulePasswordReason reason, |
23 const std::string& host, | 23 const std::string& host, |
24 Callback0::Type* callback); | 24 Callback0::Type* callback); |
25 | 25 |
26 void Start(); | 26 void Start(); |
27 | 27 |
28 private: | 28 private: |
29 void GotPassword(const char* password); | 29 void GotPassword(const char* password); |
30 void Done(); | 30 void Done(); |
31 | 31 |
32 scoped_refptr<net::CryptoModule> module_; | 32 scoped_refptr<net::CryptoModule> module_; |
33 browser::PK11PasswordReason reason_; | 33 browser::CryptoModulePasswordReason reason_; |
34 std::string host_; | 34 std::string host_; |
35 Callback0::Type* callback_; | 35 Callback0::Type* callback_; |
36 PRBool retry_; | 36 PRBool retry_; |
37 }; | 37 }; |
38 | 38 |
39 SlotUnlocker::SlotUnlocker(net::CryptoModule* module, | 39 SlotUnlocker::SlotUnlocker(net::CryptoModule* module, |
40 browser::PK11PasswordReason reason, | 40 browser::CryptoModulePasswordReason reason, |
41 const std::string& host, | 41 const std::string& host, |
42 Callback0::Type* callback) | 42 Callback0::Type* callback) |
43 : module_(module), | 43 : module_(module), |
44 reason_(reason), | 44 reason_(reason), |
45 host_(host), | 45 host_(host), |
46 callback_(callback), | 46 callback_(callback), |
47 retry_(PR_FALSE) { | 47 retry_(PR_FALSE) { |
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
49 } | 49 } |
50 | 50 |
51 void SlotUnlocker::Start() { | 51 void SlotUnlocker::Start() { |
52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
53 | 53 |
54 ShowPK11PasswordDialog( | 54 ShowCryptoModulePasswordDialog( |
55 module_->GetTokenName(), | 55 module_->GetTokenName(), |
56 retry_, | 56 retry_, |
57 reason_, | 57 reason_, |
58 host_, | 58 host_, |
59 NewCallback(this, &SlotUnlocker::GotPassword)); | 59 NewCallback(this, &SlotUnlocker::GotPassword)); |
60 } | 60 } |
61 | 61 |
62 void SlotUnlocker::GotPassword(const char* password) { | 62 void SlotUnlocker::GotPassword(const char* password) { |
63 // TODO(mattm): PK11_DoPassword has something about PK11_Global.verifyPass. | 63 // TODO(mattm): PK11_DoPassword has something about PK11_Global.verifyPass. |
64 // Do we need it? | 64 // Do we need it? |
(...skipping 26 matching lines...) Expand all Loading... |
91 void SlotUnlocker::Done() { | 91 void SlotUnlocker::Done() { |
92 callback_->Run(); | 92 callback_->Run(); |
93 delete this; | 93 delete this; |
94 } | 94 } |
95 | 95 |
96 } // namespace | 96 } // namespace |
97 | 97 |
98 namespace browser { | 98 namespace browser { |
99 | 99 |
100 void UnlockSlotIfNecessary(net::CryptoModule* module, | 100 void UnlockSlotIfNecessary(net::CryptoModule* module, |
101 browser::PK11PasswordReason reason, | 101 browser::CryptoModulePasswordReason reason, |
102 const std::string& host, | 102 const std::string& host, |
103 Callback0::Type* callback) { | 103 Callback0::Type* callback) { |
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
105 // The wincx arg is unused since we don't call PK11_SetIsLoggedInFunc. | 105 // The wincx arg is unused since we don't call PK11_SetIsLoggedInFunc. |
106 if (PK11_NeedLogin(module->os_module_handle()) && | 106 if (PK11_NeedLogin(module->os_module_handle()) && |
107 !PK11_IsLoggedIn(module->os_module_handle(), NULL /* wincx */)) { | 107 !PK11_IsLoggedIn(module->os_module_handle(), NULL /* wincx */)) { |
108 (new SlotUnlocker(module, reason, host, callback))->Start(); | 108 (new SlotUnlocker(module, reason, host, callback))->Start(); |
109 } else { | 109 } else { |
110 callback->Run(); | 110 callback->Run(); |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 void UnlockCertSlotIfNecessary(net::X509Certificate* cert, | 114 void UnlockCertSlotIfNecessary(net::X509Certificate* cert, |
115 browser::PK11PasswordReason reason, | 115 browser::CryptoModulePasswordReason reason, |
116 const std::string& host, | 116 const std::string& host, |
117 Callback0::Type* callback) { | 117 Callback0::Type* callback) { |
118 scoped_refptr<net::CryptoModule> module(net::CryptoModule::CreateFromHandle( | 118 scoped_refptr<net::CryptoModule> module(net::CryptoModule::CreateFromHandle( |
119 cert->os_cert_handle()->slot)); | 119 cert->os_cert_handle()->slot)); |
120 UnlockSlotIfNecessary(module.get(), reason, host, callback); | 120 UnlockSlotIfNecessary(module.get(), reason, host, callback); |
121 } | 121 } |
122 | 122 |
123 } // namespace browser | 123 } // namespace browser |
OLD | NEW |