From 1f8aa5fc4c17f829c91bf1dabe384baa19207715 Mon Sep 17 00:00:00 2001 From: Heiko Reese Date: Sat, 11 Sep 2021 02:46:32 +0200 Subject: [PATCH] Added test fo password decryption command --- src/meson.build | 6 ++-- ...ibexim-encrypt-dlfunc-decrypt-secretbox.sh | 31 +++++++++++++++++++ src/test_libexim-encrypt-dlfunc.sh | 2 +- 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100755 src/test_libexim-encrypt-dlfunc-decrypt-secretbox.sh diff --git a/src/meson.build b/src/meson.build index 86f24f0..5d72b45 100644 --- a/src/meson.build +++ b/src/meson.build @@ -16,6 +16,8 @@ shared_library('exim-encrypt-dlfunc', 'libexim-encrypt-dlfunc.c', dependencies : [ sodium_deps ], install: true) -simple_exim_test = find_program('test_libexim-encrypt-dlfunc.sh') -test('simple test', simple_exim_test) +dlfunc_test = find_program('test_libexim-encrypt-dlfunc.sh') +test('simple test', dlfunc_test) +decrypt_secretbox_test = find_program('test_libexim-encrypt-dlfunc-decrypt-secretbox.sh') +test('decrypt-secretbox', decrypt_secretbox_test) \ No newline at end of file diff --git a/src/test_libexim-encrypt-dlfunc-decrypt-secretbox.sh b/src/test_libexim-encrypt-dlfunc-decrypt-secretbox.sh new file mode 100755 index 0000000..c67310f --- /dev/null +++ b/src/test_libexim-encrypt-dlfunc-decrypt-secretbox.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# shellcheck disable=SC2034 + +set -e + +PATH=/sbin:/usr/sbin:$PATH + +TEST_PASSWORD='ThisIsAPassword' +TEST_CLEARTEXT='This is my cleartext' +TEST_CIPHERTEXT01='RCHI+VukmWIsVE3eixbWIAtPPBW63nmV1ITpSBEDYXC9Y5QMBd1zmGLLhE+S9yg0sHfOF/1+wmfF7YXv' +TEST_CIPHERTEXT02='sEG09WnEKIN2nyJYGNNVo14o7wV6X9HQxW+zxAxMLX9jVdashdaoHqLXQGM8lzpJhG6629lccjzAfrq8' + +LIBEXIM_PASSWORD="${TEST_PASSWORD}" +DECRYPTED01="$(src/libexim-encrypt-dlfunc-decrypt-secretbox ${TEST_CIPHERTEXT01})" + +if [ "${DECRYPTED01}" == "${TEST_CLEARTEXT}" ] ; then + echo "decryption with password from environment successful" +else + echo "decryption with password from environment unsuccessful" + exit 127 +fi + +unset LIBEXIM_PASSWORD +DECRYPTED02="$(src/libexim-encrypt-dlfunc-decrypt-secretbox -p ${TEST_PASSWORD} ${TEST_CIPHERTEXT02})" + +if [ "${DECRYPTED02}" == "${TEST_CLEARTEXT}" ] ; then + echo "decryption with password from commandline successful" +else + echo "decryption with password from commandline unsuccessful" + exit 128 +fi \ No newline at end of file diff --git a/src/test_libexim-encrypt-dlfunc.sh b/src/test_libexim-encrypt-dlfunc.sh index cf5acff..87ea4d2 100755 --- a/src/test_libexim-encrypt-dlfunc.sh +++ b/src/test_libexim-encrypt-dlfunc.sh @@ -9,7 +9,7 @@ install -t /tmp src/libexim-encrypt-dlfunc.so LIB=/tmp/libexim-encrypt-dlfunc.so CLEARTEXT="127.88.99.23" # keep short; see above -PASSWORD="`openssl rand -base64 32`" +PASSWORD="$(openssl rand -base64 32)" CIPHERTEXT=$(exim -be "\${dlfunc{${LIB}}{sodium_crypto_secretbox_encrypt_password}{${PASSWORD}}{${CLEARTEXT}}}") DECRYPTED=$(exim -be "\${dlfunc{${LIB}}{sodium_crypto_secretbox_decrypt_password}{${PASSWORD}}{${CIPHERTEXT}}}")