-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ondrej Moris <[email protected]>
- Loading branch information
Showing
3 changed files
with
67 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
# Copyright (C) 2024 Ondrej Moris <[email protected]> | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# shellcheck disable=SC1091 | ||
source "../helpers.sh" | ||
|
||
BASEDIR=$PWD | ||
|
@@ -20,7 +21,7 @@ install_dependencies() | |
elif [ "$FEDORA_VERSION" -eq 39 ]; then | ||
releasever="--releasever=40" | ||
fi | ||
dnf install -y $releasever --skip-broken \ | ||
dnf install -y "$releasever" --skip-broken \ | ||
autoconf automake autoconf-archive libtool \ | ||
p11-kit httpd mod_ssl openssl-devel gnutls-utils nss-tools \ | ||
p11-kit-devel p11-kit-server opensc softhsm-devel procps-ng \ | ||
|
@@ -43,7 +44,7 @@ softhsm_token_setup() | |
|
||
title SECTION "List token content" | ||
TOKENURL=$(p11tool --list-token-urls | grep "softhsm") | ||
p11tool --login --set-pin $PIN --list-all $TOKENURL | ||
p11tool --login --set-pin "$PIN" --list-all "$TOKENURL" | ||
title ENDSECTION | ||
} | ||
|
||
|
@@ -58,26 +59,27 @@ pkcs11_provider_setup() | |
fi | ||
echo "Skipped (running in Github Actions)" | ||
else | ||
git clone ${GIT_URL:-"https://github.com/latchset/pkcs11-provider.git"} \ | ||
${WORKDIR}/pkcs11-provider | ||
pushd $WORKDIR/pkcs11-provider | ||
git checkout ${GIT_REF:-"main"} | ||
git clone \ | ||
"${GIT_URL:-"https://github.com/latchset/pkcs11-provider.git"}" \ | ||
"${WORKDIR}"/pkcs11-provider | ||
pushd "${WORKDIR}"/pkcs11-provider | ||
git checkout "${GIT_REF:-"main"}" | ||
autoreconf -fiv | ||
./configure --libdir=/usr/lib64 | ||
make | ||
make install | ||
popd | ||
export PKCS11_MODULE=/usr/lib64/ossl-modules/pkcs11.so | ||
fi | ||
test -e $PKCS11_MODULE | ||
test -e "$PKCS11_MODULE" | ||
} | ||
|
||
p11kit_server_setup() | ||
{ | ||
title PARA "Proxy module driver through p11-kit server" | ||
|
||
export XDG_RUNTIME_DIR=$PWD | ||
eval $(p11-kit server --provider $PKCS11_PROVIDER_MODULE "pkcs11:") | ||
eval "$(p11-kit server --provider "$PKCS11_PROVIDER_MODULE" "pkcs11:")" | ||
test -n "$P11_KIT_SERVER_PID" | ||
export PKCS11_PROVIDER_MODULE="/usr/lib64/pkcs11/p11-kit-client.so" | ||
} | ||
|
@@ -92,35 +94,35 @@ openssl_setup() | |
-e "s|\(\[default_sect\]\)|module = $PKCS11_MODULE\n\1|" \ | ||
-e "s|\(\[default_sect\]\)|pkcs11-module-load-behavior = early\n\1|" \ | ||
-e "s|\(\[default_sect\]\)|activate = 1\n\n\1|" \ | ||
/etc/pki/tls/openssl.cnf >${WORKDIR}/openssl.cnf | ||
/etc/pki/tls/openssl.cnf >"${WORKDIR}"/openssl.cnf | ||
|
||
title SECTION "openssl.cnf" | ||
cat ${WORKDIR}/openssl.cnf | ||
cat "${WORKDIR}"/openssl.cnf | ||
title ENDSECTION | ||
} | ||
|
||
bind_setup() | ||
{ | ||
title PARA "Bind setup" | ||
|
||
cp /var/named/named.localhost ${WORKDIR}/localhost | ||
cp /var/named/named.localhost "${WORKDIR}"/localhost | ||
} | ||
|
||
bind_test() | ||
{ | ||
title PARA "Bind test" | ||
|
||
TOKENURL=$(p11tool --list-token-urls | grep "softhsm") | ||
KSKURL="$(p11tool --login --set-pin $PIN --list-keys $TOKENURL \ | ||
KSKURL="$(p11tool --login --set-pin "$PIN" --list-keys "$TOKENURL" \ | ||
| grep 'URL:.*object=localhost-ksk' \ | ||
| awk '{ print $NF }' \ | ||
| sed "s/type=.*\$/pin-value=$PIN/")" | ||
ZSKURL="$(p11tool --login --set-pin $PIN --list-keys $TOKENURL \ | ||
ZSKURL="$(p11tool --login --set-pin "$PIN" --list-keys "$TOKENURL" \ | ||
| grep 'URL:.*object=localhost-zsk' \ | ||
| awk '{ print $NF }' \ | ||
| sed "s/type=.*\$/pin-value=$PIN/")" | ||
|
||
pushd $WORKDIR | ||
pushd "$WORKDIR" | ||
|
||
title PARA "Test 1: Extract KSK and ZSK keys from PKCS11 URIs" | ||
PKCS11_PROVIDER_DEBUG=file:${PKCS11_DEBUG_FILE}.extract \ | ||
|
@@ -130,15 +132,15 @@ bind_test() | |
OPENSSL_CONF=openssl.cnf \ | ||
dnssec-keyfromlabel -a RSASHA256 -l "$KSKURL" -f KSK localhost | ||
for K in *.key; do | ||
cat $K >>localhost | ||
cat "$K" >>localhost | ||
done | ||
test -s ${PKCS11_DEBUG_FILE}.extract | ||
test -s "${PKCS11_DEBUG_FILE}".extract | ||
|
||
title PARA "Test 2: Sign zone" | ||
PKCS11_PROVIDER_DEBUG=file:${PKCS11_DEBUG_FILE}.sign \ | ||
OPENSSL_CONF=openssl.cnf \ | ||
dnssec-signzone -o localhost localhost | ||
test -s ${PKCS11_DEBUG_FILE}.sign | ||
test -s "${PKCS11_DEBUG_FILE}".sign | ||
|
||
popd | ||
echo "Test passed" | ||
|
@@ -148,14 +150,14 @@ cleanup() | |
{ | ||
title PARA "Clean-up" | ||
|
||
for L in ${PKCS11_DEBUG_FILE}.*; do | ||
for L in "${PKCS11_DEBUG_FILE}".*; do | ||
title SECTION "$L" | ||
cat $L | ||
cat "$L" | ||
title ENDSECTION | ||
done | ||
|
||
pushd $BASEDIR >/dev/null | ||
rm -rf $WORKDIR | ||
pushd "$BASEDIR" >/dev/null | ||
rm -rf "$WORKDIR" | ||
if [ -e /var/lib/softhsm/tokens.bck ]; then | ||
rm -rf /var/lib/softhsm/tokens | ||
mv /var/lib/softhsm/tokens.bck /var/lib/softhsm/tokens | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
# Copyright (C) 2024 Ondrej Moris <[email protected]> | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# shellcheck disable=SC1091 | ||
source "../helpers.sh" | ||
|
||
BASEDIR=$PWD | ||
|
@@ -22,7 +23,7 @@ install_dependencies() | |
elif [ "$FEDORA_VERSION" -eq 39 ]; then | ||
releasever="--releasever=40" | ||
fi | ||
dnf install -y $releasever --skip-broken \ | ||
dnf install -y "$releasever" --skip-broken \ | ||
autoconf automake autoconf-archive libtool \ | ||
p11-kit httpd mod_ssl openssl-devel gnutls-utils nss-tools \ | ||
p11-kit-devel p11-kit-server opensc softhsm-devel procps-ng \ | ||
|
@@ -33,15 +34,15 @@ softhsm_token_setup() | |
{ | ||
title PARA "Softhsm token setup" | ||
|
||
pushd $WORKDIR | ||
pushd "$WORKDIR" | ||
mkdir ca server | ||
openssl req -x509 -sha256 -newkey rsa:2048 -noenc -batch \ | ||
-keyout ca/key.pem -out ca/cert.pem | ||
openssl req -newkey rsa:2048 -subj '/CN=localhost' -noenc -batch \ | ||
-keyout server/key.pem -out server/csr.pem | ||
openssl x509 -req -CA ca/cert.pem -CAkey ca/key.pem \ | ||
-in server/csr.pem -out server/cert.pem -CAcreateserial | ||
chown -R apache:apache $WORKDIR | ||
chown -R apache:apache "$WORKDIR" | ||
|
||
usermod -a -G ods apache | ||
cp -rnp /var/lib/softhsm/tokens{,.bck} | ||
|
@@ -54,20 +55,20 @@ softhsm_token_setup() | |
--label httpd \ | ||
--id=%01 \ | ||
--login \ | ||
--set-pin $PIN $TOKENURL | ||
--set-pin "$PIN" "$TOKENURL" | ||
runuser -u apache -- p11tool \ | ||
--write \ | ||
--load-certificate server/cert.pem \ | ||
--label httpd \ | ||
--id=%01 \ | ||
--login \ | ||
--set-pin $PIN $TOKENURL | ||
--set-pin "$PIN" "$TOKENURL" | ||
popd | ||
|
||
export PKCS11_PROVIDER_MODULE="/usr/lib64/pkcs11/libsofthsm2.so" | ||
|
||
title SECTION "List token content" | ||
p11tool --login --set-pin $PIN --list-all $TOKENURL | ||
p11tool --login --set-pin "$PIN" --list-all "$TOKENURL" | ||
title ENDSECTION | ||
} | ||
|
||
|
@@ -83,36 +84,37 @@ pkcs11_provider_setup() | |
fi | ||
echo "Skipped (running in Github Actions)" | ||
else | ||
git clone ${GIT_URL:-"https://github.com/latchset/pkcs11-provider.git"} \ | ||
${WORKDIR}/pkcs11-provider | ||
pushd $WORKDIR/pkcs11-provider | ||
git checkout ${GIT_REF:-"main"} | ||
git clone \ | ||
"${GIT_URL:-"https://github.com/latchset/pkcs11-provider.git"}" \ | ||
"${WORKDIR}"/pkcs11-provider | ||
pushd "$WORKDIR"/pkcs11-provider | ||
git checkout "${GIT_REF:-"main"}" | ||
autoreconf -fiv | ||
./configure --libdir=/usr/lib64 | ||
make | ||
make install | ||
popd | ||
export PKCS11_MODULE=/usr/lib64/ossl-modules/pkcs11.so | ||
fi | ||
test -e $PKCS11_MODULE | ||
test -e "$PKCS11_MODULE" | ||
} | ||
|
||
openssl_setup() | ||
{ | ||
title PARA "OpenSSL setup" | ||
|
||
echo "$PIN" >$PIN_FILE | ||
echo "$PIN" >"$PIN_FILE" | ||
sed \ | ||
-e "s|\(default = default_sect\)|\1\npkcs11 = pkcs11_sect\n|" \ | ||
-e "s|\(\[default_sect\]\)|\[pkcs11_sect\]\n\1|" \ | ||
-e "s|\(\[default_sect\]\)|module = $PKCS11_MODULE\n\1|" \ | ||
-e "s|\(\[default_sect\]\)|pkcs11-module-load-behavior = early\n\1|" \ | ||
-e "s|\(\[default_sect\]\)|pkcs11-module-token-pin = file:$PIN_FILE\n\1|" \ | ||
-e "s|\(\[default_sect\]\)|activate = 1\n\n\1|" \ | ||
/etc/pki/tls/openssl.cnf >${WORKDIR}/openssl.cnf | ||
/etc/pki/tls/openssl.cnf >"${WORKDIR}"/openssl.cnf | ||
|
||
title SECTION "openssl.cnf" | ||
cat ${WORKDIR}/openssl.cnf | ||
cat "${WORKDIR}"/openssl.cnf | ||
title ENDSECTION | ||
} | ||
|
||
|
@@ -121,10 +123,10 @@ httpd_setup() | |
title PARAM "Httpd setup" | ||
|
||
TOKENURL=$(p11tool --list-token-urls | grep "softtoken") | ||
KEYURL="$(p11tool --login --set-pin $PIN --list-keys $TOKENURL \ | ||
KEYURL="$(p11tool --login --set-pin "$PIN" --list-keys "$TOKENURL" \ | ||
| grep 'URL:.*object=httpd;type=private' \ | ||
| awk '{ print $NF }')?pin-value=$PIN" | ||
CERTURL=$(p11tool --list-all-certs $TOKENURL \ | ||
CERTURL=$(p11tool --list-all-certs "$TOKENURL" \ | ||
| grep "URL:.*object=httpd;type=cert" \ | ||
| awk '{ print $NF }') | ||
|
||
|
@@ -155,34 +157,35 @@ httpd_test() | |
|
||
title PARA "Test 2: Curl connects to httpd over TLS" | ||
PKCS11_PROVIDER_DEBUG=file:${PKCS11_DEBUG_FILE}.curl \ | ||
curl -v -sS --cacert ${WORKDIR}/ca/cert.pem https://localhost >/dev/null | ||
curl -v -sS --cacert "${WORKDIR}"/ca/cert.pem https://localhost >/dev/null | ||
|
||
echo "Test passed" | ||
} | ||
|
||
# shellcheck disable=SC2317 | ||
cleanup() | ||
{ | ||
title PARA "Clean-up" | ||
|
||
for L in ${PKCS11_DEBUG_FILE}.*; do | ||
for L in "${PKCS11_DEBUG_FILE}".*; do | ||
title SECTION "$L" | ||
cat $L | ||
cat "$L" | ||
title ENDSECTION | ||
done | ||
ssl_log="/var/log/httpd/ssl_error_log" | ||
if [ -e $ssl_log ]; then | ||
if [ -e "$ssl_log" ]; then | ||
title SECTION "$ssl_log" | ||
cat $ssl_log | ||
cat "$ssl_log" | ||
title ENDSECTION | ||
fi | ||
|
||
pushd $BASEDIR >/dev/null | ||
rm -rf $WORKDIR | ||
pushd "$BASEDIR" >/dev/null | ||
rm -rf "$WORKDIR" | ||
if pgrep httpd >/dev/null; then | ||
pkill httpd | ||
fi | ||
if [ -e ${MOD_SSL_CONF}.bck ]; then | ||
mv ${MOD_SSL_CONF}.bck $MOD_SSL_CONF | ||
if [ -e "${MOD_SSL_CONF}".bck ]; then | ||
mv "${MOD_SSL_CONF}".bck "$MOD_SSL_CONF" | ||
fi | ||
if [ -e /var/lib/softhsm/tokens.bck ]; then | ||
rm -rf /var/lib/softhsm/tokens | ||
|
@@ -203,5 +206,3 @@ httpd_setup | |
|
||
# Test. | ||
httpd_test | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
# Copyright (C) 2024 Ondrej Moris <[email protected]> | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# shellcheck disable=SC1091 | ||
source "../helpers.sh" | ||
|
||
BASEDIR=$PWD | ||
|
@@ -30,36 +31,37 @@ pkcs11_provider_setup() | |
exit 1 | ||
fi | ||
else | ||
git clone ${GIT_URL:-"https://github.com/latchset/pkcs11-provider.git"} \ | ||
${WORKDIR}/pkcs11-provider | ||
pushd $WORKDIR/pkcs11-provider | ||
git checkout ${GIT_REF:-"main"} | ||
git clone \ | ||
"${GIT_URL:-"https://github.com/latchset/pkcs11-provider.git"}" \ | ||
"${WORKDIR}"/pkcs11-provider | ||
pushd "$WORKDIR"/pkcs11-provider | ||
git checkout "${GIT_REF:-"main"}" | ||
autoreconf -fiv | ||
./configure --libdir=/usr/lib64 | ||
make | ||
make install | ||
popd | ||
export PKCS11_MODULE=/usr/lib64/ossl-modules/pkcs11.so | ||
fi | ||
test -e $PKCS11_MODULE | ||
test -e "$PKCS11_MODULE" | ||
} | ||
|
||
libssh_setup() | ||
{ | ||
title PRAM "Clone, setup and build libssh" | ||
|
||
git clone https://gitlab.com/libssh/libssh-mirror.git \ | ||
${WORKDIR}/libssh-mirror | ||
"${WORKDIR}"/libssh-mirror | ||
|
||
mkdir ${WORKDIR}/libssh-mirror/build | ||
pushd ${WORKDIR}/libssh-mirror/build | ||
mkdir "${WORKDIR}"/libssh-mirror/build | ||
pushd "${WORKDIR}"/libssh-mirror/build | ||
cmake \ | ||
-DUNIT_TESTING=ON \ | ||
-DCLIENT_TESTING=ON \ | ||
-DCMAKE_BUILD_TYPE=Debug \ | ||
-DWITH_PKCS11_URI=ON \ | ||
-DWITH_PKCS11_PROVIDER=ON \ | ||
-DPKCS11_PROVIDER=${PKCS11_MODULE} .. | ||
-DPKCS11_PROVIDER="${PKCS11_MODULE}" .. | ||
make | ||
popd | ||
} | ||
|
@@ -68,7 +70,7 @@ libssh_test() | |
{ | ||
title PARAM "Run libssh pkcs11 tests" | ||
|
||
pushd ${WORKDIR}/libssh-mirror/build | ||
pushd "${WORKDIR}"/libssh-mirror/build | ||
PKCS11_PROVIDER_DEBUG=file:$PKCS11_DEBUG_FILE ctest \ | ||
--output-on-failure -R \ | ||
'(torture_auth_pkcs11|torture_pki_rsa_uri|torture_pki_ecdsa_uri)' \ | ||
|
@@ -80,16 +82,17 @@ libssh_test() | |
popd | ||
} | ||
|
||
# shellcheck disable=SC2317 | ||
cleanup() | ||
{ | ||
title PARA "Clean-up" | ||
|
||
title SECTION "$PKCS11_DEBUG_FILE" | ||
cat $PKCS11_DEBUG_FILE | ||
cat "$PKCS11_DEBUG_FILE" | ||
title ENDSECTION | ||
|
||
pushd $BASEDIR >/dev/null | ||
rm -rf $WORKDIR | ||
pushd "$BASEDIR" >/dev/null | ||
rm -rf "$WORKDIR" | ||
|
||
title LINE "Done" | ||
} | ||
|