OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_UI_CRYPTO_MODULE_DELEGATE_NSS_H_ | 5 #ifndef CHROME_BROWSER_UI_CRYPTO_MODULE_DELEGATE_NSS_H_ |
6 #define CHROME_BROWSER_UI_CRYPTO_MODULE_DELEGATE_NSS_H_ | 6 #define CHROME_BROWSER_UI_CRYPTO_MODULE_DELEGATE_NSS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
12 #include "chrome/browser/ui/crypto_module_password_dialog.h" | 12 #include "chrome/browser/ui/crypto_module_password_dialog.h" |
| 13 #include "components/cert_database/public/cert_database_service_io_part.h" |
13 #include "crypto/nss_crypto_module_delegate.h" | 14 #include "crypto/nss_crypto_module_delegate.h" |
14 #include "net/base/host_port_pair.h" | 15 #include "net/base/host_port_pair.h" |
| 16 #include "net/cert/nss_cert_database.h" |
| 17 |
| 18 class CertDatabaseServiceIOPart; |
15 | 19 |
16 namespace content { | 20 namespace content { |
17 class ResourceContext; | 21 class ResourceContext; |
18 } | 22 } |
19 | 23 |
| 24 namespace net { |
| 25 class NSSCertDatabase; |
| 26 } |
| 27 |
20 // Delegate to handle unlocking a slot or indicating which slot to store a key | 28 // Delegate to handle unlocking a slot or indicating which slot to store a key |
21 // in. When passing to NSS functions which take a wincx argument, use the value | 29 // in. When passing to NSS functions which take a wincx argument, use the value |
22 // returned from the wincx() method. | 30 // returned from the wincx() method. |
23 class ChromeNSSCryptoModuleDelegate | 31 class ChromeNSSCryptoModuleDelegate |
24 : public crypto::NSSCryptoModuleDelegate { | 32 : public crypto::NSSCryptoModuleDelegate { |
25 public: | 33 public: |
26 // Create a ChromeNSSCryptoModuleDelegate. |reason| is used to select what | 34 // Create a ChromeNSSCryptoModuleDelegate. |reason| is used to select what |
27 // string to show the user, |server| is displayed to indicate which connection | 35 // string to show the user, |server| is displayed to indicate which connection |
28 // is causing the dialog to appear. | 36 // is causing the dialog to appear. |
29 ChromeNSSCryptoModuleDelegate(chrome::CryptoModulePasswordReason reason, | 37 ChromeNSSCryptoModuleDelegate(chrome::CryptoModulePasswordReason reason, |
30 const net::HostPortPair& server); | 38 const net::HostPortPair& server); |
31 | 39 |
32 virtual ~ChromeNSSCryptoModuleDelegate(); | 40 virtual ~ChromeNSSCryptoModuleDelegate(); |
33 | 41 |
34 // Must be called on IO thread. Returns true if the delegate is ready for use. | 42 // Must be called on IO thread. Returns true if the delegate is ready for use. |
35 // Otherwise, if |initialization_complete_callback| is non-null, the | 43 // Otherwise, if |initialization_complete_callback| is non-null, the |
36 // initialization will proceed asynchronously and the callback will be run | 44 // initialization will proceed asynchronously and the callback will be run |
37 // once the delegate is ready to use. In that case, the caller must ensure the | 45 // once the delegate is ready to use. In that case, the caller must ensure the |
38 // delegate remains alive until the callback is run. | 46 // delegate remains alive until the callback is run. |
39 bool InitializeSlot(content::ResourceContext* context, | 47 bool InitializeSlot(const base::Closure& initialization_complete_callback, |
40 const base::Closure& initialization_complete_callback) | 48 CertDatabaseServiceIOPart* cert_db_io) WARN_UNUSED_RESULT; |
41 WARN_UNUSED_RESULT; | |
42 | 49 |
43 // crypto::NSSCryptoModuleDelegate implementation. | 50 // crypto::NSSCryptoModuleDelegate implementation. |
44 virtual crypto::ScopedPK11Slot RequestSlot() OVERRIDE; | 51 virtual crypto::ScopedPK11Slot RequestSlot() OVERRIDE; |
45 | 52 |
46 // crypto::CryptoModuleBlockingPasswordDelegate implementation. | 53 // crypto::CryptoModuleBlockingPasswordDelegate implementation. |
47 virtual std::string RequestPassword(const std::string& slot_name, | 54 virtual std::string RequestPassword(const std::string& slot_name, |
48 bool retry, | 55 bool retry, |
49 bool* cancelled) OVERRIDE; | 56 bool* cancelled) OVERRIDE; |
50 | 57 |
51 private: | 58 private: |
52 void ShowDialog(const std::string& slot_name, bool retry); | 59 void ShowDialog(const std::string& slot_name, bool retry); |
53 | 60 |
54 void GotPassword(const std::string& password); | 61 void GotPassword(const std::string& password); |
55 | 62 |
56 void DidGetSlot(const base::Closure& callback, crypto::ScopedPK11Slot slot); | 63 void DidGetNSSCertDB(const base::Closure& callback, |
| 64 net::NSSCertDatabase* nss_cert_db); |
57 | 65 |
58 // Parameters displayed in the dialog. | 66 // Parameters displayed in the dialog. |
59 const chrome::CryptoModulePasswordReason reason_; | 67 const chrome::CryptoModulePasswordReason reason_; |
60 net::HostPortPair server_; | 68 net::HostPortPair server_; |
61 | 69 |
62 // Event to block worker thread while waiting for dialog on UI thread. | 70 // Event to block worker thread while waiting for dialog on UI thread. |
63 base::WaitableEvent event_; | 71 base::WaitableEvent event_; |
64 | 72 |
65 // Stores the results from the dialog for access on worker thread. | 73 // Stores the results from the dialog for access on worker thread. |
66 std::string password_; | 74 std::string password_; |
67 bool cancelled_; | 75 bool cancelled_; |
68 | 76 |
69 // The slot which will be returned by RequestSlot. | 77 // The slot which will be returned by RequestSlot. |
70 crypto::ScopedPK11Slot slot_; | 78 crypto::ScopedPK11Slot slot_; |
71 | 79 |
72 DISALLOW_COPY_AND_ASSIGN(ChromeNSSCryptoModuleDelegate); | 80 DISALLOW_COPY_AND_ASSIGN(ChromeNSSCryptoModuleDelegate); |
73 }; | 81 }; |
74 | 82 |
75 // Create a delegate which only handles unlocking slots. | 83 // Create a delegate which only handles unlocking slots. |
76 crypto::CryptoModuleBlockingPasswordDelegate* | 84 crypto::CryptoModuleBlockingPasswordDelegate* |
77 CreateCryptoModuleBlockingPasswordDelegate( | 85 CreateCryptoModuleBlockingPasswordDelegate( |
78 chrome::CryptoModulePasswordReason reason, | 86 chrome::CryptoModulePasswordReason reason, |
79 const net::HostPortPair& server); | 87 const net::HostPortPair& server); |
80 | 88 |
81 #endif // CHROME_BROWSER_UI_CRYPTO_MODULE_DELEGATE_NSS_H_ | 89 #endif // CHROME_BROWSER_UI_CRYPTO_MODULE_DELEGATE_NSS_H_ |
OLD | NEW |