Commit Graph

699 Commits

Author SHA1 Message Date
Janis Danisevskis
4545933da5 Keystore 2.0 SPI: Evolve the Crypto SPI.
This patch evolves the Crypto SPI to use the new Keystore 2.0 shim.
The main changes are:
 * The SPI uses the AIDL defined KeyParameter instead of
   KeymasterArguments.
 * Operations are created directly from the KeystoreSecurityLevel that
   is part of the AndroidKeyStoreKey object.

Also this patch deletes the DeletatingX509Certificate class. This is no
longer needed, because public key operations are no longer performed by
Keystore 2.0. We can delegate public certificate operations simply by
wrapping such certificates into public keys that are understood by other
providers, such as BouncyCastle.

Bug: 159476414
Test: None
Change-Id: Ice874a8121d80bf788da059b4e8420c7dd799d81
2020-11-13 19:55:40 -08:00
Janis Danisevskis
4be5005c05 Keystore 2.0 SPI: KeyParameter utilities.
The wire type for key parameters is now generated from AIDL rather than
the hand written parcelable KeymasterArguments. So we need some of the
utilities for creating key parameters that the latter provided.
We also nicked some utility function from KeymasterUtils.

Bug: 159476414
Test: None
Change-Id: I12c674b6a00dd3abbed4972d80ceb766a73881e8
2020-11-13 19:55:40 -08:00
Janis Danisevskis
4ba9a09bdd Keystore 2.0 SPI: Update the chunked streamer.
This patch makes the chunked streamer observe the simplified
Keystore 2.0 operation interface. Keystore is now required to consume
all supplied data or reject data outright if too much (more than 32KiB)
is supplied in a single transaction. This allows for a simplified
streamer logic and a simplified interface. We also no longer send
entropy to Keystore. This will be handled by the Keystore 2.0 daemon.

Test: None
Bug: 159476414
Change-Id: Ie75d10fd5d5ac0da60e23e35467d0a7873230dea
2020-11-13 19:55:40 -08:00
Janis Danisevskis
27ee56c021 Keystore 2.0 SPI: KeyStoreCryptoOperationUtils
Keystore 2.0 does no longer report an error code if an operation
requires user authorization. Instead this is indicated by sending us
an operation challenge. In that case we have to check if the
authorization can possibly succeed. We changed the utility class by
adding a predicate function that checks exactly that, and we handle
other errors separately instead of having one exception handling path
that does all.

Test: None
Bug: 159476414
Change-Id: I9a373cf8f0a0b181df54c26fe314d71b6835bb97
2020-11-13 19:55:39 -08:00
Janis Danisevskis
e5795a90db Keystore 2.0 SPI: KeyStoreKeys adopt Keystore 2.0
KeyStoreKeys can now be constructed from key entry metadata and key
descriptors as defined by the new Keystore AIDL spec.
AndroidKeystorePublicKey can now create the private key proxy.
KeyStoreKeys also cache the key characteristic, which should drastically
reduce the frequency by which the SPI has to call into the Keystore 2.0
daemon.

Test: None
Bug: 159476414
Change-Id: Ia0a7841582621897760be49d39dd5442b70b3aa0
2020-11-13 19:55:39 -08:00
Janis Danisevskis
ebd964a086 Keystore 2.0: Shim around the basic functionality of Keystore 2.0
This patch adds a shim around the Keystore 2.0 AIDL spec. The new shim
is modularized like the AIDL spec into the base Keystore module
Keystore2, the security level specific interface KeystoreSecurityLevel,
and the operation specific interface KeystoreOperation.

Other system maintenance specific interfaces have yet to be added.

Bug: 159476414
Bug: 171305684
Test: None
Change-Id: I070f73739e4b37ce10568939ac666e40b14a52a8
2020-11-13 19:55:39 -08:00
Janis Danisevskis
f88d3a4b27 Keystore 2.0 SPI: Duplicate Keystore SPI to android.security.keystore2 package
This patch copies the relevant portion of the Keystore SPI to the new
package name android.security.keystore2. The purpose of this is to
illustrate the evolution from the existing Keystore SPI to the
Keystore 2.0 SPI while keeping the existing Keystore SPI intact.
Reviewers are advised to check the equivalence of this code to the
corresponding files in
    android/security/keystore (<-- no 2 here).
