Changes in test/softhsm.bash [33af2b7:aeaf28b] in mod_gnutls


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/softhsm.bash

    r33af2b7 raeaf28b  
    1717    local label="${3}"
    1818
    19     p11tool --provider=${softhsm_lib} --login --write --label "${label}" \
     19    p11tool --provider=${SOFTHSM_LIB} --login --write --label "${label}" \
    2020            --load-privkey "${keyfile}" "${token}"
    2121}
     
    2828    local label="${3}"
    2929
    30     p11tool --provider=${softhsm_lib} --login --write --no-mark-private \
     30    p11tool --provider=${SOFTHSM_LIB} --login --write --no-mark-private \
    3131            --label "${label}" --load-certificate "${certfile}" "${token}"
    3232}
     
    3636{
    3737    local label="${1}"
    38     p11tool --provider=${softhsm_lib} --list-tokens | \
     38    p11tool --provider=${SOFTHSM_LIB} --list-tokens | \
    3939        grep -o -P "(?<=URL:\s)(.*token=${label}.*)$"
    4040}
     
    4444function get_object_url
    4545{
    46     p11tool --provider=${softhsm_lib} --list-all --login "${1}" | \
     46    p11tool --provider=${SOFTHSM_LIB} --list-all --login "${1}" | \
    4747        grep -o -P "(?<=URL:\s)(.*object=${2}.*)$"
    4848}
     
    6565
    6666# try to find SoftHSM
    67 softhsm="$(which softhsm)"
     67softhsm="$(basename ${SOFTHSM})"
     68
     69if [ "${softhsm}" = "softhsm" ]; then
     70    softhsm_libname="libsofthsm.so"
     71    # fail if SOFTHSM_CONF is not set
     72    if [ -z "${SOFTHSM_CONF}" ]; then
     73        echo "ERROR: SOFTHSM_CONF not set!" 1>&2
     74        exit 1
     75    else
     76        export SOFTHSM_CONF
     77    fi
     78    echo "using SOFTHSM_CONF=\"${SOFTHSM_CONF}\""
     79elif [ "${softhsm}" = "softhsm2-util" ]; then
     80    softhsm_libname="libsofthsm2.so"
     81    # fail if SOFTHSM2_CONF is not set
     82    if [ -z "${SOFTHSM2_CONF}" ]; then
     83        echo "ERROR: SOFTHSM2_CONF not set!" 1>&2
     84        exit 1
     85    else
     86        export SOFTHSM2_CONF
     87    fi
     88else
     89    # no SoftHSM
     90    echo "No SoftHSM!" >&2
     91    exit 77
     92fi
     93
     94if [ -z "${SOFTHSM_LIB}" ]; then
     95    # Try to find the libsofthsm[2] module in some common locations.
     96    softhsm_searchpath=(/usr/lib64/pkcs11 /usr/lib/softhsm /usr/lib/x86_64-linux-gnu/softhsm /usr/lib /usr/lib64/softhsm)
     97    for i in ${softhsm_searchpath[@]} ""; do
     98        SOFTHSM_LIB="${i}/${softhsm_libname}"
     99        echo "checking ${SOFTHSM_LIB} ..."
     100        if [ -f "${SOFTHSM_LIB}" ]; then
     101            echo "found!"
     102            export SOFTHSM_LIB
     103            break;
     104        fi
     105    done
     106else
     107    echo "using ${SOFTHSM_LIB} (set by user)"
     108fi
     109
     110if [ ! -f "${SOFTHSM_LIB}" ]; then
     111    echo "${softhsm_libname} not found!" >&2
     112    exit 77
     113fi
    68114
    69115case "${1}" in
     
    88134set -e
    89135
    90 # Guess location of libsofthsm based on softhsm binary. The path
    91 # matches SoftHSM upstream, but this might fail if someone changes the
    92 # libdir or bindir of the SoftHSM installation independently of its
    93 # general prefix.
    94 softhsm_prefix="$(realpath $(dirname ${softhsm})/..)"
    95 softhsm_lib="${softhsm_prefix}/lib/softhsm/libsofthsm.so"
    96 
    97 # fail if SOFTHSM_CONF is not set
    98 if [ -z "${SOFTHSM_CONF}" ]; then
    99     echo "ERROR: SOFTHSM_CONF not set!" 1>&2
    100     exit 1
    101 else
    102     export SOFTHSM_CONF
    103 fi
    104 echo "using SOFTHSM_CONF=\"${SOFTHSM_CONF}\""
    105 
    106136# variables for token configuration
    107137token_label="mod_gnutls-test"
Note: See TracChangeset for help on using the changeset viewer.