EME test page application.
[chromium-blink-merge.git] / chrome / browser / chromeos / settings / owner_key_util.h
blob8522db76346475fb627a48a15da967d8f567aa9e
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.
5 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_OWNER_KEY_UTIL_H_
6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_OWNER_KEY_UTIL_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/files/file_path.h"
14 #include "base/gtest_prod_util.h"
15 #include "base/memory/ref_counted.h"
16 #include "net/cert/x509_util_nss.h"
18 namespace base {
19 class FilePath;
22 namespace crypto {
23 class RSAPrivateKey;
26 namespace chromeos {
28 class OwnerKeyUtilTest;
30 class OwnerKeyUtil : public base::RefCountedThreadSafe<OwnerKeyUtil> {
31 public:
32 // Creates an OwnerKeyUtil instance.
33 static OwnerKeyUtil* Create();
35 // Attempts to read the public key from the file system.
36 // Upon success, returns true and populates |output|. False on failure.
37 virtual bool ImportPublicKey(std::vector<uint8>* output) = 0;
39 // Looks for the private key associated with |key| in the default slot,
40 // and returns it if it can be found. Returns NULL otherwise.
41 // Caller takes ownership.
43 // TODO (ygorshenin@): this function is deprecated and should be
44 // removed, see crbug.com/372316.
45 virtual crypto::RSAPrivateKey* FindPrivateKey(
46 const std::vector<uint8>& key) = 0;
48 // Looks for the private key associated with |key| in the |slot|
49 // and returns it if it can be found. Returns NULL otherwise.
50 // Caller takes ownership.
51 virtual crypto::RSAPrivateKey* FindPrivateKeyInSlot(
52 const std::vector<uint8>& key,
53 PK11SlotInfo* slot) = 0;
55 // Checks whether the public key is present in the file system.
56 virtual bool IsPublicKeyPresent() = 0;
58 protected:
59 OwnerKeyUtil();
60 virtual ~OwnerKeyUtil();
62 private:
63 friend class base::RefCountedThreadSafe<OwnerKeyUtil>;
65 FRIEND_TEST_ALL_PREFIXES(OwnerKeyUtilTest, ExportImportPublicKey);
68 // Implementation of OwnerKeyUtil that is used in production code.
69 class OwnerKeyUtilImpl : public OwnerKeyUtil {
70 public:
71 explicit OwnerKeyUtilImpl(const base::FilePath& public_key_file);
73 // OwnerKeyUtil:
74 virtual bool ImportPublicKey(std::vector<uint8>* output) OVERRIDE;
75 virtual crypto::RSAPrivateKey* FindPrivateKey(
76 const std::vector<uint8>& key) OVERRIDE;
77 virtual crypto::RSAPrivateKey* FindPrivateKeyInSlot(
78 const std::vector<uint8>& key,
79 PK11SlotInfo* slot) OVERRIDE;
80 virtual bool IsPublicKeyPresent() OVERRIDE;
82 protected:
83 virtual ~OwnerKeyUtilImpl();
85 private:
86 // The file that holds the public key.
87 base::FilePath key_file_;
89 DISALLOW_COPY_AND_ASSIGN(OwnerKeyUtilImpl);
92 } // namespace chromeos
94 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_OWNER_KEY_UTIL_H_