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" | 9 #include "base/callback.h" |
| 10 #include "components/cert_database/public/cert_database_service_io_part.h" |
10 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "net/cert/nss_cert_database.h" |
11 | 13 |
12 using content::BrowserThread; | 14 using content::BrowserThread; |
13 | 15 |
14 namespace { | 16 namespace { |
15 | 17 |
16 void CreateWithSlot(chrome::CryptoModulePasswordReason reason, | 18 void CreateWithNSSCertDB( |
17 const net::HostPortPair& server, | 19 chrome::CryptoModulePasswordReason reason, |
18 const base::Callback<void( | 20 const net::HostPortPair& server, |
19 scoped_ptr<ChromeNSSCryptoModuleDelegate>)>& callback, | 21 const base::Callback<void(scoped_ptr<ChromeNSSCryptoModuleDelegate>)>& |
20 crypto::ScopedPK11Slot slot) { | 22 callback, |
| 23 net::NSSCertDatabase* nss_cert_db) { |
| 24 crypto::ScopedPK11Slot slot; |
| 25 if (nss_cert_db) |
| 26 slot = nss_cert_db->GetPrivateSlot(); |
21 if (!slot) { | 27 if (!slot) { |
22 callback.Run(scoped_ptr<ChromeNSSCryptoModuleDelegate>()); | 28 callback.Run(scoped_ptr<ChromeNSSCryptoModuleDelegate>()); |
23 return; | 29 return; |
24 } | 30 } |
25 callback.Run(scoped_ptr<ChromeNSSCryptoModuleDelegate>( | 31 callback.Run(scoped_ptr<ChromeNSSCryptoModuleDelegate>( |
26 new ChromeNSSCryptoModuleDelegate(reason, server, slot.Pass()))); | 32 new ChromeNSSCryptoModuleDelegate(reason, server, slot.Pass()))); |
27 } | 33 } |
28 | 34 |
29 } // namespace | 35 } // namespace |
30 | 36 |
31 ChromeNSSCryptoModuleDelegate::ChromeNSSCryptoModuleDelegate( | 37 ChromeNSSCryptoModuleDelegate::ChromeNSSCryptoModuleDelegate( |
32 chrome::CryptoModulePasswordReason reason, | 38 chrome::CryptoModulePasswordReason reason, |
33 const net::HostPortPair& server, | 39 const net::HostPortPair& server, |
34 crypto::ScopedPK11Slot slot) | 40 crypto::ScopedPK11Slot slot) |
35 : reason_(reason), | 41 : reason_(reason), |
36 server_(server), | 42 server_(server), |
37 event_(false, false), | 43 event_(false, false), |
38 cancelled_(false), | 44 cancelled_(false), |
39 slot_(slot.Pass()) { | 45 slot_(slot.Pass()) { |
40 } | 46 } |
41 | 47 |
42 ChromeNSSCryptoModuleDelegate::~ChromeNSSCryptoModuleDelegate() {} | 48 ChromeNSSCryptoModuleDelegate::~ChromeNSSCryptoModuleDelegate() {} |
43 | 49 |
44 // static | 50 // static |
45 void ChromeNSSCryptoModuleDelegate::CreateForResourceContext( | 51 void ChromeNSSCryptoModuleDelegate::CreateForCertDatabase( |
46 chrome::CryptoModulePasswordReason reason, | 52 chrome::CryptoModulePasswordReason reason, |
47 const net::HostPortPair& server, | 53 const net::HostPortPair& server, |
48 content::ResourceContext* context, | 54 cert_database::CertDatabaseServiceIOPart* cert_db_io, |
49 const base::Callback<void(scoped_ptr<ChromeNSSCryptoModuleDelegate>)>& | 55 const base::Callback<void(scoped_ptr<ChromeNSSCryptoModuleDelegate>)>& |
50 callback) { | 56 callback) { |
51 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 57 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
52 DCHECK(!callback.is_null()); | 58 DCHECK(!callback.is_null()); |
53 | 59 |
54 base::Callback<void(crypto::ScopedPK11Slot)> get_slot_callback = | 60 base::Callback<void(net::NSSCertDatabase*)> got_nssdb_callback = |
55 base::Bind(&CreateWithSlot, reason, server, callback); | 61 base::Bind(&CreateWithNSSCertDB, reason, server, callback); |
56 | 62 |
57 crypto::ScopedPK11Slot slot = | 63 net::NSSCertDatabase* nssdb = |
58 GetPrivateNSSKeySlotForResourceContext(context, get_slot_callback); | 64 cert_db_io->GetNSSCertDatabase(got_nssdb_callback); |
59 if (slot) | 65 if (nssdb) |
60 get_slot_callback.Run(slot.Pass()); | 66 got_nssdb_callback.Run(nssdb); |
61 } | 67 } |
62 | 68 |
63 // TODO(mattm): allow choosing which slot to generate and store the key. | 69 // TODO(mattm): allow choosing which slot to generate and store the key. |
64 crypto::ScopedPK11Slot ChromeNSSCryptoModuleDelegate::RequestSlot() { | 70 crypto::ScopedPK11Slot ChromeNSSCryptoModuleDelegate::RequestSlot() { |
65 return slot_.Pass(); | 71 return slot_.Pass(); |
66 } | 72 } |
67 | 73 |
68 std::string ChromeNSSCryptoModuleDelegate::RequestPassword( | 74 std::string ChromeNSSCryptoModuleDelegate::RequestPassword( |
69 const std::string& slot_name, | 75 const std::string& slot_name, |
70 bool retry, | 76 bool retry, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 crypto::CryptoModuleBlockingPasswordDelegate* | 119 crypto::CryptoModuleBlockingPasswordDelegate* |
114 CreateCryptoModuleBlockingPasswordDelegate( | 120 CreateCryptoModuleBlockingPasswordDelegate( |
115 chrome::CryptoModulePasswordReason reason, | 121 chrome::CryptoModulePasswordReason reason, |
116 const net::HostPortPair& server) { | 122 const net::HostPortPair& server) { |
117 // Returns a ChromeNSSCryptoModuleDelegate without Pk11Slot. Since it is only | 123 // Returns a ChromeNSSCryptoModuleDelegate without Pk11Slot. Since it is only |
118 // being used as a CryptoModuleBlockingDialogDelegate, using a slot handle is | 124 // being used as a CryptoModuleBlockingDialogDelegate, using a slot handle is |
119 // unnecessary. | 125 // unnecessary. |
120 return new ChromeNSSCryptoModuleDelegate( | 126 return new ChromeNSSCryptoModuleDelegate( |
121 reason, server, crypto::ScopedPK11Slot()); | 127 reason, server, crypto::ScopedPK11Slot()); |
122 } | 128 } |
OLD | NEW |