Merge pull request #1241 from akioyamamoto1977/master
Client certificate from local storage
This commit is contained in:
commit
3681e2c1d9
22
android/src/main/java/com/pichillilorenzo/flutter_inappwebview/Util.java
Executable file → Normal file
22
android/src/main/java/com/pichillilorenzo/flutter_inappwebview/Util.java
Executable file → Normal file
|
@ -17,6 +17,7 @@ import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
@ -139,17 +140,23 @@ public class Util {
|
||||||
public static PrivateKeyAndCertificates loadPrivateKeyAndCertificate(InAppWebViewFlutterPlugin plugin, String certificatePath, String certificatePassword, String keyStoreType) {
|
public static PrivateKeyAndCertificates loadPrivateKeyAndCertificate(InAppWebViewFlutterPlugin plugin, String certificatePath, String certificatePassword, String keyStoreType) {
|
||||||
|
|
||||||
PrivateKeyAndCertificates privateKeyAndCertificates = null;
|
PrivateKeyAndCertificates privateKeyAndCertificates = null;
|
||||||
|
InputStream certificateFileStream = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
InputStream certificateFileStream = getFileAsset(plugin, certificatePath);
|
certificateFileStream = getFileAsset(plugin, certificatePath);
|
||||||
|
} catch (IOException ignored) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (certificateFileStream == null) {
|
||||||
|
certificateFileStream = new FileInputStream(certificatePath);
|
||||||
|
}
|
||||||
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
|
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
|
||||||
keyStore.load(certificateFileStream, certificatePassword != null ? certificatePassword.toCharArray() : null);
|
keyStore.load(certificateFileStream, (certificatePassword != null ? certificatePassword : "").toCharArray());
|
||||||
|
|
||||||
Enumeration<String> aliases = keyStore.aliases();
|
Enumeration<String> aliases = keyStore.aliases();
|
||||||
String alias = aliases.nextElement();
|
String alias = aliases.nextElement();
|
||||||
|
|
||||||
Key key = keyStore.getKey(alias, certificatePassword.toCharArray());
|
Key key = keyStore.getKey(alias, (certificatePassword != null ? certificatePassword : "").toCharArray());
|
||||||
if (key instanceof PrivateKey) {
|
if (key instanceof PrivateKey) {
|
||||||
PrivateKey privateKey = (PrivateKey)key;
|
PrivateKey privateKey = (PrivateKey)key;
|
||||||
Certificate cert = keyStore.getCertificate(alias);
|
Certificate cert = keyStore.getCertificate(alias);
|
||||||
|
@ -161,6 +168,15 @@ public class Util {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Log.e(LOG_TAG, e.getMessage());
|
Log.e(LOG_TAG, e.getMessage());
|
||||||
|
} finally {
|
||||||
|
if (certificateFileStream != null) {
|
||||||
|
try {
|
||||||
|
certificateFileStream.close();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
Log.e(LOG_TAG, ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return privateKeyAndCertificates;
|
return privateKeyAndCertificates;
|
||||||
|
|
Loading…
Reference in New Issue