<commit_before>#! /bin/bash
set -euo pipefail

SCRIPT_DIR="$(dirname "$0")"
DATA_DIR="${SCRIPT_DIR}/../tests/test_data"

TOKEN_DIR=${TOKEN_DIR:-/var/lib/softhsm/tokens}
SOFTHSM2_CONF=${SOFTHSM2_CONF:-/etc/softhsm/softhsm2.conf}
sed -i "s:^directories\.tokendir = .*$:directories.tokendir = ${TOKEN_DIR}:" "${SOFTHSM2_CONF}"

mkdir -p "${TOKEN_DIR}"
softhsm2-util --init-token --slot 0 --label "Virtual token" --pin 1234 --so-pin 1234
SLOT=$(softhsm2-util --show-slots | grep -m 1 -oP 'Slot \K[0-9]+')
echo "Initialized token in slot: $SLOT"
softhsm2-util --import "${DATA_DIR}/implicit/pkey.pem" --label "pkey" --id 02 --slot "$SLOT" --pin 1234
openssl x509 -outform der -in "${DATA_DIR}/implicit/client.pem" -out "${DATA_DIR}/implicit/client.der"
pkcs11-tool --module=/usr/lib/softhsm/libsofthsm2.so --id 1 --write-object "${DATA_DIR}/implicit/client.der" --type cert --login --pin 1234

openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in "${DATA_DIR}/priv.key" -out "${DATA_DIR}/priv.p8"
softhsm2-util --import "${DATA_DIR}/priv.p8" --label "uptane" --id 03 --slot "$SLOT" --pin 1234<commit_msg>Create temp files in a temp dir in setup_hsm.sh<commit_after>#! /bin/bash
set -euo pipefail

SCRIPT_DIR="$(dirname "$0")"
DATA_DIR="${SCRIPT_DIR}/../tests/test_data"

TOKEN_DIR=${TOKEN_DIR:-/var/lib/softhsm/tokens}
SOFTHSM2_CONF=${SOFTHSM2_CONF:-/etc/softhsm/softhsm2.conf}
sed -i "s:^directories\\.tokendir = .*$:directories.tokendir = ${TOKEN_DIR}:" "${SOFTHSM2_CONF}"

TMPDIR="$(mktemp -d)"
function finish {
    rm -rf "${TMPDIR}"
}
trap finish EXIT

mkdir -p "${TOKEN_DIR}"
softhsm2-util --init-token --slot 0 --label "Virtual token" --pin 1234 --so-pin 1234
SLOT=$(softhsm2-util --show-slots | grep -m 1 -oP 'Slot \K[0-9]+')
echo "Initialized token in slot: $SLOT"
softhsm2-util --import "${DATA_DIR}/implicit/pkey.pem" --label "pkey" --id 02 --slot "$SLOT" --pin 1234
openssl x509 -outform der -in "${DATA_DIR}/implicit/client.pem" -out "${TMPDIR}/implicit_client.der"
pkcs11-tool --module=/usr/lib/softhsm/libsofthsm2.so --id 1 --write-object "${TMPDIR}/implicit_client.der" --type cert --login --pin 1234

openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in "${DATA_DIR}/priv.key" -out "${TMPDIR}/priv.p8"
softhsm2-util --import "${TMPDIR}/priv.p8" --label "uptane" --id 03 --slot "$SLOT" --pin 1234
{'fraction_non_alphanumeric': 0.20301724137931035, 'fraction_numerical': 0.041379310344827586, 'mean_word_length': 4.0456521739130435, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2056913', 'n_tokens_mistral': 1017, 'n_tokens_neox': 961, 'n_words': 211}