| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_OWNER_KEY_UTIL_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_OWNER_KEY_UTIL_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" |
| 13 #include "base/file_path.h" |
| 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/memory/ref_counted.h" |
| 16 |
| 17 class FilePath; |
| 18 |
| 19 namespace crypto { |
| 20 class RSAPrivateKey; |
| 21 } |
| 22 |
| 23 namespace chromeos { |
| 24 |
| 25 class OwnerKeyUtilTest; |
| 26 |
| 27 class OwnerKeyUtil : public base::RefCounted<OwnerKeyUtil> { |
| 28 public: |
| 29 // Creates an OwnerKeyUtil instance. |
| 30 static OwnerKeyUtil* Create(); |
| 31 |
| 32 // Attempts to read the public key from the file system. |
| 33 // Upon success, returns true and populates |output|. False on failure. |
| 34 virtual bool ImportPublicKey(std::vector<uint8>* output) = 0; |
| 35 |
| 36 // Looks for the private key associated with |key| in the default slot, |
| 37 // and returns it if it can be found. Returns NULL otherwise. |
| 38 // Caller takes ownership. |
| 39 virtual crypto::RSAPrivateKey* FindPrivateKey( |
| 40 const std::vector<uint8>& key) = 0; |
| 41 |
| 42 // Checks whether the public key is present in the file system. |
| 43 virtual bool IsPublicKeyPresent() = 0; |
| 44 |
| 45 protected: |
| 46 OwnerKeyUtil(); |
| 47 virtual ~OwnerKeyUtil(); |
| 48 |
| 49 private: |
| 50 friend class base::RefCounted<OwnerKeyUtil>; |
| 51 |
| 52 FRIEND_TEST_ALL_PREFIXES(OwnerKeyUtilTest, ExportImportPublicKey); |
| 53 }; |
| 54 |
| 55 // Implementation of OwnerKeyUtil that is used in production code. |
| 56 class OwnerKeyUtilImpl : public OwnerKeyUtil { |
| 57 public: |
| 58 // The file outside the owner's encrypted home directory where her |
| 59 // key will live. |
| 60 static const char kOwnerKeyFile[]; |
| 61 |
| 62 explicit OwnerKeyUtilImpl(const FilePath& public_key_file); |
| 63 |
| 64 // OwnerKeyUtil: |
| 65 virtual bool ImportPublicKey(std::vector<uint8>* output) OVERRIDE; |
| 66 virtual crypto::RSAPrivateKey* FindPrivateKey( |
| 67 const std::vector<uint8>& key) OVERRIDE; |
| 68 virtual bool IsPublicKeyPresent() OVERRIDE; |
| 69 |
| 70 protected: |
| 71 virtual ~OwnerKeyUtilImpl(); |
| 72 |
| 73 private: |
| 74 // The file that holds the public key. |
| 75 FilePath key_file_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(OwnerKeyUtilImpl); |
| 78 }; |
| 79 |
| 80 } // namespace chromeos |
| 81 |
| 82 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_OWNER_KEY_UTIL_H_ |
| OLD | NEW |