• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROMEOS_CRYPTOHOME_HOMEDIR_METHODS_H_
6 #define CHROMEOS_CRYPTOHOME_HOMEDIR_METHODS_H_
7 
8 #include <string>
9 
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"
16 
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;
28 
~HomedirMethods()29   virtual ~HomedirMethods() {}
30 
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;
36 
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;
47 
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;
60 
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;
72 
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;
79 
80   // Creates the global HomedirMethods instance.
81   static void Initialize();
82 
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);
88 
89   // Destroys the global HomedirMethods instance if it exists.
90   static void Shutdown();
91 
92   // Returns a pointer to the global HomedirMethods instance.
93   // Initialize() should already have been called.
94   static HomedirMethods* GetInstance();
95 };
96 
97 }  // namespace cryptohome
98 
99 #endif  // CHROMEOS_CRYPTOHOME_HOMEDIR_METHODS_H_
100