| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/ownership/mock_owner_key_util.h" | 5 #include "components/ownership/mock_owner_key_util.h" |
| 6 | 6 |
| 7 #include <pk11pub.h> | 7 #include <pk11pub.h> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "crypto/nss_key_util.h" | 11 #include "crypto/nss_key_util.h" |
| 12 #include "crypto/nss_util.h" | 12 #include "crypto/nss_util.h" |
| 13 #include "crypto/rsa_private_key.h" | 13 #include "crypto/rsa_private_key.h" |
| 14 | 14 |
| 15 namespace ownership { | 15 namespace ownership { |
| 16 | 16 |
| 17 MockOwnerKeyUtil::MockOwnerKeyUtil() { | 17 MockOwnerKeyUtil::MockOwnerKeyUtil() { |
| 18 } | 18 } |
| 19 | 19 |
| 20 MockOwnerKeyUtil::~MockOwnerKeyUtil() { | 20 MockOwnerKeyUtil::~MockOwnerKeyUtil() { |
| 21 } | 21 } |
| 22 | 22 |
| 23 bool MockOwnerKeyUtil::ImportPublicKey(std::vector<uint8>* output) { | 23 bool MockOwnerKeyUtil::ImportPublicKey(std::vector<uint8_t>* output) { |
| 24 *output = public_key_; | 24 *output = public_key_; |
| 25 return !public_key_.empty(); | 25 return !public_key_.empty(); |
| 26 } | 26 } |
| 27 | 27 |
| 28 crypto::ScopedSECKEYPrivateKey MockOwnerKeyUtil::FindPrivateKeyInSlot( | 28 crypto::ScopedSECKEYPrivateKey MockOwnerKeyUtil::FindPrivateKeyInSlot( |
| 29 const std::vector<uint8>& key, | 29 const std::vector<uint8_t>& key, |
| 30 PK11SlotInfo* slot) { | 30 PK11SlotInfo* slot) { |
| 31 if (!private_key_) | 31 if (!private_key_) |
| 32 return nullptr; | 32 return nullptr; |
| 33 return crypto::ScopedSECKEYPrivateKey( | 33 return crypto::ScopedSECKEYPrivateKey( |
| 34 SECKEY_CopyPrivateKey(private_key_.get())); | 34 SECKEY_CopyPrivateKey(private_key_.get())); |
| 35 } | 35 } |
| 36 | 36 |
| 37 bool MockOwnerKeyUtil::IsPublicKeyPresent() { | 37 bool MockOwnerKeyUtil::IsPublicKeyPresent() { |
| 38 return !public_key_.empty(); | 38 return !public_key_.empty(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void MockOwnerKeyUtil::Clear() { | 41 void MockOwnerKeyUtil::Clear() { |
| 42 public_key_.clear(); | 42 public_key_.clear(); |
| 43 private_key_.reset(); | 43 private_key_.reset(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void MockOwnerKeyUtil::SetPublicKey(const std::vector<uint8>& key) { | 46 void MockOwnerKeyUtil::SetPublicKey(const std::vector<uint8_t>& key) { |
| 47 public_key_ = key; | 47 public_key_ = key; |
| 48 } | 48 } |
| 49 | 49 |
| 50 void MockOwnerKeyUtil::SetPublicKeyFromPrivateKey( | 50 void MockOwnerKeyUtil::SetPublicKeyFromPrivateKey( |
| 51 const crypto::RSAPrivateKey& key) { | 51 const crypto::RSAPrivateKey& key) { |
| 52 CHECK(key.ExportPublicKey(&public_key_)); | 52 CHECK(key.ExportPublicKey(&public_key_)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void MockOwnerKeyUtil::SetPrivateKey(scoped_ptr<crypto::RSAPrivateKey> key) { | 55 void MockOwnerKeyUtil::SetPrivateKey(scoped_ptr<crypto::RSAPrivateKey> key) { |
| 56 crypto::EnsureNSSInit(); | 56 crypto::EnsureNSSInit(); |
| 57 | 57 |
| 58 CHECK(key->ExportPublicKey(&public_key_)); | 58 CHECK(key->ExportPublicKey(&public_key_)); |
| 59 | 59 |
| 60 std::vector<uint8_t> key_exported; | 60 std::vector<uint8_t> key_exported; |
| 61 CHECK(key->ExportPrivateKey(&key_exported)); | 61 CHECK(key->ExportPrivateKey(&key_exported)); |
| 62 | 62 |
| 63 crypto::ScopedPK11Slot slot(PK11_GetInternalSlot()); | 63 crypto::ScopedPK11Slot slot(PK11_GetInternalSlot()); |
| 64 CHECK(slot); | 64 CHECK(slot); |
| 65 private_key_ = crypto::ImportNSSKeyFromPrivateKeyInfo( | 65 private_key_ = crypto::ImportNSSKeyFromPrivateKeyInfo( |
| 66 slot.get(), key_exported, false /* not permanent */); | 66 slot.get(), key_exported, false /* not permanent */); |
| 67 CHECK(private_key_); | 67 CHECK(private_key_); |
| 68 } | 68 } |
| 69 | 69 |
| 70 } // namespace ownership | 70 } // namespace ownership |
| OLD | NEW |