make-ca: remove workarounds and use certdata.txt values first, remove trailing spaces from x509 Subject derived p11label.

This commit is contained in:
DJ Lucas 2021-08-08 00:26:59 -05:00
parent 2c1da33970
commit 53ac95f8fd

36
make-ca
View File

@ -462,30 +462,36 @@ function get_p11_label() {
# $1 == individual nss certificate extracted from certdata.txt # $1 == individual nss certificate extracted from certdata.txt
# or x509 certificate with OpenSSL text values # or x509 certificate with OpenSSL text values
# Get the subject line for any certs and do some early normalization # Start with the label assigned by Mozilla
subjectline=$(grep -m1 "Subject:" ${1} | sed -e 's@\s*=\s*@=@g' \ p11label=$(grep -m1 "^CKA_LABEL" ${1} | cut -d '"' -f 2 | sed 's@"@@g')
-e "s@(@ - @g" -e "s@)@ - @g" -e 's@\\@-@g' )
# Try for CN first (and further normalize) # If not coming from certdata.txt, get from x509 Subject line
p11label="$(echo ${subjectline} | grep -o "CN=.*$" | cut -d '=' -f 2 | \ if [ "${p11label}" == "" ]; then
sed -e 's@[A-Z]*$@@g' -e 's@, $@@' -e 's@"@@g' -e 's@,@@g')" # Get the subject line for any certs and do some early normalization
subjectline=$(grep -m1 "Subject:" ${1} | sed -e 's@\s*=\s*@=@g' \
-e "s@(@ - @g" -e "s@)@ - @g" -e 's@\\@-@g' )
# Special case for NetLock Arany certs # Try for CN Next (and further normalize) if not from certdata.txt
echo ${p11label} | grep -q "^NetLock" && p11label="NetLock Arany - Class Gold" p11label="$(echo ${subjectline} | grep -o "CN=.*$" | cut -d '=' -f 2 | \
sed -e 's@[A-Z]*$@@g' -e 's@, $@@' -e 's@"@@g' \
-e 's@,@@g' -e 's@ $@@')"
# Fallback to the last OU value if CN does not exeist in Subject string # Fallback to the last OU value if CN does not exeist in Subject string
## Special case for GlobalSign certs ## Special case for GlobalSign certs
if [ "${p11label}" == "" -o "${p11label}" == "GlobalSign" ]; then if [ "${p11label}" == "" ]; then
p11label="$(echo ${subjectline} | grep -o "OU=.*$" | \ p11label="$(echo ${subjectline} | grep -o "OU=.*$" | \
sed 's@OU=.*, OU=@OU=@g'| cut -d '=' -f 2 | \ sed 's@OU=.*, OU=@OU=@g'| cut -d '=' -f 2 | \
sed -e 's@[A-Z]*$@@' -e 's@, $@@' -e 's@"@@g' -e 's@,@@g')" sed -e 's@[A-Z]*$@@' -e 's@, $@@' -e 's@"@@g' \
-e 's@,@@g' -e 's@ $@@')"
# If still empty, fall back to Object value as a last resort # If still empty, fall back to Object value as a last resort
if [ "${p11label}" == "" ]; then if [ "${p11label}" == "" ]; then
p11label="$(echo ${subjectline} | grep -o "O=.*$" | \ p11label="$(echo ${subjectline} | grep -o "O=.*$" | \
cut -d '=' -f 2 | sed -e 's@[A-Z]*$@@g' \ cut -d '=' -f 2 | sed -e 's@[A-Z]*$@@g' \
-e 's@, $@@' -e 's@"@@g' -e 's@,@@g')" -e 's@, $@@' -e 's@"@@g' \
-e 's@,@@g' -e 's@ $@@')"
fi fi
fi
fi fi
} }