SmartPGP/.github/workflows/main.yml
Ryad Benadjila 0b43929a83 Add CI/CD tests using Github Actions.
The tests compile and run the applet in the jcardsim Javacard simulator.
ECDSA signature tests are performed using OpenPGPpy, other tests such as
AES are performed using the local bin/smartpgp-cli script.

TODO: add tests for RSA, asymmetric encryption, pin modifications, secure
messaging (if well supported by jcardsim), etc.
2022-01-10 16:40:35 +01:00

70 lines
3.8 KiB
YAML

name: smartgpg-test-applet
# Run this workflow every time a new commit pushed to your repository
on: push
jobs:
applet_tests:
runs-on: ubuntu-18.04
steps:
# Checkout repository
- name: checkout repository
uses: actions/checkout@v2
# Run actions
# Compilation tests
- name: applet tests
shell: bash
run: |
# 1) Get dependencies
sudo apt-get install -y --no-install-recommends procps autoconf automake libtool m4 pkg-config help2man make gcc ant automake autotools-dev sudo wget gnupg software-properties-common maven git pcscd libpcsclite-dev opensc;
# 2) Get JDK
wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | sudo apt-key add -;
sudo add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/;
sudo apt-get update && sudo apt-get install --reinstall adoptopenjdk-8-hotspot;
sudo update-java-alternatives -s adoptopenjdk-8-hotspot-amd64;
# 3) Get Javacard SDKs
git clone https://github.com/martinpaljak/oracle_javacard_sdks && mv oracle_javacard_sdks/jc305u3_kit/ /tmp/ && rm -rf oracle_javacard_sdks;
# 4) Compile our applet
cat build.xml | sed 's/<cap /<cap export="SmartPGPApplet" /' > /tmp/build.xml && mv /tmp/build.xml ./; # export jar for simulator
JC_HOME=/tmp/jc305u3_kit/ ant;
# 5) Clone jcardsim repository, compile and install
git clone https://github.com/licel/jcardsim && cd jcardsim && git fetch origin pull/155/head:pr155 && git config --global user.name "John Doe" && git merge pr155 -m "AA" && cd -;
# Patch random
cd jcardsim && patch -p1 < ../.github/workflows/jcardsim_patches/jcardsim_random_patch && cd -;
# Compile
cd jcardsim && export JC_CLASSIC_HOME=/tmp/jc305u3_kit/ && mvn initialize && mvn clean install && cd -;
# 7) Clone vsmartcard, compile and install
git clone https://github.com/frankmorgner/vsmartcard.git;
cd vsmartcard/virtualsmartcard && autoreconf --verbose --install && ./configure --sysconfdir=/etc && make && sudo make install && cd -;
# 8) (re)Launch PCSCD
sudo killall pcscd && sudo pcscd -fad &>/tmp/log_pcsc & echo "PCSCD launched";
sleep 2;
# 9) launch jcardsim
java -cp jcardsim/target/jcardsim-3.0.5-SNAPSHOT.jar:SmartPGPApplet/smartpgp.jar com.licel.jcardsim.remote.VSmartCard .github/workflows/smartpgp.cfg &>/tmp/log_jcardsim & echo "jcardsim launched!";
# Wait a bit for insertion
sleep 2;
echo "========= PCSCD log" && cat /tmp/log_pcsc;
echo "========= jcard sim log" && cat /tmp/log_jcardsim;
# 10) Test our applet
# Execute tests
sudo apt-get install -y python3-setuptools python3-pyscard python-setuptools python-pyscard python-pyasn1;
pip3 install OpenPGPpy;
# Install applet
opensc-tool -l;
opensc-tool -s 80b800001810d276000124010304AFAF000000000000050000020F0F00;
# Get card status
python3 .github/workflows/card-status.py;
# Test ECDSA signatures
python3 .github/workflows/test_SmartPGP.py;
# Reset
python3 .github/workflows/reset.py;
# Test crypto switch
python2 bin/example-set-mixed-crypto.py;
# Test AES
echo -n "AAAAAAAAAAAAAAAA" > /tmp/aes_key.bin;
python2 bin/smartpgp-cli put-aes-key -i /tmp/aes_key.bin;
echo -n "BBBBBBBBBBBBBBBB" > /tmp/aes_to_encrypt.bin;
python2 bin/smartpgp-cli encrypt-aes -p "123456" -i /tmp/aes_to_encrypt.bin -o /tmp/aes_encrypted.bin;
python2 bin/smartpgp-cli decrypt-aes -p "123456" -i /tmp/aes_encrypted.bin -o /tmp/aes_decrypted.bin;
diff /tmp/aes_decrypted.bin /tmp/aes_to_encrypt.bin;