add_dkim_key.sh: fix error in case long keys (i.e.2048 bit).

This commit is contained in:
Christoph 2025-02-18 17:57:27 +01:00
parent e4c9a4fc8f
commit 78a1610517

View File

@ -38,13 +38,13 @@ usage() {
$conf_file: Configuration file
\033[1mExample:\033[m
<description example>
$(basename $0) .. <comand example>
<description another example>
$(basename $0) .. <command another example>
"
@ -401,7 +401,7 @@ if $terminal ; then
echo " [6] hmac-sha512"
fi
echo ""
echo ""
echo " Type a number or press <RETURN> to choose highlighted value"
echo ""
echononl " Key algorithm [${DEFAULT_KEY_ALGO}]: "
@ -421,7 +421,7 @@ if $terminal ; then
5) KEY_ALGO="hmac-sha384" ;;
6) KEY_ALGO="hmac-sha512" ;;
'') KEY_ALGO="${DEFAULT_KEY_ALGO}" ;;
*) echo ""
*) echo ""
echo -e " \033[33m\033[1mFalsche Eingabe ! [ 1 = hmac-md5 | 2 = hmac-sha1 | .. ]\033[m"
echo ""
echononl " Key algorithm [hmac-sha256]:"
@ -467,48 +467,6 @@ if $terminal ; then
if [[ "X$TTL" = "X" ]] ; then
TTL="${DEFAULT_TTL}"
fi
blank_line
blank_line
declare -i length_dkim_key=${#DKIM_KEY}
declare -i pos_begin=0
declare -i pos_end=64
_intro="v=${DKIM_TYPE}; k=${KEY_TYPE}; p="
declare -i length_intro=${#_intro}
declare -i total_length=$((length_intro + length_dkim_key))
echononl "Create (splitted 'p' value of DNS record.."
if [[ ${total_length} -gt 255 ]] ; then
_failed=false
p_val=""
while [[ $pos_end -lt $length ]] ; do
p_val+="\"$(echo "${DKIM_KEY:$pos_begin:64}")\" "
[[ $? -gt 0 ]] && _failed=true
pos_begin=$pos_end
pos_end=$(expr $pos_end + 64)
[[ $? -gt 0 ]] && _failed=true
done
p_val+="\"$(echo "${DKIM_KEY:$pos_begin}")\""
[[ $? -gt 0 ]] && _failed=true
if $_failed ; then
echo_failed
fatal "Cannot create p vaalue of DNS Record"
else
echo_ok
fi
txt_val="\"v=${DKIM_TYPE}; k=${KEY_TYPE}; s=email; p=\" ${p_val}"
else
echo_skipped
p_val="${DKIM_KEY}"
txt_val="\"${_intro}${p_val}\""
fi
fi
@ -534,6 +492,51 @@ if [[ -z "$(trim "${KEY_SECRET}")" ]]; then
fi
blank_line
blank_line
declare -i length_dkim_key=${#DKIM_KEY}
_intro="v=${DKIM_TYPE}; k=${KEY_TYPE}; p="
declare -i length_intro=${#_intro}
declare -i total_length=$((length_intro + length_dkim_key))
echononl "Create (splitted) 'p' value of DNS record.."
if [[ ${total_length} -gt 255 ]] ; then
TMP_DKIM_KEY="$DKIM_KEY"
p_val=""
_length=64
declare -i index=1
while [ -n "$TMP_DKIM_KEY" ]; do
if [[ index -eq 1 ]]; then
p_val="\"${TMP_DKIM_KEY:0:$_length}\""
else
p_val+=" \"${TMP_DKIM_KEY:0:$_length}\""
fi
TMP_DKIM_KEY="${TMP_DKIM_KEY:$_length}"
(( ++index ))
done
echo_done
txt_val="\"v=${DKIM_TYPE}; k=${KEY_TYPE}; s=email; p=\" ${p_val}"
else
echo_skipped
p_val="${DKIM_KEY}"
txt_val="\"${_intro}${p_val}\""
fi
if $terminal ; then
echo ""
@ -560,7 +563,7 @@ if $terminal ; then
echo " DKIM Key.........................: $DKIM_KEY"
echo -e " \033[1m----------\033[m"
echo ""
echo -e " DNS Record to add:\n\n\033[33m${DKIM_SELECTOR}.${DKIM_UPDATE_ZONE}. ${TTL} IN TXT ${txt_val}\033[m"
echo -e " DNS Record to add:\n\n\033[33m${DKIM_SELECTOR}.${DKIM_UPDATE_ZONE}. ${TTL} IN TXT ${txt_val}\033[m"
echo ""
echo -e "\n\n The following 'nsupdate'command will be used:"
cat <<END