merged Android - Load client certificate from local storage
This commit is contained in:
parent
596a228a05
commit
0a49c7094f
@ -40,6 +40,7 @@
|
|||||||
- Merged "Fix RangeError: Maximum call stack size exceeded" [#1208](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1208) (thanks to [liasica](https://github.com/liasica))
|
- Merged "Fix RangeError: Maximum call stack size exceeded" [#1208](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1208) (thanks to [liasica](https://github.com/liasica))
|
||||||
- Merged "fix: try to open with Chrome if default browser app does not support custom tabs" [#1233](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1233) (thanks to [addie9000](https://github.com/addie9000))
|
- Merged "fix: try to open with Chrome if default browser app does not support custom tabs" [#1233](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1233) (thanks to [addie9000](https://github.com/addie9000))
|
||||||
- Merged "fix: Prevent Android java.lang.NullPointerException in InAppWebViewCl…" [#1237](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1237) (thanks to [kamilpowalowski](https://github.com/kamilpowalowski))
|
- Merged "fix: Prevent Android java.lang.NullPointerException in InAppWebViewCl…" [#1237](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1237) (thanks to [kamilpowalowski](https://github.com/kamilpowalowski))
|
||||||
|
- Merged "Android - Load client certificate from local storage" [#1241](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1241) (thanks to [akioyamamoto1977](https://github.com/akioyamamoto1977))
|
||||||
|
|
||||||
## 5.4.4+3
|
## 5.4.4+3
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
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;
|
||||||
@ -110,17 +111,23 @@ public class Util {
|
|||||||
@Nullable String certificatePassword,
|
@Nullable String certificatePassword,
|
||||||
@NonNull String keyStoreType) {
|
@NonNull 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 != null ? certificatePassword.toCharArray() : null);
|
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);
|
||||||
@ -132,6 +139,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…
x
Reference in New Issue
Block a user