| 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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_KEY_UTILS_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_KEY_UTILS_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_KEY_UTILS_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_KEY_UTILS_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "chrome/browser/chromeos/cros/login_library.h" | 14 #include "chrome/browser/chromeos/cros/login_library.h" |
| 15 | 15 |
| 16 class FilePath; | 16 class FilePath; |
| 17 | 17 |
| 18 namespace base { | 18 namespace crypto { |
| 19 class RSAPrivateKey; | 19 class RSAPrivateKey; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace chromeos { | 22 namespace chromeos { |
| 23 | 23 |
| 24 class OwnerKeyUtilsTest; | 24 class OwnerKeyUtilsTest; |
| 25 | 25 |
| 26 class OwnerKeyUtils : public base::RefCounted<OwnerKeyUtils> { | 26 class OwnerKeyUtils : public base::RefCounted<OwnerKeyUtils> { |
| 27 public: | 27 public: |
| 28 class Factory { | 28 class Factory { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 53 // |public_key| | 53 // |public_key| |
| 54 // Returns true if so, false on bad signature or other error. | 54 // Returns true if so, false on bad signature or other error. |
| 55 virtual bool Verify(const std::string& data, | 55 virtual bool Verify(const std::string& data, |
| 56 const std::vector<uint8> signature, | 56 const std::vector<uint8> signature, |
| 57 const std::vector<uint8> public_key) = 0; | 57 const std::vector<uint8> public_key) = 0; |
| 58 | 58 |
| 59 // Sign |data| with |key| using Sha1 with RSA. If successful, return true | 59 // Sign |data| with |key| using Sha1 with RSA. If successful, return true |
| 60 // and populate |OUT_signature|. | 60 // and populate |OUT_signature|. |
| 61 virtual bool Sign(const std::string& data, | 61 virtual bool Sign(const std::string& data, |
| 62 std::vector<uint8>* OUT_signature, | 62 std::vector<uint8>* OUT_signature, |
| 63 base::RSAPrivateKey* key) = 0; | 63 crypto::RSAPrivateKey* key) = 0; |
| 64 | 64 |
| 65 // Looks for the private key associated with |key| in the default slot, | 65 // Looks for the private key associated with |key| in the default slot, |
| 66 // and returns it if it can be found. Returns NULL otherwise. | 66 // and returns it if it can be found. Returns NULL otherwise. |
| 67 // Caller takes ownership. | 67 // Caller takes ownership. |
| 68 virtual base::RSAPrivateKey* FindPrivateKey( | 68 virtual crypto::RSAPrivateKey* FindPrivateKey( |
| 69 const std::vector<uint8>& key) = 0; | 69 const std::vector<uint8>& key) = 0; |
| 70 | 70 |
| 71 virtual FilePath GetOwnerKeyFilePath() = 0; | 71 virtual FilePath GetOwnerKeyFilePath() = 0; |
| 72 | 72 |
| 73 protected: | 73 protected: |
| 74 virtual ~OwnerKeyUtils(); | 74 virtual ~OwnerKeyUtils(); |
| 75 | 75 |
| 76 // DER encodes public half of |pair| and writes it out to |key_file|. | 76 // DER encodes public half of |pair| and writes it out to |key_file|. |
| 77 // The blob on disk is a DER-encoded X509 SubjectPublicKeyInfo object. | 77 // The blob on disk is a DER-encoded X509 SubjectPublicKeyInfo object. |
| 78 // Returns false on error. | 78 // Returns false on error. |
| 79 virtual bool ExportPublicKeyToFile(base::RSAPrivateKey* pair, | 79 virtual bool ExportPublicKeyToFile(crypto::RSAPrivateKey* pair, |
| 80 const FilePath& key_file) = 0; | 80 const FilePath& key_file) = 0; |
| 81 | 81 |
| 82 private: | 82 private: |
| 83 friend class base::RefCounted<OwnerKeyUtils>; | 83 friend class base::RefCounted<OwnerKeyUtils>; |
| 84 static Factory* factory_; | 84 static Factory* factory_; |
| 85 | 85 |
| 86 FRIEND_TEST_ALL_PREFIXES(OwnerKeyUtilsTest, ExportImportPublicKey); | 86 FRIEND_TEST_ALL_PREFIXES(OwnerKeyUtilsTest, ExportImportPublicKey); |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 } // namespace chromeos | 89 } // namespace chromeos |
| 90 | 90 |
| 91 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_KEY_UTILS_H_ | 91 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_KEY_UTILS_H_ |
| OLD | NEW |