OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "net/base/keygen_handler.h" | 5 #include "net/base/keygen_handler.h" |
6 | 6 |
| 7 #include "base/crypto/scoped_nss_types.h" |
| 8 #include "base/logging.h" |
| 9 #include "base/nss_util.h" |
| 10 #include "base/nss_util_internal.h" |
7 #include "net/third_party/mozilla_security_manager/nsKeygenHandler.h" | 11 #include "net/third_party/mozilla_security_manager/nsKeygenHandler.h" |
8 | 12 |
9 // PSM = Mozilla's Personal Security Manager. | 13 // PSM = Mozilla's Personal Security Manager. |
10 namespace psm = mozilla_security_manager; | 14 namespace psm = mozilla_security_manager; |
11 | 15 |
12 namespace net { | 16 namespace net { |
13 | 17 |
14 std::string KeygenHandler::GenKeyAndSignChallenge() { | 18 std::string KeygenHandler::GenKeyAndSignChallenge() { |
| 19 // Ensure NSS is initialized. |
| 20 base::EnsureNSSInit(); |
| 21 |
| 22 base::ScopedPK11Slot slot(base::GetDefaultNSSKeySlot()); |
| 23 if (!slot.get()) { |
| 24 LOG(ERROR) << "Couldn't get Internal key slot!"; |
| 25 return std::string(); |
| 26 } |
| 27 |
| 28 // Authenticate to the token. |
| 29 if (SECSuccess != PK11_Authenticate(slot.get(), PR_TRUE, |
| 30 pk11_password_delegate_.get())) { |
| 31 LOG(ERROR) << "Couldn't authenticate to PK11 token!"; |
| 32 return std::string(); |
| 33 } |
| 34 |
15 return psm::GenKeyAndSignChallenge(key_size_in_bits_, challenge_, url_, | 35 return psm::GenKeyAndSignChallenge(key_size_in_bits_, challenge_, url_, |
16 stores_key_); | 36 slot.get(), stores_key_); |
| 37 } |
| 38 |
| 39 void KeygenHandler::set_pk11_password_delegate( |
| 40 base::PK11BlockingPasswordDelegate* delegate) { |
| 41 pk11_password_delegate_.reset(delegate); |
17 } | 42 } |
18 | 43 |
19 } // namespace net | 44 } // namespace net |
OLD | NEW |