| 1 |
#!/bin/sh |
| 2 |
set -e |
| 3 |
|
| 4 |
pkg=secrecy |
| 5 |
|
| 6 |
export LC_ALL=C.UTF-8 |
| 7 |
if [ "${AUTOPKGTEST_TMP}" = "" ] ; then |
| 8 |
AUTOPKGTEST_TMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX) |
| 9 |
trap "rm -rf ${AUTOPKGTEST_TMP}" 0 INT QUIT ABRT PIPE TERM |
| 10 |
fi |
| 11 |
|
| 12 |
cd "${AUTOPKGTEST_TMP}" |
| 13 |
|
| 14 |
set -v |
| 15 |
################################################################################ |
| 16 |
# I. Test secrecy |
| 17 |
# 0. Preparation |
| 18 |
HOME="${AUTOPKGTEST_TMP}" |
| 19 |
export HOME |
| 20 |
cp -r /usr/share/doc/secrecy/* . |
| 21 |
gunzip *.gz |
| 22 |
readonly GPGID="[email protected]" |
| 23 |
readonly EXPIRY="$(date +'%F' -d 'tomorrow + 1 hour')" |
| 24 |
gpg --batch --pinentry-mode loopback --passphrase '' \ |
| 25 |
--quick-generate-key "$GPGID" default default "$EXPIRY" |
| 26 |
|
| 27 |
# 1. Create key |
| 28 |
readonly KEYNAME="autpkgtest_key" |
| 29 |
readonly KEYHASH="$( secrecy createKey AES256 "$GPGID" "$KEYNAME")" |
| 30 |
secrecy listKeys |
| 31 |
|
| 32 |
# 2. Encrypt files |
| 33 |
secrecy encrypt "$KEYNAME" < changelog > changelog.ciphered |
| 34 |
secrecy encrypt "$KEYHASH" < copyright > copyright.ciphered |
| 35 |
|
| 36 |
# 3. Decrypt files |
| 37 |
secrecy decrypt < changelog.ciphered > changelog.deciphered |
| 38 |
secrecy decrypt < copyright.ciphered > copyright.deciphered |
| 39 |
# Make sure the cipher/decipher cycle did not affect the payload. |
| 40 |
diff changelog changelog.deciphered |
| 41 |
diff copyright copyright.deciphered |
| 42 |
|
| 43 |
# 4. Export key to share with [email protected] |
| 44 |
readonly GPGID2="[email protected]" |
| 45 |
gpg --batch --pinentry-mode loopback --passphrase '' \ |
| 46 |
--quick-gen-key "$GPGID2" default default "$EXPIRY" |
| 47 |
secrecy exportKey "$KEYHASH" "$GPGID2" > exported_key.txt |
| 48 |
|
| 49 |
# 5. Import key |
| 50 |
# Destroy the initial secrecy key first, to make sure it is not used by |
| 51 |
# accident. |
| 52 |
rm -r "${HOME}/.libsecrecy" |
| 53 |
secrecy importKey "$GPGID2" < exported_key.txt |
| 54 |
secrecy listKeys |
| 55 |
|
| 56 |
################################################################################ |
| 57 |
# II. Test libsecrecy-dev |
| 58 |
# 0. Preparation |
| 59 |
CXXFLAGS="$( pkg-config libsecrecy --cflags )" |
| 60 |
LDFLAGS="$( pkg-config libsecrecy --libs )" |
| 61 |
export CXXFLAGS LDFLAGS |
| 62 |
printf -- 'CXXFLAGS=%s\nLDFLAGS=%s\n' "$CXXFLAGS" "$LDFLAGS" |
| 63 |
|
| 64 |
# 1. Encryption program |
| 65 |
cat > encrypt.cpp <<-END |
| 66 |
#include <libsecrecy/GCMOutputStream.hpp> |
| 67 |
#include <iostream> |
| 68 |
|
| 69 |
int main() |
| 70 |
{ |
| 71 |
std::string const scipher = "AES256"; |
| 72 |
std::string const shexhash = "$KEYHASH"; |
| 73 |
static std::size_t const buffersize = 16*1024; |
| 74 |
libsecrecy::GCMOutputStream GOS(std::cout, shexhash); |
| 75 |
char B[buffersize]; |
| 76 |
|
| 77 |
while ( std::cin ) |
| 78 |
{ |
| 79 |
std::cin.read(&B[0],buffersize); |
| 80 |
GOS.write(&B[0],std::cin.gcount()); |
| 81 |
} |
| 82 |
} |
| 83 |
END |
| 84 |
CXX="g++" |
| 85 |
"$CXX" $CXXFLAGS -c encrypt.cpp -o encrypt.o |
| 86 |
"$CXX" $CXXFLAGS encrypt.o -o encrypt $LDFLAGS |
| 87 |
./encrypt < changelog > changelog.ciphered |
| 88 |
./encrypt < copyright > copyright.ciphered |
| 89 |
CXX="clang++" |
| 90 |
"$CXX" $CXXFLAGS -c encrypt.cpp -o encrypt.o |
| 91 |
"$CXX" $CXXFLAGS encrypt.o -o encrypt $LDFLAGS |
| 92 |
./encrypt < changelog > changelog.ciphered |
| 93 |
./encrypt < copyright > copyright.ciphered |
| 94 |
|
| 95 |
# 2. Decryption program |
| 96 |
cat > decrypt.cpp <<-END |
| 97 |
#include <libsecrecy/GCMInputStream.hpp> |
| 98 |
#include <iostream> |
| 99 |
|
| 100 |
int main() |
| 101 |
{ |
| 102 |
libsecrecy::GCMInputStream GIS(std::cin); |
| 103 |
static std::size_t const buffersize = 16*1024; |
| 104 |
char B[buffersize]; |
| 105 |
|
| 106 |
while ( GIS ) |
| 107 |
{ |
| 108 |
GIS.read(&B[0],buffersize); |
| 109 |
std::cout.write(&B[0],GIS.gcount()); |
| 110 |
} |
| 111 |
} |
| 112 |
END |
| 113 |
CXX="g++" |
| 114 |
"$CXX" $CXXFLAGS -c decrypt.cpp -o decrypt.o |
| 115 |
"$CXX" $CXXFLAGS decrypt.o -o decrypt $LDFLAGS |
| 116 |
./decrypt < changelog.ciphered > changelog.deciphered |
| 117 |
./decrypt < copyright.ciphered > copyright.deciphered |
| 118 |
# Make sure the cipher/decipher cycle did not affect the payload. |
| 119 |
diff changelog changelog.deciphered |
| 120 |
diff copyright copyright.deciphered |
| 121 |
CXX="clang++" |
| 122 |
"$CXX" $CXXFLAGS -c decrypt.cpp -o decrypt.o |
| 123 |
"$CXX" $CXXFLAGS decrypt.o -o decrypt $LDFLAGS |
| 124 |
./decrypt < changelog.ciphered > changelog.deciphered |
| 125 |
./decrypt < copyright.ciphered > copyright.deciphered |
| 126 |
# Make sure the cipher/decipher cycle did not affect the payload. |
| 127 |
diff changelog changelog.deciphered |
| 128 |
diff copyright copyright.deciphered |
| 129 |
|
| 130 |
################################################################################ |