Skip to content

Commit d291837

Browse files
committed
sign-req: Allow the CSR DN-field order to be preserved
When signing a request, EasyRSA ALWAYS defaults to the CA defined Distinguished Name field order, as defined by openssl-easyrsa.cnf configuration file. In the unlikely event that a CSR is received with a different DN- field order, that order can be preserved for the signed certificate. Command 'sign-req', now has a command option 'preserve' for this. Additional: Use of 'preserve = yes' in openssl-easyrsa.cnf has no effect for EasyRSA. Testing OpenSSL directly indicates that this option may have no effect when used in OpenSSL default configuration file openssl.cnf Also, OpenSSL documentation for command 'ca', option '-preserveDN' does NOT infer that this option can be used in the configuration file. None of which is important to EasyRSA because only foreign CSRs can have a different DN-field order, so default behavior can remain. Signed-off-by: Richard T Bonhomme <[email protected]>
1 parent 27c5973 commit d291837

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

ChangeLog

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Easy-RSA 3 ChangeLog
22

3+
3.1.6 (2023-10-13)
4+
* sign-req: Allow the CSR DN-field order to be preserved (#970)
5+
36
3.1.5 (2023-06-10)
47
* Build Update: script now supports signing and verifying
58
* Automate support-file creation (Free packaging) (#964)

easyrsa3/easyrsa

+13-1
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,16 @@ cmd_help() {
128128
;;
129129
sign|sign-req)
130130
text="
131-
* sign-req <type> <file_name_base>
131+
* sign-req <type> <file_name_base> [ cmd-opts ]
132132

133133
Sign a certificate request of the defined type. <type> must be a known type,
134134
such as: 'client', 'server', 'serverClient', or 'ca' (or a user-added type).
135135
All supported types are listed in the x509-types directory.
136136

137137
This request file must exist in the reqs/ dir and have a .req file
138138
extension. See import-req below for importing reqs from other sources."
139+
opts="
140+
* preserve - When signing a request, 'preserve' the DN-field order of the CSR."
139141
;;
140142
build|build-client-full|build-server-full|build-serverClient-full)
141143
text="
@@ -2243,6 +2245,15 @@ sign_req() {
22432245
Incorrect number of arguments provided to sign-req:
22442246
expected 2, got $# (see command help for usage)"
22452247

2248+
# Check for preserve-dn
2249+
if [ "$3" ]; then
2250+
case "$3" in
2251+
preserve*) export EASYRSA_PRESERVE_DN=1 ;;
2252+
*)
2253+
warn "Ignoring unknown option '$3'"
2254+
esac
2255+
fi
2256+
22462257
# Cert type must exist under the EASYRSA_EXT_DIR
22472258
[ -e "$EASYRSA_EXT_DIR/$crt_type" ] || warn "\
22482259
Missing X509-type '$crt_type'"
@@ -2512,6 +2523,7 @@ $(display_dn req "$req_in")
25122523
easyrsa_openssl ca -utf8 -batch \
25132524
-in "$req_in" -out "$crt_out_tmp" \
25142525
-extfile "$ext_tmp" \
2526+
${EASYRSA_PRESERVE_DN:+ -preserveDN} \
25152527
${EASYRSA_PASSIN:+ -passin "$EASYRSA_PASSIN"} \
25162528
${EASYRSA_NO_TEXT:+ -notext} \
25172529
${EASYRSA_CERT_EXPIRE:+ -days "$EASYRSA_CERT_EXPIRE"} \

easyrsa3/openssl-easyrsa.cnf

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ crl_extensions = crl_ext
3131
default_days = $ENV::EASYRSA_CERT_EXPIRE # how long to certify for
3232
default_crl_days = $ENV::EASYRSA_CRL_DAYS # how long before next CRL
3333
default_md = $ENV::EASYRSA_DIGEST # use public key default MD
34+
35+
# Note: preserve=no|yes, does nothing for EasyRSA.
36+
# Use sign-req command option 'preserve' instead.
3437
preserve = no # keep passed DN ordering
3538

3639
# This allows to renew certificates which have not been revoked

easyrsa3/vars.example

+6
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ fi
105105
#set_var EASYRSA_REQ_EMAIL "[email protected]"
106106
#set_var EASYRSA_REQ_OU "My Organizational Unit"
107107

108+
# Preserve the Distinguished Name field order
109+
# of the certificate signing request
110+
# *Only* effective in --dn-mode=org
111+
#
112+
#set_var EASYRSA_PRESERVE_DN 1
113+
108114
# Set no password mode - This will create the entire PKI without passwords.
109115
# This can be better managed by choosing which entity private keys should be
110116
# encrypted with the following command line options:

0 commit comments

Comments
 (0)