Skip to content

Commit

Permalink
Run one analysis at a time using CLI args
Browse files Browse the repository at this point in the history
  • Loading branch information
xuganyu96 committed Dec 11, 2023
1 parent c672bc7 commit 1a35b6e
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 11 deletions.
8 changes: 6 additions & 2 deletions marvin-toolkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ This document describes the procedure for replicating the analysis for the Marvi

```bash
docker build -t marvin:latest .
docker run -d --rm --name marvin marvin:latest
```
docker run -d --rm \
--name marvin \
-v /path/to/keys:/home/rustcrypto/marvin-toolkit/keys \
-v /path/to/results:/home/rustcrypto/marvin-toolkit/results \
marvin:latest -h
```
92 changes: 83 additions & 9 deletions marvin-toolkit/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,94 @@ cd example/rust-crypto
cargo build --profile release
cd ~/marvin-toolkit

# Generate key pairs
./step1.sh
# Parse CLI inputs to $size and $repeat
size=2048
repeat=100000

# Function to display help message
display_help() {
echo "Usage: $0 [-s SIZE] [-n NUMBER] [-h]"
echo " -s SIZE Set the RSA key size (1024, 2048, or 4096; default: 2048)"
echo " -n NUMBER Set the repeat number (integer; default: 100000)"
echo " -h Display this help message"
}

# Parse command-line arguments using getopts
while getopts ":s:n:h" opt; do
case $opt in
s)
size=$OPTARG
if [[ ! "$size" =~ ^(1024|2048|4096)$ ]]; then
echo "Error: Invalid size. Please choose 1024, 2048, or 4096."
exit 1
fi
;;
n)
repeat=$OPTARG
if ! [[ "$repeat" =~ ^[0-9]+$ ]]; then
echo "Error: Invalid number. Please specify a valid integer."
exit 1
fi
;;
h)
display_help
exit 0
;;
\?)
echo "Error: Invalid option -$OPTARG"
display_help
exit 1
;;
:)
echo "Error: Option -$OPTARG requires an argument."
display_help
exit 1
;;
esac
done
size_bytes = $(($size / 8))

# Step 1: Generate key pairs
name="rsa${size}"
tmp_file="$(mktemp)"
if ! x509KeyGen -s $size $name &> "$tmp_file"; then
echo "ERROR $size bit key generation failed" >&2
cat "$tmp_file" >&2
exit 1
fi
if ! x509SelfSign $name &> "$tmp_file"; then
echo "ERROR: $size bit key self-signing failed" >&2
cat "$tmp_file" >&2
exit 1
fi

echo "RSA $size bit private key in old OpenSSL PEM format is in" $(x509Key $name)
echo "RSA $size bit private key in old OpenSSL DER format is in" $(x509Key --der $name)
echo "RSA $size bit private key in PKCS#8 PEM format is in" $(x509Key --pkcs8 $name)
echo "RSA $size bit private key in PKCS#8 DER format is in" $(x509Key --der --pkcs8 $name)
echo "RSA $size bit private key in PKCS#12 format is in" $(x509Key --with-cert --pkcs12 $name)
echo "RSA $size bit self-signed certificate is in" $(x509Cert $name)
mv rsa${size} keys # Keys generated under rsa${size}/
echo

# Generate ciphertexts
./step2-alt.sh
echo "Finished generating ciphertexts"
PYTHONPATH=tlsfuzzer ./marvin-venv/bin/python ./step2.py \
-c keys/cert.pem -o results \
--repeat 100000 --verbose \
no_structure no_padding=48 signature_padding=8 \
valid_repeated_byte_payload="246 0xff" \
valid_repeated_byte_payload="246 0x01" \
valid=48 header_only \
no_header_with_payload=48 zero_byte_in_padding="48 4" \
valid=0 valid=192 valid=246

# Run decryptions and analyze data
./example/rust-crypto/target/release/rust-crypto \
-i rsa2048_repeat/ciphers.bin \
-o rsa2048_repeat/raw_times.csv -k rsa2048/pkcs8.pem -n 256
-i results/ciphers.bin \
-o results/raw_times.csv -k keys/pkcs8.pem -n $size_bytes
PYTHONPATH=tlsfuzzer marvin-venv/bin/python3 tlsfuzzer/tlsfuzzer/extract.py \
-l rsa2048_repeat/log.csv --raw-times rsa2048_repeat/raw_times.csv \
-o rsa2048_repeat/ \
-l results/log.csv --raw-times results/raw_times.csv \
-o results/ \
--clock-frequency 1000
PYTHONPATH=tlsfuzzer marvin-venv/bin/python3 tlsfuzzer/tlsfuzzer/analysis.py \
-o rsa2048_repeat/ --verbose
-o results/ --verbose

0 comments on commit 1a35b6e

Please sign in to comment.