Chromium Code Reviews| Index: chrome/browser/chromeos/login/owner_key_util.h |
| diff --git a/chrome/browser/chromeos/login/owner_key_util.h b/chrome/browser/chromeos/login/owner_key_util.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cd07174639a971319a1883aff289ff687010c881 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/login/owner_key_util.h |
| @@ -0,0 +1,102 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_KEY_UTIL_H_ |
| +#define CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_KEY_UTIL_H_ |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/compiler_specific.h" |
| +#include "base/file_path.h" |
| +#include "base/gtest_prod_util.h" |
| +#include "base/memory/ref_counted.h" |
| + |
| +class FilePath; |
| + |
| +namespace crypto { |
| +class RSAPrivateKey; |
| +} |
| + |
| +namespace chromeos { |
| + |
| +class OwnerKeyUtilTest; |
| + |
| +class OwnerKeyUtil : public base::RefCounted<OwnerKeyUtil> { |
| + public: |
| + // Creates an OwnerKeyUtil instance. |
| + static OwnerKeyUtil* Create(); |
| + |
| + // Attempts to read the public key from the file system. |
| + // Upon success, returns true and populates |output|. False on failure. |
| + virtual bool ImportPublicKey(std::vector<uint8>* output) = 0; |
| + |
| + // Verfiy that |signature| is a SHA1-with-RSA signature over |data| with |
|
pastarmovj
2012/07/30 12:19:19
fix Verify
Mattias Nissler (ping if slow)
2012/07/31 13:02:15
Done.
|
| + // |public_key|. Returns true if so, false on bad signature or other error. |
| + virtual bool Verify(const std::string& data, |
| + const std::vector<uint8> signature, |
| + const std::vector<uint8> public_key); |
| + |
| + // Sign |data| with |key| using Sha1 with RSA. If successful, return true |
| + // and populate |OUT_signature|. |
| + virtual bool Sign(const std::string& data, |
| + std::vector<uint8>* OUT_signature, |
| + crypto::RSAPrivateKey* key); |
| + |
| + // Looks for the private key associated with |key| in the default slot, |
| + // and returns it if it can be found. Returns NULL otherwise. |
| + // Caller takes ownership. |
| + virtual crypto::RSAPrivateKey* FindPrivateKey( |
| + const std::vector<uint8>& key) = 0; |
| + |
| + // Checks whether the public key is present in the file system. |
| + virtual bool IsPublicKeyPresent() = 0; |
| + |
| + protected: |
| + OwnerKeyUtil(); |
| + virtual ~OwnerKeyUtil(); |
| + |
| + // DER encodes public half of |pair| and writes it to the file system. |
| + // The blob on disk is a DER-encoded X509 SubjectPublicKeyInfo object. |
| + // Returns false on error. |
| + virtual bool ExportPublicKey(crypto::RSAPrivateKey* pair) = 0; |
| + |
| + private: |
| + friend class base::RefCounted<OwnerKeyUtil>; |
| + |
| + FRIEND_TEST_ALL_PREFIXES(OwnerKeyUtilTest, ExportImportPublicKey); |
| +}; |
| + |
| +// Implementation of OwnerKeyUtil that is used in production code. |
| +class OwnerKeyUtilImpl : public OwnerKeyUtil { |
| + public: |
| + // The file outside the owner's encrypted home directory where her |
| + // key will live. |
| + static const char kOwnerKeyFile[]; |
| + |
| + explicit OwnerKeyUtilImpl(const FilePath& public_key_file); |
| + |
| + // OwnerKeyUtil: |
| + virtual bool ImportPublicKey(std::vector<uint8>* output) OVERRIDE; |
| + virtual crypto::RSAPrivateKey* FindPrivateKey( |
| + const std::vector<uint8>& key) OVERRIDE; |
| + virtual bool IsPublicKeyPresent() OVERRIDE; |
| + |
| + protected: |
| + virtual ~OwnerKeyUtilImpl(); |
| + |
| + // OwnerKeyUtil: |
| + virtual bool ExportPublicKey(crypto::RSAPrivateKey* pair) OVERRIDE; |
| + |
| + private: |
| + // The file that holds the public key. |
| + FilePath key_file_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(OwnerKeyUtilImpl); |
| +}; |
| + |
| +} // namespace chromeos |
| + |
| +#endif // CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_KEY_UTIL_H_ |