OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #ifndef CHROMEOS_ATTESTATION_ATTESTATION_FLOW_H_ | |
6 #define CHROMEOS_ATTESTATION_ATTESTATION_FLOW_H_ | |
7 | |
8 #include <string> | |
9 | |
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" | |
16 | |
17 namespace cryptohome { | |
18 | |
19 class AsyncMethodCaller; | |
20 | |
21 } // namespace cryptohome | |
22 | |
23 namespace chromeos { | |
24 | |
25 class CryptohomeClient; | |
26 | |
27 namespace attestation { | |
28 | |
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; | |
39 }; | |
40 | |
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; | |
54 | |
55 AttestationFlow(cryptohome::AsyncMethodCaller* async_caller, | |
56 CryptohomeClient* cryptohome_client, | |
57 ServerProxy* server_proxy); | |
58 virtual ~AttestationFlow(); | |
Mattias Nissler (ping if slow)
2013/01/18 13:38:46
drop virtual?
dkrahn
2013/01/22 22:50:11
I want the class to be mock-able and have plans to
| |
59 | |
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. | |
63 // | |
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, | |
Mattias Nissler (ping if slow)
2013/01/18 13:38:46
drop virtual?
| |
73 const CertificateCallback& callback); | |
74 | |
75 private: | |
76 static const char kEnterpriseMachineKey[]; | |
Mattias Nissler (ping if slow)
2013/01/18 13:38:46
could use a comment
dkrahn
2013/01/22 22:50:11
Done.
| |
77 | |
78 // Asynchronously initiates the attestation enrollment flow. | |
79 // | |
80 // Parameters | |
81 // on_failure - Called if any failure occurs. | |
82 // next_task - Called on successful enrollment. | |
83 void StartEnroll(const base::Closure& on_failure, | |
84 const base::Closure& next_task); | |
85 | |
86 // Called when the attestation daemon has finished creating an enrollment | |
87 // request for the Privacy CA. The request is asynchronously forwarded as-is | |
88 // to the PCA. | |
89 // | |
90 // Parameters | |
91 // on_failure - Called if any failure occurs. | |
92 // next_task - Called on successful enrollment. | |
93 // success - The status of request creation. | |
94 // data - The request data for the Privacy CA. | |
95 void SendEnrollRequestToPCA(const base::Closure& on_failure, | |
96 const base::Closure& next_task, | |
97 bool success, | |
98 const std::string& data); | |
99 | |
100 // Called when the Privacy CA responds to an enrollment request. The response | |
101 // is asynchronously forwarded as-is to the attestation daemon in order to | |
102 // complete the enrollment operation. | |
103 // | |
104 // Parameters | |
105 // on_failure - Called if any failure occurs. | |
106 // next_task - Called on successful enrollment. | |
107 // success - The status of the Privacy CA operation. | |
108 // data - The response data from the Privacy CA. | |
109 void OnEnrollResponse(const base::Closure& on_failure, | |
Mattias Nissler (ping if slow)
2013/01/18 13:38:46
Maybe rename to SendEnrollResponseToDaemon?
dkrahn
2013/01/22 22:50:11
Done.
| |
110 const base::Closure& next_task, | |
111 bool success, | |
112 const std::string& data); | |
113 | |
114 // Called when the attestation daemon completes an enrollment operation. If | |
115 // the operation was successful, the next_task callback is called. | |
116 // | |
117 // Parameters | |
118 // on_failure - Called if any failure occurs. | |
119 // next_task - Called on successful enrollment. | |
120 // success - The status of the enrollment operation. | |
121 // not_used - An artifact of the cryptohome D-Bus interface; ignored. | |
122 void OnEnrollComplete(const base::Closure& on_failure, | |
123 const base::Closure& next_task, | |
124 bool success, | |
125 cryptohome::MountError not_used); | |
126 | |
127 // Asynchronously initiates the certificate request flow. Attestation | |
128 // enrollment must complete successfully before this operation can succeed. | |
129 // | |
130 // Parameters | |
131 // name - The name of the key for which a certificate is requested. | |
132 // callback - Called when the operation completes. | |
133 void StartCertificateRequest(const std::string& name, | |
134 const CertificateCallback& callback); | |
135 | |
136 // Called when the attestation daemon has finished creating a certificate | |
137 // request for the Privacy CA. The request is asynchronously forwarded as-is | |
138 // to the PCA. | |
139 // | |
140 // Parameters | |
141 // callback - Called when the operation completes. | |
142 // success - The status of request creation. | |
143 // data - The request data for the Privacy CA. | |
144 void SendCertificateRequestToPCA(const CertificateCallback& callback, | |
145 bool success, | |
146 const std::string& data); | |
147 | |
148 // Called when the Privacy CA responds to a certificate request. The response | |
149 // is asynchronously forwarded as-is to the attestation daemon in order to | |
150 // complete the operation. | |
151 // | |
152 // Parameters | |
153 // callback - Called when the operation completes. | |
154 // success - The status of the Privacy CA operation. | |
155 // data - The response data from the Privacy CA. | |
156 void OnCertificateResponse(const CertificateCallback& callback, | |
Mattias Nissler (ping if slow)
2013/01/18 13:38:46
Maybe rename to SendCertificateResponseToDaemon?
dkrahn
2013/01/22 22:50:11
Done.
| |
157 bool success, | |
158 const std::string& data); | |
159 | |
160 base::WeakPtrFactory<AttestationFlow> weak_factory_; | |
161 cryptohome::AsyncMethodCaller* async_caller_; | |
162 CryptohomeClient* cryptohome_client_; | |
163 ServerProxy* server_proxy_; | |
164 | |
165 DISALLOW_COPY_AND_ASSIGN(AttestationFlow); | |
166 }; | |
167 | |
168 } // namespace attestation | |
169 } // namespace chromeos | |
170 | |
171 #endif // CHROMEOS_ATTESTATION_ATTESTATION_FLOW_H_ | |
OLD | NEW |