Subsequent patches can them be reviewed as evolution towards the new SPI
rather than completely new code.

Test: None. When the evolution is complete, Keystore CTS tests can be
used to check for regressions.
Bug: 159476414

Change-Id: I21a01a679e789868ce820b5f73221e616a456a61
2020-11-13 11:01:47 -08:00
Treehugger Robot
47e0d9e30b Merge "Keystore 2.0 SPI: Add forEach for int arrays to ArrayUtils" 2020-11-12 17:57:42 +00:00
Janis Danisevskis
cbab0d133b Keystore 2.0 SPI: Add forEach for int arrays to ArrayUtils
This patch adds a forEach function for int arrays to
android.security.keystore.ArrayUtils. A utility function with the
intendet use in Keystore 2.0 Key paramter handling.

Test: None
Change-Id: I2c02b300ee68fcd548c128deb0266fe603226807
2020-11-12 08:03:25 -08:00
Janis Danisevskis
17f24b5799 Merge "Keystore 2.0 SPI: Update KeyInfo and KeyGenParameterSpec" 2020-11-11 23:10:13 +00:00
Janis Danisevskis
c5bdd77f1a Keystore 2.0 SPI: Update KeyInfo and KeyGenParameterSpec
This patch adds set/getSecurityLevel to KeyInfo and KeyGenParameterSpec
and it deprecates the superseded function isInSecureHardware.

It also deprecates the system API set/getUid and replaces it with the
more generic set/getNamespace.

Test: None
Change-Id: Id2f54596510954862b5077a935f3daf07211f29c
2020-11-11 07:53:54 -08:00
Mathew Inwood
f8abe13db4 Merge "Add maxTargetSdk restriction to unused APIs." 2020-11-09 14:41:20 +00:00
Janis Danisevskis
62c1d2869d Keystore 2.0: KeyProperties SignaturePadding is now public but hidden
In anticipation of the new Keystore 2.0 SPI we made this nested class
public (like its siblings) so that the new SPI which resides in a
different package may access it. It is hidden though because it does not
constitute public API surface.

Test: None
Bug: 171305684
Change-Id: I1dbe3d02c03f97f843813c26c16aaef7152ca478
2020-11-05 13:11:12 -08:00
Janis Danisevskis
d2c944bc4d Keystore SPI: Add SecurityLevelEnum to KeyProperties
This patch adds the SecurityLevelEnum to KeyProperties. This enum can be
used by the public API surface to express levels of enforcements of key
properties. And to select a designated residence for a newly generated
or imported key.

The values UNKNOWN and UNKNOWN_SECURE are used to convey to older target
APIs API levels that have not been defined when they where published.

Test: None
Change-Id: I88681f21b8a8ea9a383d32ba99f3ab7d7c8909c3
2020-11-05 13:11:12 -08:00
Mathew Inwood
5d123b6775 Add maxTargetSdk restriction to unused APIs.
These are APIs that have @UnsupportedAppUsage but for which we don't
have any evidence of them currently being used, so should be safe to
remove from the unsupported list.

Bug: 170729553
Test: Treehugger
Merged-In: I626caf7c1fe46c5ab1f39c2895b42a34319f771a
Change-Id: I54e5ecd11e76ca1de3c5893e3a98b0108e735413
2020-11-04 09:45:53 +00:00
Janis Danisevskis
26c878fb66 Keystore SPI: Deprecate encryption flag.
The encryption-required flag is only available in already deprecated
API KeyPairGeneratorSpec and KeyStoreParameter will be ignored from
Android S. Keys are and have been encrypted by default for a long time
and if additional binding to the LSKF is desired it can be requested
by KeyGenParameterSpec.Builder#setUserAuthenticationRequired(boolean).

Test: None
Change-Id: I5bd4acb4bba276decd1930ae2e96a55f95627e10
2020-10-27 12:09:37 -07:00
Janis Danisevskis
2528438731 Keystore 2.0: Deprecate Credential prefixes.
Keystore 2.0 will no longer support free form blobs. Certificates and
certificate chains will have types fields associated with an alias.
Other free form blobs will need to be migrated to a different key value
store.

