Snap for 8564071 from b7454c366ffd804c3df4e2c4889e6b9bb7d80d88 to mainline-wifi-release

Change-Id: Ia0d1a80fbfa1e4d0f93d9714f32f9e1f0dd86078
diff --git a/Android.bp b/Android.bp
index aefddc2..5ac1791 100644
--- a/Android.bp
+++ b/Android.bp
@@ -147,6 +147,7 @@
     "//external/robolectric-shadows/robolectric",
     "//external/robolectric-shadows/shadows/supportv4",
     "//external/robolectric-shadows/shadows/httpclient",
+    "//external/wycheproof",
     "//frameworks/opt/net/wifi/service",
     "//frameworks/opt/net/wifi/tests/wifitests",
     "//packages/apps/CertInstaller",
@@ -157,6 +158,7 @@
     "//packages/modules/Wifi/service/tests/wifitests",
     "//libcore",
     "//system/extras/verity",
+    "//system/security/identity/util",
     "//tools/security/remote_provisioning/attestation_testing",
     "//vendor:__subpackages__",
 ]
@@ -251,3 +253,26 @@
     ],
     sdk_version: "core_current",
 }
+
+// Bouncycastle for use by packages/modules/ExtServices project.
+//
+// Excludes directories not needed for ASN1*.java and X509* sources.
+//
+java_library {
+    name: "bouncycastle-extservices-asn",
+    visibility: [
+        "//packages/modules/ExtServices",
+    ],
+    apex_available: [
+        "com.android.extservices",
+        "test_com.android.extservices",
+    ],
+    srcs: [
+        "bcprov/src/main/java/org/bouncycastle/**/*.java",
+    ],
+    exclude_srcs: [
+        "bcprov/src/main/java/org/bouncycastle/asn1/ocsp/**/*.java",
+        "bcprov/src/main/java/org/bouncycastle/iana/**/*.java",
+    ],
+    sdk_version: "core_current",
+}
diff --git a/OWNERS b/OWNERS
index 1a1bcd9..73617ea 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,2 +1,2 @@
 # Bug component: 684135
-include platform/external/conscrypt:/OWNERS
+include platform/libcore:/OWNERS
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 2c439f4..5ec21c8 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 @@
         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 @@
     
             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 44faf7d..9605ced 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 @@
         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 @@
     
             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 44be654..6c2c25b 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 @@
         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 @@
     
             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.
     }
 
     /**