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="{@docRoot}security/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>). 62 See <a href="#hal_implementation">HAL Implementation</a>. 63 <li>Implement the TEE-specific Gatekeeper component, in part based on the following 64 header file: <code>system/gatekeeper/include/gatekeeper/gatekeeper.h</code>. This 65 header file includes pure virtual functions for creating and accessing 66 keys, as well as for computing signatures. 67 See <a href="#trusty_and_other_implementations">Trusty and other implementations</a>. 68 </ul> 69 70 <p>As shown in the following diagram, the <code>LockSettingsService</code> makes a request (via 71 Binder) that reaches the <code>gatekeeperd</code> daemon in the Android OS. 72 The <code>gatekeeperd</code> 73 daemon makes a request that reaches its counterpart (Gatekeeper) in the TEE.</p> 74 75 <img src="../images/gatekeeper-flow.png" alt="Gatekeeper flow" id="figure1" /> 76 <p class="img-caption"><strong>Figure 1.</strong> High-level data flow for authentication by GateKeeper</p> 77 78 <p>The <code>gatekeeperd</code> daemon gives the Android framework APIs access to the HAL, and 79 participates in reporting device <a href="index.html">authentications</a> to Keystore. 80 The <code>gatekeeperd</code> daemon runs in its own process, separate from the system 81 server.</p> 82 83 <h2 id=hal_implementation>HAL Implementation</h2> 84 85 <p>The <code>gatekeeperd</code> daemon uses the HAL to interact 86 with the <code>gatekeeperd</code> daemon's TEE 87 counterpart for password authentication. The HAL implementation must be able to 88 sign (enroll) and verify blobs. All implementations are expected to adhere to 89 the standard format for the authentication token (AuthToken) generated on each 90 successful password verification. The contents and semantics of the AuthToken 91 are described in <a href="index.html">Authentication</a>.</p> 92 93 <p>Specifically, an implementation of the <code>gatekeeper.h</code> header file (in the 94 <code>hardware/libhardware/include/hardware</code> folder) needs to implement the 95 <code>enroll</code> and <code>verify</code> functions.</p> 96 97 <p>The <code>enroll</code> function takes a password blob, signs it, and returns the signature 98 as a handle. The returned blob (from a call to <code>enroll</code>) must have the structure 99 shown in <code>system/gatekeeper/include/gatekeeper/password_handle.h</code>.</p> 100 101 <p>The <code>verify</code> function needs to compare the signature produced 102 by the provided password and 103 ensure that it matches the enrolled password handle.</p> 104 105 <p>The key used to enroll and verify must never change, and should be re-derivable 106 at every device boot.</p> 107 108 <h2 id=trusty_and_other_implementations>Trusty and other implementations</h2> 109 110 <p>The <a href="{@docRoot}security/trusty/index.html">Trusty</a> operating system is 111 Google's open source trusted OS for TEE 112 environments. Trusty contains an approved implementation of GateKeeper. However, 113 <strong>any TEE OS</strong> can be used for the implementation of Gatekeeper. 114 The TEE <strong>must</strong> have access to a hardware-backed key as well as a secure, 115 monotonic clock <strong>that ticks in suspend</strong>.</p> 116 117 <p>Trusty uses an internal IPC system to communicate a shared secret directly 118 between Keymaster and the Trusty implementation of Gatekeeper ("Trusty 119 Gatekeeper"). This shared secret is used for signing AuthTokens that will be 120 sent to Keystore, providing attestations of password verification. Trusty 121 Gatekeeper requests the key from Keymaster for each use and does not persist 122 or cache the value. Implementations are free to share this secret in any way 123 that does not compromise security.</p> 124 125 <p>The HMAC key, used to enroll and verify passwords, is derived and kept solely 126 in GateKeeper.</p> 127 128 <p>The Android tree provides a generic C++ implementation of GateKeeper, requiring 129 only the addition of device-specific routines to be complete. To implement a 130 TEE Gatekeeper with device-specific code for your TEE, please refer to the 131 functions and comments in the following file:</p> 132 <pre> 133 system/gatekeeper/include/gatekeeper/gatekeeper.h 134 </pre> 135 136 <p>For the TEE GateKeeper, the primary responsibilities of a compliant 137 implementation are:</p> 138 139 <ul> 140 <li>Adherence to the Gatekeeper HAL 141 <li>Returned AuthTokens must be formatted according to the AuthToken specification 142 (described in <a href="index.html">Authentication</a>) 143 <li>The TEE Gatekeeper must be able to share an HMAC key with Keymaster, either by 144 requesting the key through a TEE IPC on demand or maintaining a valid cache of 145 the value at all times 146 </ul> 147 148 <h2 id=user_sids>User SIDs</h2> 149 150 <p>A User Secure ID (User SID) is the TEE representation of a user. 151 The User SID has no strong connection to an Android user ID.</p> 152 153 <p>A User SID is generated with a cryptographic 154 PRNG whenever a user enrolls a new password without providing a previous one. 155 This is known as an "untrusted" re-enroll. 156 A "trusted" re-enroll occurs when a user provides a valid, previous password. 157 In this case, the User SID is migrated to the new password handle, 158 conserving the keys that were bound to it. 159 The Android framework does not allow for an "untrusted" re-enroll under regular circumstances.</p> 160 161 <p>The User SID is HMAC'ed along with the password in the password handle when the 162 password is enrolled.</p> 163 164 <p>User SIDs are written into the AuthToken returned by the <code>verify</code> 165 function and associated to all authentication-bound Keystore keys. For 166 information about the AuthToken format and Keystore, see 167 <a href="index.html">Authentication</a>. 168 Since an untrusted call to the <code>enroll</code> function 169 will change the User SID, the call will render the keys bound to that password useless.</p> 170 171 <p>Attackers can change the password for the device if they control the Android 172 OS, but they will destroy root-protected, sensitive keys in the process.</p> 173 174 <h2 id=request_throttling>Request throttling</h2> 175 176 <p>GateKeeper must be able to securely throttle brute-force attempts on a user 177 credential. As shown in the <code>gatekeeper.h</code> 178 file (in <code>hardware/libhardware/include/hardware</code>), 179 the HAL provides for returning a timeout in milliseconds. The timeout 180 informs the client not to call GateKeeper again until after the timeout has 181 elapsed. GateKeeper should not service requests if there is a pending timeout.</p> 182 183 <p>GateKeeper must write a failure counter before verifying a user password. If 184 the password verification succeeds, the failure counter should be cleared. This 185 prevents attacks that prevent throttling by disabling the embedded MMC (eMMC) 186 after issuing a <code>verify</code> call. The <code>enroll</code> function also verifies 187 the user password (if provided) and so must be throttled in the same way.</p> 188 189 <p>If supported by the device, it is highly recommended that the failure counter 190 be written to secure storage. If the device does not support 191 file-based encryption, or if secure storage is too slow, implementations may 192 use RPMB directly.</p> 193 194 195 196 197