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