Roll BoringSSL.
[chromium-blink-merge.git] / chromeos / cryptohome / homedir_methods.h
blob0276f1b7a16f493d15633b3c88e70fa194f2f455
1 // Copyright 2014 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 CHROMEOS_CRYPTOHOME_HOMEDIR_METHODS_H_
6 #define CHROMEOS_CRYPTOHOME_HOMEDIR_METHODS_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/callback_forward.h"
12 #include "chromeos/chromeos_export.h"
13 #include "chromeos/cryptohome/cryptohome_parameters.h"
14 #include "chromeos/dbus/cryptohome_client.h"
15 #include "third_party/cros_system_api/dbus/service_constants.h"
17 namespace cryptohome {
18 // This class manages calls to Cryptohome service's home directory methods:
19 // Mount, CheckKey, Add/UpdateKey.
20 class CHROMEOS_EXPORT HomedirMethods {
21 public:
22 // A callback type which is called back on the UI thread when the results of
23 // method calls are ready.
24 typedef base::Callback<void(bool success, MountError return_code)> Callback;
25 typedef base::Callback<
26 void(bool success, MountError return_code, const std::string& mount_hash)>
27 MountCallback;
29 virtual ~HomedirMethods() {}
31 // Asks cryptohomed to attempt authorization for user identified by |id| using
32 // |auth|. This can be used to unlock a user session.
33 virtual void CheckKeyEx(const Identification& id,
34 const Authorization& auth,
35 const Callback& callback) = 0;
37 // Asks cryptohomed to find the cryptohome for user identified by |id| and
38 // then mount it using |auth| to unlock the key.
39 // If the |create_keys| are not given and no cryptohome exists for |id|,
40 // the expected result is
41 // callback.Run(false, kCryptohomeMountErrorUserDoesNotExist, string()).
42 // Otherwise, the normal range of return codes is expected.
43 virtual void MountEx(const Identification& id,
44 const Authorization& auth,
45 const MountParameters& request,
46 const MountCallback& callback) = 0;
48 // Asks cryptohomed to try to add another |key| for user identified by |id|
49 // using |auth| to unlock the key.
50 // |clobber_if_exist| governs action if key with same label already exists for
51 // this user. if |true| old key will be replaced, if |false| old key will be
52 // preserved.
53 // Key used in |auth| should have PRIV_ADD privilege.
54 // |callback| will be called with status info on completion.
55 virtual void AddKeyEx(const Identification& id,
56 const Authorization& auth,
57 const KeyDefinition& key,
58 bool clobber_if_exist,
59 const Callback& callback) = 0;
61 // Asks cryptohomed to update |key| for user identified by |id| using |auth|
62 // to unlock the key.
63 // Label for |auth| and |key| have to be the same.
64 // Key used in |auth| should have PRIV_AUTHORIZED_UPDATE privilege.
65 // |signature| is used by cryptohome to verify the authentity of new key.
66 // |callback| will be called with status info on completion.
67 virtual void UpdateKeyEx(const Identification& id,
68 const Authorization& auth,
69 const KeyDefinition& key,
70 const std::string& signature,
71 const Callback& callback) = 0;
73 // Asks cryptohomed to remove specific key labeled with |label| for user
74 // identified by |id| using |auth|.
75 virtual void RemoveKeyEx(const Identification& id,
76 const Authorization& auth,
77 const std::string& label,
78 const Callback& callback) = 0;
80 // Creates the global HomedirMethods instance.
81 static void Initialize();
83 // Similar to Initialize(), but can inject an alternative
84 // HomedirMethods such as MockHomedirMethods for testing.
85 // The injected object will be owned by the internal pointer and deleted
86 // by Shutdown().
87 static void InitializeForTesting(HomedirMethods* homedir_methods);
89 // Destroys the global HomedirMethods instance if it exists.
90 static void Shutdown();
92 // Returns a pointer to the global HomedirMethods instance.
93 // Initialize() should already have been called.
94 static HomedirMethods* GetInstance();
97 } // namespace cryptohome
99 #endif // CHROMEOS_CRYPTOHOME_HOMEDIR_METHODS_H_