| 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 "chrome/browser/chromeos/settings/owner_key_util.h" | 5 #include "components/ownership/owner_key_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "crypto/rsa_private_key.h" | |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 17 |
| 19 namespace chromeos { | 18 namespace ownership { |
| 20 | 19 |
| 21 // 2048-bit RSA public key for testing. | 20 // 2048-bit RSA public key for testing. |
| 22 const uint8 kTestKeyData[] = { | 21 const uint8 kTestKeyData[] = { |
| 23 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, | 22 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, |
| 24 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, | 23 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, |
| 25 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xe8, 0x39, 0x11, | 24 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xe8, 0x39, 0x11, |
| 26 0xd0, 0x98, 0x52, 0x4f, 0xf7, 0x18, 0xd1, 0xbf, 0x98, 0x06, 0xae, 0x7a, | 25 0xd0, 0x98, 0x52, 0x4f, 0xf7, 0x18, 0xd1, 0xbf, 0x98, 0x06, 0xae, 0x7a, |
| 27 0x7c, 0xd7, 0x6f, 0x02, 0x54, 0x37, 0x4e, 0xcd, 0xa6, 0x27, 0x8e, 0xf7, | 26 0x7c, 0xd7, 0x6f, 0x02, 0x54, 0x37, 0x4e, 0xcd, 0xa6, 0x27, 0x8e, 0xf7, |
| 28 0x82, 0x1d, 0xde, 0x3d, 0xf5, 0x6b, 0xa4, 0xe5, 0x6b, 0x0c, 0xf0, 0x39, | 27 0x82, 0x1d, 0xde, 0x3d, 0xf5, 0x6b, 0xa4, 0xe5, 0x6b, 0x0c, 0xf0, 0x39, |
| 29 0xe5, 0xd9, 0x53, 0xe7, 0x6b, 0x6d, 0xa1, 0xc7, 0xdf, 0x92, 0xb7, 0xb0, | 28 0xe5, 0xd9, 0x53, 0xe7, 0x6b, 0x6d, 0xa1, 0xc7, 0xdf, 0x92, 0xb7, 0xb0, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 47 0x41, 0x02, 0x03, 0x01, 0x00, 0x01, | 46 0x41, 0x02, 0x03, 0x01, 0x00, 0x01, |
| 48 }; | 47 }; |
| 49 | 48 |
| 50 class OwnerKeyUtilTest : public testing::Test { | 49 class OwnerKeyUtilTest : public testing::Test { |
| 51 protected: | 50 protected: |
| 52 OwnerKeyUtilTest() {} | 51 OwnerKeyUtilTest() {} |
| 53 virtual ~OwnerKeyUtilTest() {} | 52 virtual ~OwnerKeyUtilTest() {} |
| 54 | 53 |
| 55 virtual void SetUp() OVERRIDE { | 54 virtual void SetUp() OVERRIDE { |
| 56 ASSERT_TRUE(tmpdir_.CreateUniqueTempDir()); | 55 ASSERT_TRUE(tmpdir_.CreateUniqueTempDir()); |
| 57 key_file_ = tmpdir_.path().Append("key"); | 56 key_file_ = tmpdir_.path().Append(FILE_PATH_LITERAL("key")); |
| 58 util_ = new OwnerKeyUtilImpl(key_file_); | 57 util_ = new OwnerKeyUtil(key_file_); |
| 59 } | 58 } |
| 60 | 59 |
| 61 base::ScopedTempDir tmpdir_; | 60 base::ScopedTempDir tmpdir_; |
| 62 base::FilePath key_file_; | 61 base::FilePath key_file_; |
| 63 scoped_refptr<OwnerKeyUtil> util_; | 62 scoped_refptr<OwnerKeyUtil> util_; |
| 64 | 63 |
| 65 private: | 64 private: |
| 66 DISALLOW_COPY_AND_ASSIGN(OwnerKeyUtilTest); | 65 DISALLOW_COPY_AND_ASSIGN(OwnerKeyUtilTest); |
| 67 }; | 66 }; |
| 68 | 67 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 90 EXPECT_FALSE(util_->ImportPublicKey(&from_disk)); | 89 EXPECT_FALSE(util_->ImportPublicKey(&from_disk)); |
| 91 | 90 |
| 92 // Next try empty file. This should fail and the array should be empty. | 91 // Next try empty file. This should fail and the array should be empty. |
| 93 from_disk.resize(10); | 92 from_disk.resize(10); |
| 94 ASSERT_EQ(0, base::WriteFile(key_file_, "", 0)); | 93 ASSERT_EQ(0, base::WriteFile(key_file_, "", 0)); |
| 95 EXPECT_TRUE(util_->IsPublicKeyPresent()); | 94 EXPECT_TRUE(util_->IsPublicKeyPresent()); |
| 96 EXPECT_FALSE(util_->ImportPublicKey(&from_disk)); | 95 EXPECT_FALSE(util_->ImportPublicKey(&from_disk)); |
| 97 EXPECT_FALSE(from_disk.size()); | 96 EXPECT_FALSE(from_disk.size()); |
| 98 } | 97 } |
| 99 | 98 |
| 100 } // namespace chromeos | 99 } // namespace ownership |
| OLD | NEW |