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_
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"
28 class OwnerKeyUtilTest
;
30 class OwnerKeyUtil
: public base::RefCountedThreadSafe
<OwnerKeyUtil
> {
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;
60 virtual ~OwnerKeyUtil();
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
{
71 explicit OwnerKeyUtilImpl(const base::FilePath
& public_key_file
);
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
;
83 virtual ~OwnerKeyUtilImpl();
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_