Skip to content

Commit

Permalink
added BC jar files download via script, updated README_JCE
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Tjaden committed Jan 7, 2025
1 parent dbbf4f0 commit 11ad022
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 7 deletions.
17 changes: 11 additions & 6 deletions README_JCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,15 @@ This script requires for JAVA_HOME to be set.

For Bouncy Castle comparison testing:

CryptoBenchmark.sh will prompt with the following:

```
Would you like to download Bouncy Castle JARs? (y/n)
```
If you respond with 'y', the script will download the Bouncy Castle JARs and run the benchmark with Bouncy Castle. At the end of the benchmark, the script will prompt whether or not to remove the Bouncy Castle JAR files.

If you prefer to download the JARs manually, follow the instructions below:

Visit [bouncy-castle-java](https://www.bouncycastle.org/download/bouncy-castle-java/)
Download:
```
Expand All @@ -317,12 +326,8 @@ bctls-jdk18on-1.79.jar # Bouncy Castle DTLS/TLS API/JSSE Provider
```
Copy jar files to $JAVA_HOME/lib/ext/:
```
cp bcprov-jdk18on-1.79.jar $JAVA_HOME/lib/ext/
cp bctls-jdk18on-1.79.jar $JAVA_HOME/lib/ext/
```
Add Bouncy Castle as provider in java.security file:
```
echo "security.provider.X=org.bouncycastle.jce.provider.BouncyCastleProvider" >> $JAVA_HOME/lib/security/java.security
cp bcprov-jdk18on-1.79.jar wolfcrypt-jni/lib
cp bctls-jdk18on-1.79.jar wolfcrypt-jni/lib
```

### JAR Code Signing
Expand Down
90 changes: 89 additions & 1 deletion examples/provider/CryptoBenchmark.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,93 @@
#!/bin/bash

# Flag to track if we downloaded BC during this session
BC_DOWNLOADED=false

# Function to download Bouncy Castle JARs
download_bc_jars() {
local bc_version="1.79"
local lib_dir="../../../lib"
local bc_url="https://downloads.bouncycastle.org/java"

echo -n "Downloading Bouncy Castle JARs... "

# Create lib directory if it doesn't exist
mkdir -p "$lib_dir" 2>/dev/null

# Download both required JARs
if command -v wget >/dev/null; then
wget -q -P "$lib_dir" "$bc_url/bcprov-jdk18on-$bc_version.jar" 2>/dev/null &&
wget -q -P "$lib_dir" "$bc_url/bctls-jdk18on-$bc_version.jar" 2>/dev/null || return 1
elif command -v curl >/dev/null; then
curl -s -L -o "$lib_dir/bcprov-jdk18on-$bc_version.jar" "$bc_url/bcprov-jdk18on-$bc_version.jar" 2>/dev/null &&
curl -s -L -o "$lib_dir/bctls-jdk18on-$bc_version.jar" "$bc_url/bctls-jdk18on-$bc_version.jar" 2>/dev/null || return 1
else
echo "failed"
echo "Error: Neither wget nor curl is available. Please install either wget or curl."
return 1
fi

# Verify downloads were successful
if [ -f "$lib_dir/bcprov-jdk18on-$bc_version.jar" ] && [ -f "$lib_dir/bctls-jdk18on-$bc_version.jar" ]; then
echo "done"
BC_DOWNLOADED=true
return 0
else
echo "failed"
return 1
fi
}

# Function to cleanup BC JARs
cleanup_bc_jars() {
local lib_dir="../../../lib"
echo -n "Removing Bouncy Castle JARs... "
rm -f "$lib_dir/bcprov-jdk18on-1.79.jar" "$lib_dir/bctls-jdk18on-1.79.jar" 2>/dev/null
if [ $? -eq 0 ]; then
echo "done"
return 0
else
echo "failed"
return 1
fi
}

cd ./examples/build/provider

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../../lib/:/usr/local/lib
java -classpath ../../../lib/wolfcrypt-jni.jar:./ -Dsun.boot.library.path=../../../lib/ CryptoBenchmark $@

CLASSPATH="../../../lib/wolfcrypt-jni.jar:."

if [ -f "../../../lib/bcprov-jdk18on-1.79.jar" ] && [ -f "../../../lib/bctls-jdk18on-1.79.jar" ]; then
echo "Running crypto benchmark with Bouncy Castle"
CLASSPATH="$CLASSPATH:../../../lib/bcprov-jdk18on-1.79.jar:../../../lib/bctls-jdk18on-1.79.jar"
else
echo "Bouncy Castle JARs not found in lib directory"
read -p "Would you like to download Bouncy Castle JARs? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
if download_bc_jars; then
echo "Running crypto benchmark with Bouncy Castle"
CLASSPATH="$CLASSPATH:../../../lib/bcprov-jdk18on-1.79.jar:../../../lib/bctls-jdk18on-1.79.jar"
else
echo "Running crypto benchmark without Bouncy Castle due to download failure"
fi
else
echo "Running crypto benchmark without Bouncy Castle"
fi
fi

# Run the benchmark
java -classpath $CLASSPATH -Dsun.boot.library.path=../../../lib/ CryptoBenchmark $@

# After benchmark completion, ask about cleanup if we downloaded the files
if [ "$BC_DOWNLOADED" = true ]; then
echo
read -p "Would you like to remove the downloaded Bouncy Castle JARs? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
cleanup_bc_jars
else
echo "Keeping Bouncy Castle JARs for future use"
fi
fi

0 comments on commit 11ad022

Please sign in to comment.