OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "net/base/keygen_handler.h" | |
6 | |
7 #include <utility> | |
8 | |
9 #include "base/logging.h" | |
10 #include "crypto/nss_crypto_module_delegate.h" | |
11 #include "crypto/nss_util.h" | |
12 #include "crypto/scoped_nss_types.h" | |
13 #include "net/third_party/mozilla_security_manager/nsKeygenHandler.h" | |
14 | |
15 // PSM = Mozilla's Personal Security Manager. | |
16 namespace psm = mozilla_security_manager; | |
17 | |
18 namespace net { | |
19 | |
20 std::string KeygenHandler::GenKeyAndSignChallenge() { | |
21 crypto::EnsureNSSInit(); | |
22 | |
23 crypto::ScopedPK11Slot slot; | |
24 if (crypto_module_delegate_) { | |
25 slot = crypto_module_delegate_->RequestSlot(); | |
26 } else { | |
27 LOG(ERROR) << "Could not get an NSS key slot."; | |
28 return std::string(); | |
29 } | |
30 | |
31 // Authenticate to the token. | |
32 if (SECSuccess != PK11_Authenticate(slot.get(), | |
33 PR_TRUE, | |
34 crypto_module_delegate_->wincx())) { | |
35 LOG(ERROR) << "Could not authenticate to the key slot."; | |
36 return std::string(); | |
37 } | |
38 | |
39 return psm::GenKeyAndSignChallenge(key_size_in_bits_, challenge_, url_, | |
40 slot.get(), stores_key_); | |
41 } | |
42 | |
43 void KeygenHandler::set_crypto_module_delegate( | |
44 std::unique_ptr<crypto::NSSCryptoModuleDelegate> delegate) { | |
45 crypto_module_delegate_ = std::move(delegate); | |
46 } | |
47 | |
48 } // namespace net | |
OLD | NEW |