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 #include "chrome/browser/ui/crypto_module_delegate_nss.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 "chrome/browser/net/nss_context.h" | |
10 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
11 | 10 |
12 using content::BrowserThread; | 11 using content::BrowserThread; |
13 | 12 |
14 ChromeNSSCryptoModuleDelegate::ChromeNSSCryptoModuleDelegate( | 13 ChromeNSSCryptoModuleDelegate::ChromeNSSCryptoModuleDelegate( |
15 chrome::CryptoModulePasswordReason reason, | 14 chrome::CryptoModulePasswordReason reason, |
16 const net::HostPortPair& server) | 15 const net::HostPortPair& server) |
17 : reason_(reason), | 16 : reason_(reason), |
18 server_(server), | 17 server_(server), |
19 event_(false, false), | 18 event_(false, false), |
20 cancelled_(false) {} | 19 cancelled_(false) {} |
21 | 20 |
22 ChromeNSSCryptoModuleDelegate::~ChromeNSSCryptoModuleDelegate() {} | 21 ChromeNSSCryptoModuleDelegate::~ChromeNSSCryptoModuleDelegate() {} |
23 | 22 |
24 bool ChromeNSSCryptoModuleDelegate::InitializeSlot( | 23 bool ChromeNSSCryptoModuleDelegate::InitializeSlot( |
25 content::ResourceContext* context, | 24 const base::Closure& initialization_complete_callback, |
26 const base::Closure& initialization_complete_callback) { | 25 CertDatabaseServiceIOPart* cert_db_io) { |
27 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 26 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
28 DCHECK(!slot_); | 27 DCHECK(!slot_); |
29 base::Callback<void(crypto::ScopedPK11Slot)> get_slot_callback; | 28 base::Callback<void(net::NSSCertDatabase*)> get_nss_cert_db_callback; |
30 if (!initialization_complete_callback.is_null()) | 29 if (!initialization_complete_callback.is_null()) { |
31 get_slot_callback = base::Bind(&ChromeNSSCryptoModuleDelegate::DidGetSlot, | 30 get_nss_cert_db_callback = |
32 // Caller is responsible for keeping |this| | 31 base::Bind(&ChromeNSSCryptoModuleDelegate::DidGetNSSCertDB, |
33 // alive until the callback is run. | 32 // Caller is responsible for keeping |this| |
34 base::Unretained(this), | 33 // alive until the callback is run. |
35 initialization_complete_callback); | 34 base::Unretained(this), |
| 35 initialization_complete_callback); |
| 36 } |
36 | 37 |
37 slot_ = GetPrivateNSSKeySlotForResourceContext(context, get_slot_callback); | 38 net::NSSCertDatabase* nss_cert_db = |
| 39 cert_db_io->GetNSSCertDatabase(get_nss_cert_db_callback); |
| 40 if (nss_cert_db) |
| 41 slot_ = nss_cert_db->GetPrivateSlot(); |
38 return slot_.get() != NULL; | 42 return slot_.get() != NULL; |
39 } | 43 } |
40 | 44 |
41 // TODO(mattm): allow choosing which slot to generate and store the key. | 45 // TODO(mattm): allow choosing which slot to generate and store the key. |
42 crypto::ScopedPK11Slot ChromeNSSCryptoModuleDelegate::RequestSlot() { | 46 crypto::ScopedPK11Slot ChromeNSSCryptoModuleDelegate::RequestSlot() { |
43 return slot_.Pass(); | 47 return slot_.Pass(); |
44 } | 48 } |
45 | 49 |
46 std::string ChromeNSSCryptoModuleDelegate::RequestPassword( | 50 std::string ChromeNSSCryptoModuleDelegate::RequestPassword( |
47 const std::string& slot_name, | 51 const std::string& slot_name, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } | 85 } |
82 | 86 |
83 void ChromeNSSCryptoModuleDelegate::GotPassword(const std::string& password) { | 87 void ChromeNSSCryptoModuleDelegate::GotPassword(const std::string& password) { |
84 if (!password.empty()) | 88 if (!password.empty()) |
85 password_ = password; | 89 password_ = password; |
86 else | 90 else |
87 cancelled_ = true; | 91 cancelled_ = true; |
88 event_.Signal(); | 92 event_.Signal(); |
89 } | 93 } |
90 | 94 |
91 void ChromeNSSCryptoModuleDelegate::DidGetSlot(const base::Closure& callback, | 95 void ChromeNSSCryptoModuleDelegate::DidGetNSSCertDB( |
92 crypto::ScopedPK11Slot slot) { | 96 const base::Closure& callback, |
| 97 net::NSSCertDatabase* nss_cert_db) { |
93 DCHECK(!slot_); | 98 DCHECK(!slot_); |
94 slot_ = slot.Pass(); | 99 slot_ = nss_cert_db->GetPrivateSlot(); |
95 callback.Run(); | 100 callback.Run(); |
96 } | 101 } |
97 | 102 |
98 crypto::CryptoModuleBlockingPasswordDelegate* | 103 crypto::CryptoModuleBlockingPasswordDelegate* |
99 CreateCryptoModuleBlockingPasswordDelegate( | 104 CreateCryptoModuleBlockingPasswordDelegate( |
100 chrome::CryptoModulePasswordReason reason, | 105 chrome::CryptoModulePasswordReason reason, |
101 const net::HostPortPair& server) { | 106 const net::HostPortPair& server) { |
102 // Returns a ChromeNSSCryptoModuleDelegate without calling InitializeSlot. | 107 // Returns a ChromeNSSCryptoModuleDelegate without calling InitializeSlot. |
103 // Since it is only being used as a CreateCryptoModuleBlockingDialogDelegate, | 108 // Since it is only being used as a CreateCryptoModuleBlockingDialogDelegate, |
104 // initializing the slot handle is unnecessary. | 109 // initializing the slot handle is unnecessary. |
105 return new ChromeNSSCryptoModuleDelegate(reason, server); | 110 return new ChromeNSSCryptoModuleDelegate(reason, server); |
106 } | 111 } |
OLD | NEW |