You'll need to add the NameConstraints extension to the request using LibreSSL's config file. The following example is an extract - you'll need to add the various sections to your current config file and tweak the constraints:
[ req ]
# Don't prompt for the DN, use configured values instead
# This saves having to type in your DN each time.
prompt = no
string_mask = default
distinguished_name = req_dn
# The size of the keys in bits:
default_bits = 4096
# The extensions added when generating a CSR
req_extensions = req_ext
[ req_dn ]
countryName = GB
stateOrProvinceName = Somewhere
organizationName = Example
organizationalUnitName = PKI
commonName = Example CA
[ req_ext ]
# Extensions added to the request
subjectKeyIdentifier = hash
basicConstraints = critical, CA:TRUE
# basicConstraints = critical, CA:TRUE, pathlen:1
keyUsage = critical, keyCertSign, cRLSign
# Policies and constraints are not recommended for Root CAs
# But could be enforced on subordinate CAs
nameConstraints = @name_constraints
#policyConstraints = requireExplicitPolicy:1
#inhibitAnyPolicy = 1
#certificatePolicies = @CertPol
[ name_constraints ]
permitted;DNS.1 = example.org
permitted;DNS.2 = example.com
permitted;dirName.1 = style_1
permitted;dirName.2 = style_2
[ style_1 ]
C=gb
ST=somewhere
O=example
1.OU=head office
2.OU=admin
[ style_2 ]
1.DC=org
2.DC=example
[ CertPol ]
policyIdentifier = 1.3.6.1.4.132473
CPS = http://pki.example.org/cps.html
If you're not using the default configuration file you'll need to add -config <config file> to your command line.
Note: I've not tried this on LibreSSL - only on OpenSSL but I believe both use the same syntax.
1.OU,1.DC), and theDCfield documented? I haven't found that documentation anywhere. – alx - recommends codidact May 14 '20 at 09:18n.DCis the domain levels. Am I right? For example for foo.bar.org it would be1.DC=org2.DC=bar3.DC=foo. If not, what is DC exactly for? – alx - recommends codidact May 14 '20 at 11:50openssl req -new -sha512 -key ca1.key.pem -out ca1.csr.pem(I edited/etc/ssl/openssl.cnfdirectly) and got: – alx - recommends codidact May 14 '20 at 12:00Error Loading request extension section req_ext 140424884049152:error:0D06407A:asn1 encoding routines:a2d_ASN1_OBJECT:first num too large:../crypto/asn1/a_object.c:73: 140424884049152:error:0B083077:x509 certificate routines:X509_NAME_ENTRY_create_by_txt:invalid field name:../crypto/x509/x509name.c:251:name=string_mask 140424884049152:error:220A4095:X509 V3 routines:a2i_GENERAL_NAME:dirname error:../crypto/x509v3/v3_alt.c:481: 140424884049152:error:22098080:X509 V3 routines:X509V3_EXT_nconf:error in extension:../crypto/x509v3/v3_conf.c:47:name=nameConstraints, value=@name_constraints– alx - recommends codidact May 14 '20 at 12:00