From 040875003d3c7fd05085bf3aea37a0e57a21f271 Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Thu, 15 Nov 2018 16:47:39 -0800 Subject: [PATCH] Fix for Android P warnings --- .../wrapper/AbstractAndroidKeystoreSecretKeyWrapper.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/AndroidVault/vault/src/main/java/com/bottlerocketstudios/vault/keys/wrapper/AbstractAndroidKeystoreSecretKeyWrapper.java b/AndroidVault/vault/src/main/java/com/bottlerocketstudios/vault/keys/wrapper/AbstractAndroidKeystoreSecretKeyWrapper.java index 46ce169..7885045 100644 --- a/AndroidVault/vault/src/main/java/com/bottlerocketstudios/vault/keys/wrapper/AbstractAndroidKeystoreSecretKeyWrapper.java +++ b/AndroidVault/vault/src/main/java/com/bottlerocketstudios/vault/keys/wrapper/AbstractAndroidKeystoreSecretKeyWrapper.java @@ -33,6 +33,8 @@ import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.KeyStore; +import java.security.PrivateKey; +import java.security.PublicKey; import java.security.spec.AlgorithmParameterSpec; import java.util.Arrays; import java.util.Calendar; @@ -79,8 +81,9 @@ private KeyPair getKeyPair() throws GeneralSecurityException, IOException { } // Even if we just generated the key, always read it back to ensure we // can read it successfully. - final KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) keyStore.getEntry(mAlias, null); - mKeyPair = new KeyPair(entry.getCertificate().getPublicKey(), entry.getPrivateKey()); + PrivateKey privateKey = (PrivateKey) keyStore.getKey(mAlias, null); + PublicKey publicKey = privateKey != null ? keyStore.getCertificate(mAlias).getPublicKey() : null; + mKeyPair = new KeyPair(publicKey, privateKey); } } return mKeyPair;