Bug: 171305684
Test: None
Change-Id: I93270f0086329229dc36c2b14c88f229351e6560
2020-10-27 12:09:37 -07:00
Janis Danisevskis
bb4e97ebf3 Keystore SPI: Fix typos.
Test: None
Change-Id: Iba25385b42db8059cc0811e99463e01acb98e00f
2020-10-22 21:03:32 -07:00
Anton Hansson
dd7d52f963 Remove @TestApi from @SystemApi symbols
I ran these commands:
    cd frameworks/base
    grep -rl '@TestApi' --include '*.java' | xargs perl -i -p0e \
        's/\@SystemApi[\s\n]+(\@\w+[\s\n]+)?\@TestApi/\@SystemApi\1/gs'
    grep -rl '@TestApi' --include '*.java' | xargs perl -i -p0e \
        's/\@TestApi[\s\n]+(\@\w+[\s\n]+)?\@SystemApi/\1\@SystemApi/gs'

Bug: 171179806
Test: m checkapi
Change-Id: I772790b783b0a8730b8bf680c9e569a886b8d789
Merged-In: I772790b783b0a8730b8bf680c9e569a886b8d789
2020-10-19 16:41:01 +01:00
Daulet Zhanguzin
96bdc2d785 Merge "Remove DERInteger usages" am: 1835a24839 am: 07e62d7649
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1305793

Change-Id: I7ec9709e9f152fac13b3f56dc1f9238869502c39
2020-07-03 12:02:35 +00:00
Daulet Zhanguzin
1835a24839 Merge "Remove DERInteger usages" 2020-07-03 11:42:50 +00:00
Treehugger Robot
faa8d92090 Merge "Preserve interrupted state across waiting for future" am: 3a91c75184 am: f6574a21c2
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1340128

Change-Id: Ica523ae5269ba5e2a339653024870fefa581ad64
2020-06-17 14:53:00 +00:00
Janis Danisevskis
edcacd5374 Preserve interrupted state across waiting for future
A normal synchronous binder call would not be influenced by an
interrupted thread. With the move to asynchronous keystore IPC we wait
on a future which can throw an interrupted exception. The Java crypto
API does not expect the implementation to throw interrupted exceptions
though. So to preserve the expected behavior we wrap the Future.get()
calls in a loop that handles the interrupted exception and sets the
interrupted state after the get completed successfully.

Bug: 147398412
Bug: 155254932
Test: atest android.keystore.cts.CipherTest#testEncryptsAndDecryptsInterrupted
Change-Id: I066180e8028cc426fa1b3739fa007faa17c8c012
Merged-In: I066180e8028cc426fa1b3739fa007faa17c8c012
2020-06-16 19:54:38 -07:00
TreeHugger Robot
8502b97753 Merge "Fixing default timeout constant" into rvc-dev am: 7697d0f3eb
Change-Id: I327671ad92b312cb1484d6433ac48497873f1497
2020-05-21 15:59:55 +00:00
TreeHugger Robot
7697d0f3eb Merge "Fixing default timeout constant" into rvc-dev 2020-05-21 15:58:33 +00:00
TreeHugger Robot
f2fe180f43 Merge "Update KeyChain.createInstallIntent documentation" into rvc-dev am: 0bada478b6
Change-Id: I3f593e73e7166ab9dc1fa9eb9c95c4c2c587df11
2020-05-20 14:53:12 +00:00
Eran Messeri
cdcbb66be6 Update KeyChain.createInstallIntent documentation
Update the KeyChain.createInstallIntent method documentation to reflect
the change where CA certificates can no longer be installed using
this intent.

Bug: 156941631
Test: m docs
Change-Id: I3cf2c677c4c772698c8df5f25224dd67d12b5606
2020-05-20 11:14:06 +01:00
Dorin Drimus
c5a547bb2b Merge "Attest device base properties" am: 547aeb27e8 am: f078d49979
Change-Id: Icbca4968438f659bf3d636100b5b172e63eaefb2
2020-05-18 10:13:21 +00:00
Dorin Drimus
9d5b804ea3 Attest device base properties
Add API to allow inclusion of device base properties to the
attestation certificate generated with a Key in Keystore.

Test: atest KeyAttestationTest
Bug: 152945378

Change-Id: Iaf282709f800501aa4c988ebf51cf3238583f9b6
2020-05-15 07:56:05 +00:00
Daulet Zhanguzin
d3d06ceea2 Remove DERInteger usages
Not really used in AndroidKeyStore

