OLD | NEW |
1 // Copyright (c) 2011 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/crypto_module_password_dialog.h" | 5 #include "chrome/browser/ui/crypto_module_password_dialog_nss.h" |
6 | 6 |
7 #include <pk11pub.h> | 7 #include <pk11pub.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
12 #include "net/base/crypto_module.h" | 12 #include "net/base/crypto_module.h" |
13 #include "net/cert/x509_certificate.h" | 13 #include "net/cert/x509_certificate.h" |
14 | 14 |
15 using content::BrowserThread; | 15 using content::BrowserThread; |
(...skipping 13 matching lines...) Expand all Loading... |
29 public: | 29 public: |
30 SlotUnlocker(const net::CryptoModuleList& modules, | 30 SlotUnlocker(const net::CryptoModuleList& modules, |
31 chrome::CryptoModulePasswordReason reason, | 31 chrome::CryptoModulePasswordReason reason, |
32 const std::string& host, | 32 const std::string& host, |
33 gfx::NativeWindow parent, | 33 gfx::NativeWindow parent, |
34 const base::Closure& callback); | 34 const base::Closure& callback); |
35 | 35 |
36 void Start(); | 36 void Start(); |
37 | 37 |
38 private: | 38 private: |
39 void GotPassword(const char* password); | 39 void GotPassword(const std::string& password); |
40 void Done(); | 40 void Done(); |
41 | 41 |
42 size_t current_; | 42 size_t current_; |
43 net::CryptoModuleList modules_; | 43 net::CryptoModuleList modules_; |
44 chrome::CryptoModulePasswordReason reason_; | 44 chrome::CryptoModulePasswordReason reason_; |
45 std::string host_; | 45 std::string host_; |
46 gfx::NativeWindow parent_; | 46 gfx::NativeWindow parent_; |
47 base::Closure callback_; | 47 base::Closure callback_; |
48 PRBool retry_; | 48 PRBool retry_; |
49 }; | 49 }; |
(...skipping 24 matching lines...) Expand all Loading... |
74 reason_, | 74 reason_, |
75 host_, | 75 host_, |
76 parent_, | 76 parent_, |
77 base::Bind(&SlotUnlocker::GotPassword, base::Unretained(this))); | 77 base::Bind(&SlotUnlocker::GotPassword, base::Unretained(this))); |
78 return; | 78 return; |
79 } | 79 } |
80 } | 80 } |
81 Done(); | 81 Done(); |
82 } | 82 } |
83 | 83 |
84 void SlotUnlocker::GotPassword(const char* password) { | 84 void SlotUnlocker::GotPassword(const std::string& password) { |
85 // TODO(mattm): PK11_DoPassword has something about PK11_Global.verifyPass. | 85 // TODO(mattm): PK11_DoPassword has something about PK11_Global.verifyPass. |
86 // Do we need it? | 86 // Do we need it? |
87 // http://mxr.mozilla.org/mozilla/source/security/nss/lib/pk11wrap/pk11auth.c#
577 | 87 // http://mxr.mozilla.org/mozilla/source/security/nss/lib/pk11wrap/pk11auth.c#
577 |
88 | 88 |
89 if (!password) { | 89 if (password.empty()) { |
90 // User cancelled entering password. Oh well. | 90 // User cancelled entering password. Oh well. |
91 ++current_; | 91 ++current_; |
92 Start(); | 92 Start(); |
93 return; | 93 return; |
94 } | 94 } |
95 | 95 |
96 // TODO(mattm): handle protectedAuthPath | 96 // TODO(mattm): handle protectedAuthPath |
97 SECStatus rv = PK11_CheckUserPassword(modules_[current_]->os_module_handle(), | 97 SECStatus rv = PK11_CheckUserPassword(modules_[current_]->os_module_handle(), |
98 password); | 98 password.c_str()); |
99 if (rv == SECWouldBlock) { | 99 if (rv == SECWouldBlock) { |
100 // Incorrect password. Try again. | 100 // Incorrect password. Try again. |
101 retry_ = PR_TRUE; | 101 retry_ = PR_TRUE; |
102 Start(); | 102 Start(); |
103 return; | 103 return; |
104 } | 104 } |
105 | 105 |
106 // TODO(mattm): PK11_DoPassword calls nssTrustDomain_UpdateCachedTokenCerts on | 106 // TODO(mattm): PK11_DoPassword calls nssTrustDomain_UpdateCachedTokenCerts on |
107 // non-friendly slots. How important is that? | 107 // non-friendly slots. How important is that? |
108 | 108 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 const std::string& host, | 142 const std::string& host, |
143 gfx::NativeWindow parent, | 143 gfx::NativeWindow parent, |
144 const base::Closure& callback) { | 144 const base::Closure& callback) { |
145 net::CryptoModuleList modules; | 145 net::CryptoModuleList modules; |
146 modules.push_back(net::CryptoModule::CreateFromHandle( | 146 modules.push_back(net::CryptoModule::CreateFromHandle( |
147 cert->os_cert_handle()->slot)); | 147 cert->os_cert_handle()->slot)); |
148 UnlockSlotsIfNecessary(modules, reason, host, parent, callback); | 148 UnlockSlotsIfNecessary(modules, reason, host, parent, callback); |
149 } | 149 } |
150 | 150 |
151 } // namespace chrome | 151 } // namespace chrome |
OLD | NEW |