Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / chromeos / attestation / attestation_flow.h
blob572be93b1c196f1ff4211cdbed3553cbea8c27ae
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 CHROMEOS_ATTESTATION_ATTESTATION_FLOW_H_
6 #define CHROMEOS_ATTESTATION_ATTESTATION_FLOW_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/callback_forward.h"
12 #include "base/memory/weak_ptr.h"
13 #include "chromeos/chromeos_export.h"
14 #include "chromeos/dbus/dbus_method_call_status.h"
15 #include "third_party/cros_system_api/dbus/service_constants.h"
17 namespace cryptohome {
19 class AsyncMethodCaller;
21 } // namespace cryptohome
23 namespace chromeos {
25 class CryptohomeClient;
27 namespace attestation {
29 // Interface for access to the Privacy CA server.
30 class CHROMEOS_EXPORT ServerProxy {
31 public:
32 typedef base::Callback<void(bool success,
33 const std::string& data)> DataCallback;
34 virtual ~ServerProxy() {}
35 virtual void SendEnrollRequest(const std::string& request,
36 const DataCallback& on_response) = 0;
37 virtual void SendCertificateRequest(const std::string& request,
38 const DataCallback& on_response) = 0;
41 // Implements the message flow for Chrome OS attestation tasks. Generally this
42 // consists of coordinating messages between the Chrome OS attestation service
43 // and the Privacy CA server. Sample usage:
44 // AttestationFlow flow(AsyncMethodCaller::GetInstance(),
45 // DBusThreadManager::Get().GetCryptohomeClient(),
46 // my_server_proxy);
47 // CertificateCallback callback = base::Bind(&MyCallback);
48 // flow.GetCertificate("attest-ent-machine", callback);
49 class CHROMEOS_EXPORT AttestationFlow {
50 public:
51 typedef base::Callback<void(bool success,
52 const std::string& pem_certificate_chain)>
53 CertificateCallback;
55 AttestationFlow(cryptohome::AsyncMethodCaller* async_caller,
56 CryptohomeClient* cryptohome_client,
57 ServerProxy* server_proxy);
58 virtual ~AttestationFlow();
60 // Asynchronously gets an attestation certificate bound to the given name.
61 // If no certificate has been associated with the name, a new certificate is
62 // issued.
64 // Parameters
65 // name - The name of the key for which to retrieve a certificate. The
66 // following key names are available:
67 // "attest-ent-machine" - The enterprise machine key.
68 // "attest-ent-user" - An enterprise user key for the current user.
69 // "content-[origin]" - A content protection key bound to a
70 // specific origin for the current user.
71 // callback - A callback which will be called when the operation completes.
72 virtual void GetCertificate(const std::string& name,
73 const CertificateCallback& callback);
75 private:
76 // The key name defined for the special-purpose Enterprise Machine Key.
77 static const char kEnterpriseMachineKey[];
79 // Asynchronously initiates the attestation enrollment flow.
81 // Parameters
82 // on_failure - Called if any failure occurs.
83 // next_task - Called on successful enrollment.
84 void StartEnroll(const base::Closure& on_failure,
85 const base::Closure& next_task);
87 // Called when the attestation daemon has finished creating an enrollment
88 // request for the Privacy CA. The request is asynchronously forwarded as-is
89 // to the PCA.
91 // Parameters
92 // on_failure - Called if any failure occurs.
93 // next_task - Called on successful enrollment.
94 // success - The status of request creation.
95 // data - The request data for the Privacy CA.
96 void SendEnrollRequestToPCA(const base::Closure& on_failure,
97 const base::Closure& next_task,
98 bool success,
99 const std::string& data);
101 // Called when the Privacy CA responds to an enrollment request. The response
102 // is asynchronously forwarded as-is to the attestation daemon in order to
103 // complete the enrollment operation.
105 // Parameters
106 // on_failure - Called if any failure occurs.
107 // next_task - Called on successful enrollment.
108 // success - The status of the Privacy CA operation.
109 // data - The response data from the Privacy CA.
110 void SendEnrollResponseToDaemon(const base::Closure& on_failure,
111 const base::Closure& next_task,
112 bool success,
113 const std::string& data);
115 // Called when the attestation daemon completes an enrollment operation. If
116 // the operation was successful, the next_task callback is called.
118 // Parameters
119 // on_failure - Called if any failure occurs.
120 // next_task - Called on successful enrollment.
121 // success - The status of the enrollment operation.
122 // not_used - An artifact of the cryptohome D-Bus interface; ignored.
123 void OnEnrollComplete(const base::Closure& on_failure,
124 const base::Closure& next_task,
125 bool success,
126 cryptohome::MountError not_used);
128 // Asynchronously initiates the certificate request flow. Attestation
129 // enrollment must complete successfully before this operation can succeed.
131 // Parameters
132 // name - The name of the key for which a certificate is requested.
133 // callback - Called when the operation completes.
134 void StartCertificateRequest(const std::string& name,
135 const CertificateCallback& callback);
137 // Called when the attestation daemon has finished creating a certificate
138 // request for the Privacy CA. The request is asynchronously forwarded as-is
139 // to the PCA.
141 // Parameters
142 // name - The name of the key for which a certificate is requested.
143 // callback - Called when the operation completes.
144 // success - The status of request creation.
145 // data - The request data for the Privacy CA.
146 void SendCertificateRequestToPCA(const std::string& name,
147 const CertificateCallback& callback,
148 bool success,
149 const std::string& data);
151 // Called when the Privacy CA responds to a certificate request. The response
152 // is asynchronously forwarded as-is to the attestation daemon in order to
153 // complete the operation.
155 // Parameters
156 // name - The name of the key for which a certificate is requested.
157 // callback - Called when the operation completes.
158 // success - The status of the Privacy CA operation.
159 // data - The response data from the Privacy CA.
160 void SendCertificateResponseToDaemon(const std::string& name,
161 const CertificateCallback& callback,
162 bool success,
163 const std::string& data);
165 base::WeakPtrFactory<AttestationFlow> weak_factory_;
166 cryptohome::AsyncMethodCaller* async_caller_;
167 CryptohomeClient* cryptohome_client_;
168 ServerProxy* server_proxy_;
170 DISALLOW_COPY_AND_ASSIGN(AttestationFlow);
173 } // namespace attestation
174 } // namespace chromeos
176 #endif // CHROMEOS_ATTESTATION_ATTESTATION_FLOW_H_