| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "crypto/nss_crypto_module_delegate.h" | 8 #include "crypto/nss_crypto_module_delegate.h" |
| 9 #include "crypto/nss_util.h" | 9 #include "crypto/nss_util.h" |
| 10 #include "crypto/nss_util_internal.h" | |
| 11 #include "crypto/scoped_nss_types.h" | |
| 12 #include "net/third_party/mozilla_security_manager/nsKeygenHandler.h" | 10 #include "net/third_party/mozilla_security_manager/nsKeygenHandler.h" |
| 13 | 11 |
| 14 // PSM = Mozilla's Personal Security Manager. | 12 // PSM = Mozilla's Personal Security Manager. |
| 15 namespace psm = mozilla_security_manager; | 13 namespace psm = mozilla_security_manager; |
| 16 | 14 |
| 17 namespace net { | 15 namespace net { |
| 18 | 16 |
| 19 std::string KeygenHandler::GenKeyAndSignChallenge() { | 17 std::string KeygenHandler::GenKeyAndSignChallenge() { |
| 20 // Ensure NSS is initialized. | |
| 21 crypto::EnsureNSSInit(); | 18 crypto::EnsureNSSInit(); |
| 22 | 19 |
| 23 crypto::ScopedPK11Slot slot; | 20 if (!slot_) { |
| 24 if (crypto_module_delegate_) | 21 LOG(ERROR) << "No slot set."; |
| 25 slot = crypto_module_delegate_->RequestSlot().Pass(); | |
| 26 else | |
| 27 slot.reset(crypto::GetPersistentNSSKeySlot()); | |
| 28 if (!slot.get()) { | |
| 29 LOG(ERROR) << "Couldn't get private key slot from NSS!"; | |
| 30 return std::string(); | 22 return std::string(); |
| 31 } | 23 } |
| 32 | 24 |
| 33 // Authenticate to the token. | 25 // Authenticate to the token. |
| 34 if (SECSuccess != | 26 if (SECSuccess != |
| 35 PK11_Authenticate( | 27 PK11_Authenticate( |
| 36 slot.get(), | 28 slot_.get(), |
| 37 PR_TRUE, | 29 PR_TRUE, |
| 38 crypto_module_delegate_ ? crypto_module_delegate_->wincx() : NULL)) { | 30 crypto_module_delegate_ ? crypto_module_delegate_->wincx() : NULL)) { |
| 39 LOG(ERROR) << "Couldn't authenticate to private key slot!"; | 31 LOG(ERROR) << "Couldn't authenticate to private key slot!"; |
| 40 return std::string(); | 32 return std::string(); |
| 41 } | 33 } |
| 42 | 34 |
| 43 return psm::GenKeyAndSignChallenge(key_size_in_bits_, challenge_, url_, | 35 return psm::GenKeyAndSignChallenge( |
| 44 slot.get(), stores_key_); | 36 key_size_in_bits_, challenge_, url_, slot_.get(), stores_key_); |
| 37 } |
| 38 |
| 39 void KeygenHandler::set_key_slot(PK11SlotInfo* slot) { |
| 40 slot_.reset(PK11_ReferenceSlot(slot)); |
| 45 } | 41 } |
| 46 | 42 |
| 47 void KeygenHandler::set_crypto_module_delegate( | 43 void KeygenHandler::set_crypto_module_delegate( |
| 48 scoped_ptr<crypto::NSSCryptoModuleDelegate> delegate) { | 44 scoped_ptr<crypto::CryptoModuleBlockingPasswordDelegate> delegate) { |
| 49 crypto_module_delegate_ = delegate.Pass(); | 45 crypto_module_delegate_ = delegate.Pass(); |
| 50 } | 46 } |
| 51 | 47 |
| 52 } // namespace net | 48 } // namespace net |
| OLD | NEW |