diff options
author | Miguel Aranda <miguelaranda@google.com> | 2022-02-28 15:45:50 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-02-28 15:45:50 +0000 |
commit | 1d86a600c6918204877a24fad666280e45973a8e (patch) | |
tree | e854bb16497cf69713de99f71a5d2047297a1289 | |
parent | ada2dad4fc127fdeaa0468bf6181d65f4ae34780 (diff) | |
parent | a25dc12e108bf8c043f92e96bc1fe09f70a6aa86 (diff) | |
download | bouncycastle-1d86a600c6918204877a24fad666280e45973a8e.tar.gz |
Merge "Add engineProbe to BcKeyStoreSpi." am: a25dc12e10
Original change: https://android-review.googlesource.com/c/platform/external/bouncycastle/+/2000730
Change-Id: Ib2a5b8447a79640be57559c64af98258343a2913
3 files changed, 153 insertions, 0 deletions
diff --git a/bcprov/src/main/java/org/bouncycastle/jcajce/provider/keystore/bc/BcKeyStoreSpi.java b/bcprov/src/main/java/org/bouncycastle/jcajce/provider/keystore/bc/BcKeyStoreSpi.java index 2c439f4e..5ec21c8b 100644 --- a/bcprov/src/main/java/org/bouncycastle/jcajce/provider/keystore/bc/BcKeyStoreSpi.java +++ b/bcprov/src/main/java/org/bouncycastle/jcajce/provider/keystore/bc/BcKeyStoreSpi.java @@ -931,6 +931,33 @@ public class BcKeyStoreSpi dOut.close(); } + // BEGIN Android-added: new API for KeyStore probing. + /** + * Probe the first few bytes of the keystore data stream for a valid + * keystore encoding. Only the primary keystore implementation is probed. + */ + public boolean engineProbe(InputStream stream) throws IOException { + if (stream == null) { + throw new NullPointerException("input stream must not be null"); + } + DataInputStream dIn = new DataInputStream(stream); + int version = dIn.readInt(); + + if (version != STORE_VERSION) { + if (version != 0 && version != 1) { + return false; + } + } + byte[] salt = new byte[dIn.readInt()]; + + if (salt.length != STORE_SALT_SIZE) { + return false; + } + + return true; + } + // END Android-added: new API for KeyStore probing. + /** * the BouncyCastle store. This wont work with the key tool as the * store is stored encrypted on disk, so the password is mandatory, @@ -1050,6 +1077,30 @@ public class BcKeyStoreSpi cOut.close(); } + + // BEGIN Android-added: new API for KeyStore probing. + @Override + public boolean engineProbe(InputStream stream) throws IOException { + if (stream == null) { + throw new NullPointerException("input stream must not be null"); + } + DataInputStream dIn = new DataInputStream(stream); + int version = dIn.readInt(); + + if (version != STORE_VERSION) { + if (version != 0 && version != 1) { + return false; + } + } + byte[] salt = new byte[dIn.readInt()]; + + if (salt.length != STORE_SALT_SIZE) { + return false; + } + + return true; + } + // END Android-added: new API for KeyStore probing. } public static class Std diff --git a/repackaged/bcprov/src/main/java/com/android/org/bouncycastle/jcajce/provider/keystore/bc/BcKeyStoreSpi.java b/repackaged/bcprov/src/main/java/com/android/org/bouncycastle/jcajce/provider/keystore/bc/BcKeyStoreSpi.java index 44faf7db..9605cedd 100644 --- a/repackaged/bcprov/src/main/java/com/android/org/bouncycastle/jcajce/provider/keystore/bc/BcKeyStoreSpi.java +++ b/repackaged/bcprov/src/main/java/com/android/org/bouncycastle/jcajce/provider/keystore/bc/BcKeyStoreSpi.java @@ -935,6 +935,33 @@ public class BcKeyStoreSpi dOut.close(); } + // BEGIN Android-added: new API for KeyStore probing. + /** + * Probe the first few bytes of the keystore data stream for a valid + * keystore encoding. Only the primary keystore implementation is probed. + */ + public boolean engineProbe(InputStream stream) throws IOException { + if (stream == null) { + throw new NullPointerException("input stream must not be null"); + } + DataInputStream dIn = new DataInputStream(stream); + int version = dIn.readInt(); + + if (version != STORE_VERSION) { + if (version != 0 && version != 1) { + return false; + } + } + byte[] salt = new byte[dIn.readInt()]; + + if (salt.length != STORE_SALT_SIZE) { + return false; + } + + return true; + } + // END Android-added: new API for KeyStore probing. + /** * the BouncyCastle store. This wont work with the key tool as the * store is stored encrypted on disk, so the password is mandatory, @@ -1055,6 +1082,30 @@ public class BcKeyStoreSpi cOut.close(); } + + // BEGIN Android-added: new API for KeyStore probing. + @Override + public boolean engineProbe(InputStream stream) throws IOException { + if (stream == null) { + throw new NullPointerException("input stream must not be null"); + } + DataInputStream dIn = new DataInputStream(stream); + int version = dIn.readInt(); + + if (version != STORE_VERSION) { + if (version != 0 && version != 1) { + return false; + } + } + byte[] salt = new byte[dIn.readInt()]; + + if (salt.length != STORE_SALT_SIZE) { + return false; + } + + return true; + } + // END Android-added: new API for KeyStore probing. } /** diff --git a/repackaged_platform/bcprov/src/main/java/com/android/internal/org/bouncycastle/jcajce/provider/keystore/bc/BcKeyStoreSpi.java b/repackaged_platform/bcprov/src/main/java/com/android/internal/org/bouncycastle/jcajce/provider/keystore/bc/BcKeyStoreSpi.java index 44be654a..6c2c25b0 100644 --- a/repackaged_platform/bcprov/src/main/java/com/android/internal/org/bouncycastle/jcajce/provider/keystore/bc/BcKeyStoreSpi.java +++ b/repackaged_platform/bcprov/src/main/java/com/android/internal/org/bouncycastle/jcajce/provider/keystore/bc/BcKeyStoreSpi.java @@ -935,6 +935,33 @@ public class BcKeyStoreSpi dOut.close(); } + // BEGIN Android-added: new API for KeyStore probing. + /** + * Probe the first few bytes of the keystore data stream for a valid + * keystore encoding. Only the primary keystore implementation is probed. + */ + public boolean engineProbe(InputStream stream) throws IOException { + if (stream == null) { + throw new NullPointerException("input stream must not be null"); + } + DataInputStream dIn = new DataInputStream(stream); + int version = dIn.readInt(); + + if (version != STORE_VERSION) { + if (version != 0 && version != 1) { + return false; + } + } + byte[] salt = new byte[dIn.readInt()]; + + if (salt.length != STORE_SALT_SIZE) { + return false; + } + + return true; + } + // END Android-added: new API for KeyStore probing. + /** * the BouncyCastle store. This wont work with the key tool as the * store is stored encrypted on disk, so the password is mandatory, @@ -1055,6 +1082,30 @@ public class BcKeyStoreSpi cOut.close(); } + + // BEGIN Android-added: new API for KeyStore probing. + @Override + public boolean engineProbe(InputStream stream) throws IOException { + if (stream == null) { + throw new NullPointerException("input stream must not be null"); + } + DataInputStream dIn = new DataInputStream(stream); + int version = dIn.readInt(); + + if (version != STORE_VERSION) { + if (version != 0 && version != 1) { + return false; + } + } + byte[] salt = new byte[dIn.readInt()]; + + if (salt.length != STORE_SALT_SIZE) { + return false; + } + + return true; + } + // END Android-added: new API for KeyStore probing. } /** |