Test: Treehugger
Bug: 154796679
Change-Id: Id21b256b3221fd4353401c81e538a46b2f7c6246
2020-05-13 16:27:11 +01:00
Bill Yi
b61408add5 Merge android10-qpr2-s3-release to aosp/master - DO NOT MERGE
Change-Id: I7ce0992bd12158655c0f4833fd924c8012386996
Merged-In: I34d1d5f9a751c1d7680a5a5941c39b9fe33a473b
Merged-In: Icd731877c220b0e3b39258812030313cbaba90c0
2020-05-05 20:34:22 +00:00
Max Bires
919a9d6d77 Fixing default timeout constant
The getKeyInfo check was not updated to use the new integer representing
an auth per operation key.

Bug: 152618140
Test: atest AuthBoundKeyTest
Change-Id: Ifa6d37ac878ba267761ed7ae32c544cd4b662d25
2020-04-27 17:45:22 +00:00
Rubin Xu
576c4d816c RESTRICT AUTOMERGE
Update keyguard locked state from TrustManagerService

TrustManagerService holds the ground truth about whether a user is
locked or not, so update keystore using the information there,
instead of doing it from KeyguardStateMonitor. This fixes the issue
of work profile locked state not being correctly pushed to keystore.

Note: since this change is likely to be backported as a security
patch, I'm refraining from doing major refactoring right now.

Bug: 141329041
Bug: 144430870
Test: manually with KeyPairSampleApp
Change-Id: I3472ece73d573a775345ebcceeeb2cc460374c9b
(cherry picked from commit f9418dbb2c)
2020-03-19 04:51:51 +00:00
Max Bires
1cfd95ec0c Fixing how SIDs are added to keys during generation time
SIDs were not being properly applied to key parameters under the new
authentication rework. Now that biometric/credential unlocks are valid
for either auth-per-op or timeout auth bound keys, the SIDs need to be
tacked on appropriately in each authentication flow.

Bug: 148425329
Test: CtsVerifier
Change-Id: I73733b00d2da5ac78db6d77c53de144f4473bb54
2020-03-17 02:57:36 +00:00
Max Bires
a811787a96 Fixing default behavior for keys requiring auth
The default timeout and authentication type is being updated to offer a
correct default that matches the old behavior.

Bug: 148425329
Bug: 149931201
Test: CtsVerifier
Test: atest KeyguardLockedTests

Change-Id: Id20097b04ce881e7028609d2ba1c30c26ba3c8cf
2020-03-11 13:43:52 -07:00
TreeHugger Robot
0ffc3165a3 Merge "Do not allow -1 duration in setUserAuthenticationParameters" into rvc-dev 2020-03-05 21:39:57 +00:00
Kevin Chyn
9f49e8df2a Do not allow -1 duration in setUserAuthenticationParameters
This is a completely new API so callers can follow the new pattern of
using 0 to require auth for every use of the key.

Supporting both -1 and 0 to require auth for every use of the key
increases CtsVerifier complexity exponentially (strongbox,
invalidated by enrollment, etc).

Fixes: 150823346
Test: builds
Change-Id: Ieef53a8b50f5119c5e52656e930bf16b1e8e3d89
2020-03-05 11:17:22 -08:00
Kenny Root
291718cdb7 Merge "Revert "Fixing default behavior for keys requiring auth"" into rvc-dev 2020-03-05 17:10:53 +00:00
Kenny Root
382e724714 Revert "Fixing default behavior for keys requiring auth"
This reverts commit e5b6686b49.

Reason for revert: Droidcop-triggered revert due to breakage https://android-build.googleplex.com/builds/quarterdeck?testMethod=testDismissKeyguard&testClass=android.server.wm.KeyguardLockedTests&atpConfigName=cts%2Fframework%2Fgce-presubmit-wm-cloud-tf-2&testModule=CtsWindowManagerDeviceTestCases&fkbb=6265187&lkbb=6266200&lkgb=6265150&testResults=true&badBuildCount=32&branch=git_rvc-dev-plus-aosp&target=aosp_cf_x86_phone-userdebug, bug b/150847441

