Skip to content

Commit 6f3d188

Browse files
authored
Fix hardware key attestation support (#715)
Enable attestation key by default, any enforcement happens in control. Also, make the HashMap for tracking loaded keys in HardwareKeyStore a singleton, so that multiple instances of HardwareKeyStore created in App.kt don't lose the state of the loaded keys. Updates tailscale/tailscale#15830 Signed-off-by: Andrew Lytvynov <[email protected]>
1 parent d62efaa commit 6f3d188

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

android/src/main/java/com/tailscale/ipn/App.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class App : UninitializedApp(), libtailscale.AppContext, ViewModelStoreOwner {
151151
// Check if a directory URI has already been stored.
152152
val storedUri = getStoredDirectoryUri()
153153
val rm = getSystemService(Context.RESTRICTIONS_SERVICE) as RestrictionsManager
154-
val hardwareAttestation = rm.applicationRestrictions.getBoolean(MDMSettings.KEY_HARDWARE_ATTESTATION, false)
154+
val hardwareAttestation = rm.applicationRestrictions.getBoolean(MDMSettings.KEY_HARDWARE_ATTESTATION, true)
155155
if (storedUri != null && storedUri.toString().startsWith("content://")) {
156156
startLibtailscale(storedUri.toString(), hardwareAttestation)
157157
} else {

android/src/main/java/com/tailscale/ipn/util/HardwareKeyStore.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: BSD-3-Clause
33
package com.tailscale.ipn.util
44

5-
import android.content.pm.PackageManager
65
import android.os.Build
76
import android.security.keystore.KeyGenParameterSpec
87
import android.security.keystore.KeyProperties
@@ -18,7 +17,13 @@ class HardwareKeysNotSupported : Exception("hardware-backed keys are not support
1817
// HardwareKeyStore implements the callbacks necessary to implement key.HardwareAttestationKey on
1918
// the Go side. It uses KeyStore with a StrongBox processor.
2019
class HardwareKeyStore() {
21-
var keyStoreKeys = HashMap<String, KeyPair>();
20+
// keyStoreKeys should be a singleton. Even if multiple HardwareKeyStores are created, we should
21+
// not create distinct underlying key maps.
22+
companion object {
23+
val keyStoreKeys: HashMap<String, KeyPair> by lazy {
24+
HashMap<String, KeyPair>()
25+
}
26+
}
2227
val keyStore: KeyStore = KeyStore.getInstance("AndroidKeyStore").apply {
2328
load(null)
2429
}

libtailscale/keystore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (k *hardwareAttestationKey) fetchPublic() error {
4848

4949
pubRaw, err := k.appCtx.HardwareAttestationKeyPublic(k.id)
5050
if err != nil {
51-
return fmt.Errorf("loading public key from KeyStore: %w", err)
51+
return fmt.Errorf("loading public key for id %q from KeyStore: %w", k.id, err)
5252
}
5353
pubAny, err := x509.ParsePKIXPublicKey(pubRaw)
5454
if err != nil {

0 commit comments

Comments
 (0)