OSDN Git Service

Fix deleting legacy key blobs
authorJanis Danisevskis <jdanis@google.com>
Tue, 6 Nov 2018 22:14:05 +0000 (14:14 -0800)
committerJanis Danisevskis <jdanis@google.com>
Wed, 21 Nov 2018 18:42:17 +0000 (18:42 +0000)
commit906147cdb3663b1aa5f6ebdc4a8ce2ce509ffa27
treedc12b2c48b0250736ea7568fe5f8d703cb7e0b8d
parent4492ec573ae421affd3adebb1d583fcf33508bb4
Fix deleting legacy key blobs

Since the keystore alias prefix USERSKEY was deprecated
Credentials.deleteUserKeyTypeForAlias tried to delete key the
remaining prefix first and if that failed tried to delete the
legacy prefix.
However, KeyStore.delete returns true if the key was deleted or
did not exist. So the first call to delete would return true
whether the key existed or not and the legacy alias would never be
deleted.

This patch introduces a new flavor of KeyStore.delete, that returns an
error code instead of a boolean. The caller can now distinguish
the nature of the failure. Credentials.deleteUserKeyTypeForAlias now
checks this return code and attempts to delete the legacy variant if
KEY_NOT_FOUND was returned.

Bug: 117818447
Change-Id: Ifae1f3dbb07d85d94f430ead2cdd3e39d22436a4
keystore/java/android/security/Credentials.java
keystore/java/android/security/KeyStore.java