1 page.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 30 Trusted Execution Environment (TEE). Gatekeeper enrolls and verifies passwords 31 via an HMAC with a hardware-backed secret key. Additionally, Gatekeeper 32 throttles consecutive failed verification attempts and must refuse to service 33 requests based on a given timeout and a given number of consecutive failed 34 attempts.</p> 35 36 <p>When users verify their passwords, Gatekeeper uses the TEE-derived shared 37 secret to sign an authentication attestation to 38 send to the <a href="../keystore/index.html">hardware-backed Keystore</a>. That is, a 39 Gatekeeper attestation notifies Keystore that authentication-bound keys (for 40 example, keys that apps have created) can be released for use by apps.</p> 41 42 <h2 id=architecture>Architecture</h2> 43 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 49 to 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 63 header file: <code>system/gatekeeper/include/gatekeeper/gatekeeper.h</code>. This 64 header file includes pure virtual functions for creating and accessing 65 keys, as well as for computing signatures. 66 See <a href="#trusty_and_other_implementations">Trusty and other implementations</a>. 67 </ul> 68 69 <p>As shown in the following diagram, the <code>LockSettingsService</code> makes a request (via 70 Binder) that reaches the <code>gatekeeperd</code> daemon in the Android OS. The <code>gatekeeperd</code> 71 daemon 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 77 participates in reporting device <a href="index.html">authentications</a> to Keystore. 78 The <code>gatekeeperd</code> daemon runs in its own process, separate from the system 79 server.</p> 80 81 <h2 id=hal_implementation>HAL Implementation</h2> 82 83 <p>The <code>gatekeeperd</code> daemon uses the HAL to interact 84 with the <code>gatekeeperd</code> daemon's TEE 85 counterpart for password authentication. The HAL implementation must be able to 86 sign (enroll) and verify blobs. All implementations are expected to adhere to 87 the standard format for the authentication token (AuthToken) generated on each 88 successful password verification. The contents and semantics of the AuthToken 89 are 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 96 as a handle. The returned blob (from a call to <code>enroll</code>) must have the structure 97 shown 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 100 ensure 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 103 at 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 108 environments. It contains an approved implementation of GateKeeper. However, 109 <strong>any TEE OS</strong> can be used for the implementation of Gatekeeper. 110 The TEE <strong>must</strong> have access to a hardware-backed key as well as a secure, 111 monotonic clock <strong>that ticks in suspend</strong>.</p> 112 113 <p>Trusty uses an internal IPC system to communicate a shared secret directly 114 between Keymaster and the Trusty implementation of Gatekeeper ("Trusty 115 Gatekeeper"). This shared secret is used for signing AuthTokens that will be 116 sent to Keystore, providing attestations of password verification. Trusty 117 Gatekeeper requests the key from Keymaster for each use and does not persist 118 or cache the value. Implementations are free to share this secret in any way 119 that does not compromise security.</p> 120 121 <p>The HMAC key, used to enroll and verify passwords, is derived and kept solely 122 in GateKeeper.</p> 123 124 <p>The Android tree provides a generic C++ implementation of GateKeeper, requiring 125 only the addition of device-specific routines to be complete. To implement a 126 TEE Gatekeeper with device-specific code for your TEE, please refer to the 127 functions and comments in the following file:</p> 128 <pre> 129 system/gatekeeper/include/gatekeeper/gatekeeper.h 130 </pre> 131 132 <p>For the TEE GateKeeper, the primary responsibilities of a compliant 133 implementation 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 140 requesting the key through a TEE IPC on demand or maintaining a valid cache of 141 the 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. 147 The User SID has no strong connection to an Android user ID.</p> 148 149 <p>A User SID is generated with a cryptographic 150 PRNG whenever a user enrolls a new password without providing a previous one. 151 This is known as an "untrusted" re-enroll. 152 A "trusted" re-enroll occurs when a user provides a valid, previous password. 153 In this case, the User SID is migrated to the new password handle, 154 conserving the keys that were bound to it. 155 The 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 158 password is enrolled.</p> 159 160 <p>User SIDs are written into the AuthToken returned by the <code>verify</code> 161 function and associated to all authentication-bound Keystore keys. For 162 information about the AuthToken format and Keystore, see 163 <a href="index.html">Authentication</a>. 164 Since an untrusted call to the <code>enroll</code> function 165 will 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 168 OS, 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 173 credential. As shown in the <code>gatekeeper.h</code> 174 file (in <code>hardware/libhardware/include/hardware</code>), 175 the HAL provides for returning a timeout in milliseconds. The timeout 176 informs the client not to call GateKeeper again until after the timeout has 177 elapsed. 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 180 the password verification succeeds, the failure counter should be cleared. This 181 prevents attacks that prevent throttling by disabling the embedded MMC (eMMC) 182 after issuing a <code>verify</code> call. The <code>enroll</code> function also verifies 183 the user password (if provided) and so must be throttled in the same way.</p> 184 185 <p>If supported by the device, it is highly recommended that the failure counter 186 be written to secure storage. If the device does not support 187 file-based encryption, or if secure storage is too slow, implementations may 188 use RPMB directly.</p> 189 190 191 192 193