blob: 9d760bcd2c2a42e202f50410f56a5a4e2f92dc34 [file] [log] [blame]
Bert McMeenb72391e2015-09-22 16:10:54 -07001page.title=Gatekeeper
2@jd:body
3
4<!--
5 Copyright 2015 The Android Open Source Project
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18-->
19<div id="qv-wrapper">
20 <div id="qv">
21 <h2>In this document</h2>
22 <ol id="auto-toc">
23 </ol>
24 </div>
25</div>
26
27<h2 id=overview>Overview</h2>
28
29<p>The Gatekeeper subsystem performs device pattern/password authentication in a
30Trusted Execution Environment (TEE). Gatekeeper enrolls and verifies passwords
31via an HMAC with a hardware-backed secret key. Additionally, Gatekeeper
32throttles consecutive failed verification attempts and must refuse to service
33requests based on a given timeout and a given number of consecutive failed
34attempts.</p>
35
36<p>When users verify their passwords, Gatekeeper uses the TEE-derived shared
37secret to sign an authentication attestation to
38send to <a href="keymaster.html">Keymaster</a>. That is, a
39Gatekeeper attestation notifies Keymaster that authentication-bound keys (for
40example, keys that apps have created) can be released for use by apps.</p>
Bert McMeen3cf26b52015-09-29 11:31:01 -070041
42<h2 id=architecture>Architecture</h2>
Bert McMeenb72391e2015-09-22 16:10:54 -070043
44<p>Gatekeeper involves three main components:</p>
45
46<ul>
47 <li><strong>gatekeeperd (Gatekeeper daemon)</strong>.
48 A C++ binder service containing platform-independent logic and corresponding
49to the <code>GateKeeperService</code> Java interface.
50 <li><strong>Gatekeeper Hardware Abstraction Layer (HAL)</strong>.
51 The HAL interface in <code>hardware/libhardware/include/hardware/gatekeeper.h</code>,
52 and the implementing module.
53 <li><strong>Gatekeeper (TEE)</strong>.
54 The TEE counterpart of <code>gatekeeperd</code>. A TEE-based implementation of Gatekeeper.
55</ul>
56
57<p>To implement Gatekeeper:</p>
58
59<ul>
60 <li>Implement the Gatekeeper HAL, specifically the functions in <code>gatekeeper.h</code>
61 (<code>hardware/libhardware/include/hardware/gatekeeper.h</code>). See <a href="#hal_implementation">HAL Implementation</a>.
62 <li>Implement the TEE-specific Gatekeeper component, in part based on the following
63header file: <code>system/gatekeeper/include/gatekeeper/gatekeeper.h</code>. This
64header file includes pure virtual functions for creating and accessing
65keys, as well as for computing signatures.
66See <a href="#trusty_and_other_implementations">Trusty and other implementations</a>.
67</ul>
68
Bert McMeen3cf26b52015-09-29 11:31:01 -070069<p>As shown in the following diagram, the <code>LockSettingsService</code> makes a request (via
Bert McMeenb72391e2015-09-22 16:10:54 -070070Binder) that reaches the <code>gatekeeperd</code> daemon in the Android OS. The <code>gatekeeperd</code>
71daemon makes a request that reaches its counterpart (Gatekeeper) in the TEE.</p>
72
73<img src="../images/gatekeeper-flow.png" alt="Gatekeeper flow" id="figure1" />
74<p class="img-caption"><strong>Figure 1.</strong> High-level data flow for authentication by GateKeeper</p>
75
76<p>The <code>gatekeeperd</code> daemon gives the Android framework APIs access to the HAL, and
77participates in reporting device <a href="index.html">authentications</a> to Keymaster.
78The <code>gatekeeperd</code> daemon runs in its own process, separate from the system
79server.</p>
80
81<h2 id=hal_implementation>HAL Implementation</h2>
82
83<p>The <code>gatekeeperd</code> daemon uses the HAL to interact
84with the <code>gatekeeperd</code> daemon's TEE
85counterpart for password authentication. The HAL implementation must be able to
86sign (enroll) and verify blobs. All implementations are expected to adhere to
87the standard format for the authentication token (AuthToken) generated on each
88successful password verification. The contents and semantics of the AuthToken
89are described in <a href="index.html">Authentication</a>.</p>
90
91<p>Specifically, an implementation of the <code>gatekeeper.h</code> header file (in the
92<code>hardware/libhardware/include/hardware</code> folder) needs to implement the
93<code>enroll</code> and <code>verify</code> functions.</p>
94
95<p>The <code>enroll</code> function takes a password blob, signs it, and returns the signature
96as a handle. The returned blob (from a call to <code>enroll</code>) must have the structure
97shown in <code>system/gatekeeper/include/gatekeeper/password_handle.h</code>.</p>
98
99<p>The <code>verify</code> function needs to compare the signature produced by the provided password and
100ensure that it matches the enrolled password handle.</p>
101
102<p>The key used to enroll and verify must never change, and should be re-derivable
103at every device boot.</p>
104
105<h2 id=trusty_and_other_implementations>Trusty and other implementations</h2>
106
107<p>The Trusty operating system is Google's open source trusted OS for TEE
108environments. It contains an approved implementation of GateKeeper. However,
109<strong>any TEE OS</strong> can be used for the implementation of Gatekeeper.
110The TEE <strong>must</strong> have access to a hardware-backed key as well as a secure,
111monotonic clock <strong>that ticks in suspend</strong>.</p>
112
113<p>Trusty uses an internal IPC system to communicate a shared secret directly
114between Keymaster and the Trusty implementation of Gatekeeper ("Trusty
115Gatekeeper"). This shared secret is used for signing AuthTokens that will be
116sent to Keymaster, providing attestations of password verification. Trusty
117Gatekeeper requests the key from Keymaster for each use and does not persist
118or cache the value. Implementations are free to share this secret in any way
119that does not compromise security.</p>
120
121<p>The HMAC key, used to enroll and verify passwords, is derived and kept solely
122in GateKeeper.</p>
123
124<p>The Android tree provides a generic C++ implementation of GateKeeper, requiring
125only the addition of device-specific routines to be complete. To implement a
126TEE Gatekeeper with device-specific code for your TEE, please refer to the
127functions and comments in the following file:</p>
128<pre>
129system/gatekeeper/include/gatekeeper/gatekeeper.h
130</pre>
131
132<p>For the TEE GateKeeper, the primary responsibilities of a compliant
133implementation are:</p>
134
135<ul>
136 <li>Adherence to the Gatekeeper HAL
137 <li>Returned AuthTokens must be formatted according to the AuthToken specification
138(described in <a href="index.html">Authentication</a>)
139 <li>The TEE Gatekeeper must be able to share an HMAC key with Keymaster, either by
140requesting the key through a TEE IPC on demand or maintaining a valid cache of
141the value at all times
142</ul>
143
144<h2 id=user_sids>User SIDs</h2>
145
146<p>A User Secure ID (User SID) is the TEE representation of a user.
147The User SID has no strong connection to an Android user ID.</p>
148
149<p>A User SID is generated with a cryptographic
150PRNG whenever a user enrolls a new password without providing a previous one.
151This is known as an "untrusted" re-enroll.
152A "trusted" re-enroll occurs when a user provides a valid, previous password.
153In this case, the User SID is migrated to the new password handle,
154conserving the keys that were bound to it.
155The Android framework does not allow for an "untrusted" re-enroll under regular circumstances.</p>
156
157<p>The User SID is HMAC'ed along with the password in the password handle when the
158password is enrolled.</p>
159
160<p>User SIDs are written into the AuthToken returned by the <code>verify</code>
161function and associated to all authentication-bound Keymaster keys. For
162information about the AuthToken format and Keymaster, see
163<a href="index.html">Authentication</a>.
164Since an untrusted call to the <code>enroll</code> function
165will change the User SID, the call will render the keys bound to that password useless.</p>
166
167<p>Attackers can change the password for the device if they control the Android
168OS, but they will destroy root-protected, sensitive keys in the process.</p>
169
170<h2 id=request_throttling>Request throttling</h2>
171
172<p>GateKeeper must be able to securely throttle brute-force attempts on a user
173credential. As shown in the <code>gatekeeper.h</code>
174file (in <code>hardware/libhardware/include/hardware</code>),
175the HAL provides for returning a timeout in milliseconds. The timeout
176informs the client not to call GateKeeper again until after the timeout has
177elapsed. GateKeeper should not service requests if there is a pending timeout.</p>
178
179<p>GateKeeper must write a failure counter before verifying a user password. If
180the password verification succeeds, the failure counter should be cleared. This
181prevents attacks that prevent throttling by disabling the embedded MMC (eMMC)
182after issuing a <code>verify</code> call. The <code>enroll</code> function also verifies
Bert McMeen3cf26b52015-09-29 11:31:01 -0700183the user password (if provided) and so must be throttled in the same way.</p>
Bert McMeenb72391e2015-09-22 16:10:54 -0700184
185<p>If supported by the device, it is highly recommended that the failure counter
186be written to secure storage. If the device does not support
187file-based encryption, or if secure storage is too slow, implementations may
188use RPMB directly.</p>
189
190
191
192