blob: 99b036aefe2367049cbbf075a72cdd44e5057290 [file] [log] [blame]
David Zeuthen81603152020-02-11 22:04:24 -05001/*
2 * Copyright 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.hardware.keymaster;
18
19import android.hardware.keymaster.Timestamp;
20import android.hardware.keymaster.HardwareAuthenticatorType;
21
22/**
23 * HardwareAuthToken is used to prove successful user authentication, to unlock the use of a key.
24 *
25 * HardwareAuthTokens are produced by other secure environment applications, notably GateKeeper and
26 * Fingerprint, in response to successful user authentication events. These tokens are passed to
27 * begin(), update(), and finish() to prove that authentication occurred. See those methods for
28 * more details. It is up to the caller to determine which of the generated auth tokens is
29 * appropriate for a given key operation.
30 */
31@VintfStability
32parcelable HardwareAuthToken {
33
34 /**
35 * challenge is a value that's used to enable authentication tokens to authorize specific
36 * events. The primary use case for challenge is to authorize an IKeymasterDevice cryptographic
37 * operation, for keys that require authentication per operation. See begin() for details.
38 */
39 long challenge;
40
41 /**
42 * userId is the a "secure" user ID. It is not related to any Android user ID or UID, but is
43 * created in the Gatekeeper application in the secure environment.
44 */
45 long userId;
46
47 /**
48 * authenticatorId is the a "secure" user ID. It is not related to any Android user ID or UID,
49 * but is created in an authentication application in the secure environment, such as the
50 * Fingerprint application.
51 */
52 long authenticatorId; // Secure authenticator ID.
53
54 /**
55 * authenticatorType describes the type of authentication that took place, e.g. password or
56 * fingerprint.
57 */
Jooyung Han9c3ebfc2021-04-27 18:33:17 +090058 HardwareAuthenticatorType authenticatorType = HardwareAuthenticatorType.NONE;
David Zeuthen81603152020-02-11 22:04:24 -050059
60 /**
61 * timestamp indicates when the user authentication took place, in milliseconds since some
62 * starting point (generally the most recent device boot) which all of the applications within
63 * one secure environment must agree upon. This timestamp is used to determine whether or not
64 * the authentication occurred recently enough to unlock a key (see Tag::AUTH_TIMEOUT).
65 */
66 Timestamp timestamp;
67
68 /**
69 * MACs are computed with a backward-compatible method, used by Keymaster 3.0, Gatekeeper 1.0
70 * and Fingerprint 1.0, as well as pre-treble HALs.
71 *
72 * The MAC is Constants::AUTH_TOKEN_MAC_LENGTH bytes in length and is computed as follows:
73 *
74 * HMAC_SHA256(
75 * H, 0 || challenge || user_id || authenticator_id || authenticator_type || timestamp)
76 *
77 * where ``||'' represents concatenation, the leading zero is a single byte, and all integers
78 * are represented as unsigned values, the full width of the type. The challenge, userId and
79 * authenticatorId values are in machine order, but authenticatorType and timestamp are in
80 * network order (big-endian). This odd construction is compatible with the hw_auth_token_t
81 * structure,
82 *
83 * Note that mac is a vec rather than an array, not because it's actually variable-length but
84 * because it could be empty. As documented in the IKeymasterDevice::begin,
85 * IKeymasterDevice::update and IKeymasterDevice::finish doc comments, an empty mac indicates
86 * that this auth token is empty.
87 */
88 byte[] mac;
89}