Bug: 150847441
Change-Id: I1e648e1174172f8077cea1dd175c4167830adcb6
2020-03-05 16:57:39 +00:00
Kevin Chyn
8586645527 Merge "Fixing default behavior for keys requiring auth" into rvc-dev 2020-03-05 04:06:22 +00:00
Max Bires
e5b6686b49 Fixing default behavior for keys requiring auth
The default timeout and authentication type is being updated to offer a
correct default that matches the old behavior.

Bug: 149931201
Test: CtsVerifier
Change-Id: I3f3d4f8d5b02455c285a882933fd6c37739ee44a
2020-03-04 17:31:06 -08:00
Eran Messeri
3f9578be3e Fix copy-pasted documentation.
Fix the documentation  for USE_INDIVIDUAL_ATTESTATION which was
copy-pasted from another attestation ID type.

Bug: 149475774
Test: That it compiles.
Change-Id: I9366870c8875997321c93fe1db216e91f374b1db
2020-02-28 11:32:33 +00:00
Kevin Chyn
df244da79a Merge changes from topic "biometric-and-credential"
* changes:
  Always start AuthController
  Clean up biometric system server
2020-02-21 21:37:14 +00:00
Kevin Chyn
7d07c89235 Clean up biometric system server
1) BiometricService / AuthService always need to be started, since on
   Android 11 and later, the public credential auth API comes through this
   path.

2) Consolidate getAuthenticatorId() and expose via AuthService. This is
   used only by the platform during key generation. Instead of asking
   each individual service, AuthService will return a list of IDs for
   sensors which are enrolled and meet the required strength.

Test: atest com.android.server.biometrics
Test: fingerprint device, CtsVerifier biometric section
Test: face unlock device, CtsVerifier biometric section
Test: remove biometrics from device, CtsVerifier biometric section

Bug: 148419762
Bug: 149795050

Change-Id: I2c5385b1cd4f343fabb0010e1fe6fb1ea8283391
2020-02-20 11:12:51 -08:00
Rubin Xu
144b057c26 Ensure user is unlocked before binding to KeyChain service
This stops KeyChain from throwing AssertionError when binding to
service fails due to user being locked, which would have crashed
the entire system server.

Bug: 149912024
Test: atest KeyChainTests
Change-Id: Ie110a4210e157cc9b111d845478bdf21e948ba4f
2020-02-20 15:53:06 +00:00
Max Bires
04b682d394 Changing op per auth keys to allow password
Previously, auth per operation keystore keys could only be authorized
with biometrics. There is no reason to restrict this functionality to
biometrics. This change slightly refactors the key parameter builder
interface to allow the caller to specify which authentication types
should be allowed for an auth per op key.

Bug: 147693375
Bug: 140256692
Test: atest keystore
Change-Id: I5cbf3d4e3f0e84d577dbf6b4cb356b1010100925
2020-02-06 11:17:26 -08:00
Rubin Xu
b3a13e1e2c Add KeyGenParameterSpec.setCriticalToDeviceEncryption
Mirror KeyProtection.setCriticalToDeviceEncryption so
the flag can also be set on keys generated by keystore.

Bug: 72178550
Test: atest android.security.keystore.KeyGenParameterSpecTest
Test: atest android.security.ParcelableKeyGenParameterSpecTest
Change-Id: I7f102c82e60f211028c694d499ffd2838b89bb2b
2020-01-14 17:10:18 +00:00
Artur Satayev
7651f0a4c0 Use new UnsupportedAppUsage annotation.
Existing annotations in libcore/ and frameworks/ will deleted after the migration. This also means that any java library that compiles @UnsupportedAppUsage requires a direct dependency on "unsupportedappusage" java_library.

Bug: 145132366
Test: m && diff unsupportedappusage_index.csv
Change-Id: I4bc8c9482e4bb1af21363f951affff7ee3fefeab
Merged-In: I4bc8c9482e4bb1af21363f951affff7ee3fefeab
2020-01-09 15:13:52 +00:00
Automerger Merge Worker
509eee80fa Merge "Make KeyStoreCryptoOperationChunkedStreamer lazy." am: c13f012cc5 am: bb8ecaef09 am: ecb9c6f041
Change-Id: Icbcec2ae8ea5c907d7ce37558b0db0b634643a56
2020-01-06 16:29:26 +00:00
Rob Barnes
c13f012cc5 Merge "Make KeyStoreCryptoOperationChunkedStreamer lazy." 2020-01-06 15:33:06 +00:00