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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "chrome/browser/net/nss_context.h" | 10 #include "chrome/browser/net/nss_context.h" |
11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
12 | 12 |
13 using content::BrowserThread; | 13 using content::BrowserThread; |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 void CreateWithSlot( | 17 void CreateWithSlot( |
18 chrome::CryptoModulePasswordReason reason, | 18 chrome::CryptoModulePasswordReason reason, |
19 const net::HostPortPair& server, | 19 const net::HostPortPair& server, |
20 const base::Callback<void(std::unique_ptr<ChromeNSSCryptoModuleDelegate>)>& | 20 const base::Callback<void(scoped_refptr<ChromeNSSCryptoModuleDelegate>)>& |
21 callback, | 21 callback, |
22 crypto::ScopedPK11Slot slot) { | 22 crypto::ScopedPK11Slot slot) { |
23 if (!slot) { | 23 if (!slot) { |
24 callback.Run(std::unique_ptr<ChromeNSSCryptoModuleDelegate>()); | 24 callback.Run(nullptr); |
25 return; | 25 return; |
26 } | 26 } |
27 callback.Run(std::unique_ptr<ChromeNSSCryptoModuleDelegate>( | 27 callback.Run(base::MakeRefCounted<ChromeNSSCryptoModuleDelegate>( |
28 new ChromeNSSCryptoModuleDelegate(reason, server, std::move(slot)))); | 28 reason, server, std::move(slot))); |
29 } | 29 } |
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 ChromeNSSCryptoModuleDelegate::ChromeNSSCryptoModuleDelegate( | 33 ChromeNSSCryptoModuleDelegate::ChromeNSSCryptoModuleDelegate( |
34 chrome::CryptoModulePasswordReason reason, | 34 chrome::CryptoModulePasswordReason reason, |
35 const net::HostPortPair& server, | 35 const net::HostPortPair& server, |
36 crypto::ScopedPK11Slot slot) | 36 crypto::ScopedPK11Slot slot) |
37 : reason_(reason), | 37 : reason_(reason), |
38 server_(server), | 38 server_(server), |
39 event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 39 event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
40 base::WaitableEvent::InitialState::NOT_SIGNALED), | 40 base::WaitableEvent::InitialState::NOT_SIGNALED), |
41 cancelled_(false), | 41 cancelled_(false), |
42 slot_(std::move(slot)) {} | 42 slot_(std::move(slot)) {} |
43 | 43 |
44 ChromeNSSCryptoModuleDelegate::~ChromeNSSCryptoModuleDelegate() {} | 44 ChromeNSSCryptoModuleDelegate::~ChromeNSSCryptoModuleDelegate() {} |
45 | 45 |
46 // static | 46 // static |
47 void ChromeNSSCryptoModuleDelegate::CreateForResourceContext( | 47 void ChromeNSSCryptoModuleDelegate::CreateForResourceContext( |
48 chrome::CryptoModulePasswordReason reason, | 48 chrome::CryptoModulePasswordReason reason, |
49 const net::HostPortPair& server, | 49 const net::HostPortPair& server, |
50 content::ResourceContext* context, | 50 content::ResourceContext* context, |
51 const base::Callback<void(std::unique_ptr<ChromeNSSCryptoModuleDelegate>)>& | 51 const base::Callback<void(scoped_refptr<ChromeNSSCryptoModuleDelegate>)>& |
52 callback) { | 52 callback) { |
53 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 53 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
54 DCHECK(!callback.is_null()); | 54 DCHECK(!callback.is_null()); |
55 | 55 |
56 base::Callback<void(crypto::ScopedPK11Slot)> get_slot_callback = | 56 base::Callback<void(crypto::ScopedPK11Slot)> get_slot_callback = |
57 base::Bind(&CreateWithSlot, reason, server, callback); | 57 base::Bind(&CreateWithSlot, reason, server, callback); |
58 | 58 |
59 crypto::ScopedPK11Slot slot = | 59 crypto::ScopedPK11Slot slot = |
60 GetPrivateNSSKeySlotForResourceContext(context, get_slot_callback); | 60 GetPrivateNSSKeySlotForResourceContext(context, get_slot_callback); |
61 if (slot) | 61 if (slot) |
62 get_slot_callback.Run(std::move(slot)); | 62 get_slot_callback.Run(std::move(slot)); |
63 } | 63 } |
64 | 64 |
65 // TODO(mattm): allow choosing which slot to generate and store the key. | 65 // TODO(mattm): allow choosing which slot to generate and store the key. |
66 crypto::ScopedPK11Slot ChromeNSSCryptoModuleDelegate::RequestSlot() { | 66 crypto::ScopedPK11Slot ChromeNSSCryptoModuleDelegate::RequestSlot() { |
davidben
2017/06/07 23:06:17
BTW, this slot was only used for <keygen> which is
mattm
2017/06/08 21:47:56
Acknowledged.
| |
67 return std::move(slot_); | 67 return std::move(slot_); |
68 } | 68 } |
69 | 69 |
70 std::string ChromeNSSCryptoModuleDelegate::RequestPassword( | 70 std::string ChromeNSSCryptoModuleDelegate::RequestPassword( |
71 const std::string& slot_name, | 71 const std::string& slot_name, |
72 bool retry, | 72 bool retry, |
73 bool* cancelled) { | 73 bool* cancelled) { |
74 DCHECK(!event_.IsSignaled()); | 74 DCHECK(!event_.IsSignaled()); |
75 event_.Reset(); | 75 event_.Reset(); |
76 | 76 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 crypto::CryptoModuleBlockingPasswordDelegate* | 113 crypto::CryptoModuleBlockingPasswordDelegate* |
114 CreateCryptoModuleBlockingPasswordDelegate( | 114 CreateCryptoModuleBlockingPasswordDelegate( |
115 chrome::CryptoModulePasswordReason reason, | 115 chrome::CryptoModulePasswordReason reason, |
116 const net::HostPortPair& server) { | 116 const net::HostPortPair& server) { |
117 // Returns a ChromeNSSCryptoModuleDelegate without Pk11Slot. Since it is only | 117 // Returns a ChromeNSSCryptoModuleDelegate without Pk11Slot. Since it is only |
118 // being used as a CryptoModuleBlockingDialogDelegate, using a slot handle is | 118 // being used as a CryptoModuleBlockingDialogDelegate, using a slot handle is |
119 // unnecessary. | 119 // unnecessary. |
120 return new ChromeNSSCryptoModuleDelegate( | 120 return new ChromeNSSCryptoModuleDelegate( |
121 reason, server, crypto::ScopedPK11Slot()); | 121 reason, server, crypto::ScopedPK11Slot()); |
122 } | 122 } |
OLD | NEW |