Skip to content

Commit 0694686

Browse files
committed
Android: add BKS KeyStore conversion script and update README
1 parent 12004e6 commit 0694686

3 files changed

Lines changed: 101 additions & 7 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ wolfcrypt*.tar.gz
1919

2020
# Android
2121
IDE/Android/.idea/deploymentTargetDropDown.xml
22+
IDE/Android/.idea/vcs.xml
2223
IDE/Android/app/.cxx/
2324
IDE/Android/app/src/main/cpp/wolfssl
2425

IDE/Android/README.md

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,34 @@ del wolfssl
7575
mklink /D wolfssl ..\..\..\..\..\..\..\src\java\com\wolfssl\
7676
```
7777

78-
## 3. Push Certificate and KeyStore Files to Android Device
78+
## 3. Convert JKS KeyStore Files to BKS for Android Use
79+
80+
Android does not support JKS format KeyStores. Several JUnit tests
81+
require BKS format KeyStore files which must be converted from the existing
82+
JKS files.
83+
84+
To convert, you will need to download a Bouncy Castle provider JAR from the
85+
[Bouncy Castle website](https://www.bouncycastle.org/download/bouncy-castle-java/).
86+
Then run the conversion script from the `examples/certs` directory:
87+
88+
```
89+
cd examples/certs
90+
./convert-to-bks.sh <path/to/bcprov.jar>
91+
```
92+
93+
For example, when using `bcprov-jdk18on-1.78.1.jar`:
94+
95+
```
96+
cd examples/certs
97+
./convert-to-bks.sh ~/Downloads/bcprov-jdk18on-1.78.1.jar
98+
```
99+
100+
This will create the following BKS files needed by the Android tests:
101+
102+
- `ca-server-rsa-2048.bks`
103+
- `ca-server-ecc-256.bks`
104+
105+
## 4. Push Certificate and KeyStore Files to Android Device
79106

80107
Several JUnit tests require access to certificate and KeyStore files. These
81108
files are located in the `examples/certs` directory and must be pushed to
@@ -92,18 +119,20 @@ adb shell mkdir -p /data/local/tmp/examples/certs/crl
92119
adb push ./examples/certs/ /data/local/tmp/examples/
93120
```
94121

95-
This will push all certificate files, KeyStore files (.jks, .wks, .p12),
96-
and subdirectories (intermediate, rsapss, crl) needed by the JUnit tests.
122+
This will push all certificate files, KeyStore files (.jks, .wks, .bks,
123+
.p12), and subdirectories (intermediate, rsapss, crl) needed by the JUnit
124+
tests.
97125

98-
If this step is skipped, tests in the following classes will be skipped due
99-
to missing certificate files:
126+
If step 3 (BKS conversion) or this step is skipped, tests in the following
127+
classes will be skipped due to missing files:
100128

101-
- `WolfSSLKeyStoreTest`
129+
- `WolfCryptPKIXCertPathBuilderTest`
102130
- `WolfCryptPKIXCertPathValidatorTest`
103131
- `WolfCryptPKIXRevocationCheckerTest`
132+
- `WolfSSLKeyStoreTest`
104133
- `WolfSSLCertManagerOCSPTest`
105134

106-
## 4. Import and Build the Example Project with Android Studio
135+
## 5. Import and Build the Example Project with Android Studio
107136

108137
1) Open the Android Studio project by double clicking on the `Android` folder
109138
in wolfcrypt-jni/IDE/. Or, from inside Android Studio, open the `Android`

examples/certs/convert-to-bks.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
3+
# Convert JKS KeyStore files to BKS format for Android use.
4+
# Android does not support JKS KeyStores, so BKS format is needed.
5+
#
6+
# Requires a Bouncy Castle provider JAR (bcprov). Download from:
7+
# https://www.bouncycastle.org/download/bouncy-castle-java/
8+
#
9+
# Usage:
10+
# cd examples/certs
11+
# ./convert-to-bks.sh <path/to/bcprov.jar>
12+
#
13+
# Example:
14+
# ./convert-to-bks.sh ~/Downloads/bcprov-jdk18on-1.78.1.jar
15+
16+
if [ -z "$1" ]; then
17+
echo "Expected path to Bouncy Castle provider JAR."
18+
echo "Usage: ./convert-to-bks.sh <path/to/bcprov.jar>"
19+
echo ""
20+
echo "Example:"
21+
echo " ./convert-to-bks.sh ~/Downloads/bcprov-jdk18on-1.78.1.jar"
22+
exit 1
23+
fi
24+
25+
PROVIDER="$1"
26+
27+
if [ ! -f "$PROVIDER" ]; then
28+
echo "Error: Provider JAR not found: $PROVIDER"
29+
exit 1
30+
fi
31+
32+
convert () {
33+
if [ ! -f "${1}.jks" ]; then
34+
echo "Warning: ${1}.jks not found, skipping"
35+
return
36+
fi
37+
38+
rm -f "${1}.bks" 2>/dev/null
39+
keytool -importkeystore \
40+
-srckeystore "${1}.jks" \
41+
-destkeystore "${1}.bks" \
42+
-srcstoretype JKS \
43+
-deststoretype BKS \
44+
-srcstorepass "wolfsslpassword" \
45+
-deststorepass "wolfsslpassword" \
46+
-provider org.bouncycastle.jce.provider.BouncyCastleProvider \
47+
-providerpath "$PROVIDER"
48+
49+
if [ $? -eq 0 ]; then
50+
echo "Converted: ${1}.jks -> ${1}.bks"
51+
else
52+
echo "Error converting: ${1}.jks"
53+
fi
54+
}
55+
56+
echo "Converting JKS KeyStore files to BKS format..."
57+
echo ""
58+
59+
convert "ca-server-rsa-2048"
60+
convert "ca-server-ecc-256"
61+
62+
echo ""
63+
echo "Done."
64+

0 commit comments

Comments
 (0)