Error loading extension section server

I am running openvpn on an Ubuntu 14.04 box. The setup was fine until an OpenSSL upgrade, then when I try to create new client cert with easy-rsa, I got this message: root@:easy-rsa# ./pkitool ono...

I am running openvpn on an Ubuntu 14.04 box. The setup was fine until an OpenSSL upgrade, then when I try to create new client cert with easy-rsa, I got this message:

root@:easy-rsa# ./pkitool onokun
Using Common Name: onokun
Generating a 2048 bit RSA private key
.+++
........+++
writing new private key to 'onokun.key'
-----
Using configuration from /etc/openvpn/easy-rsa/openssl-1.0.0.cnf
Error Loading extension section usr_cert
3074119356:error:0E06D06C:configuration file routines:NCONF_get_string:no value:conf_lib.c:335:group=CA_default name=email_in_dn
3074119356:error:2207507C:X509 V3 routines:v2i_GENERAL_NAME_ex:missing value:v3_alt.c:537:
3074119356:error:22098080:X509 V3 routines:X509V3_EXT_nconf:error in extension:v3_conf.c:93:name=subjectAltName, value=onokun

This problem is different from a reported bug that the which opensslcnf script can not find an matching version of openssl.cnf to use (above message shows openssl-1.0.0.cnf). I performed a Google search but did not find an answer.

Here are some environment information:

## openvpn
OpenVPN 2.3.2 i686-pc-linux-gnu [SSL (OpenSSL)] [LZO] [EPOLL] [PKCS11] [eurephia] [MH] [IPv6] built on Feb  4 2014
Originally developed by James Yonan

## openssl
OpenSSL 1.0.1f 6 Jan 2014

## dpkg --get-selections | grep ssl
libgnutls-openssl27:i386                        install
libio-socket-ssl-perl                           install
libnet-smtp-ssl-perl                            install
libnet-ssleay-perl                              install
libssl-dev:i386                                 install
libssl-doc                                      install
libssl0.9.8:i386                                install
libssl1.0.0:i386                                install
openssl                                         install
ssl-cert                                        install

What should I look at to solve this? Thanks,

jww's user avatar

jww

95k88 gold badges397 silver badges861 bronze badges

asked Jun 17, 2014 at 3:18

eN_Joy's user avatar

Using configuration from /etc/openvpn/easy-rsa/openssl-1.0.0.cnf
Error Loading extension section usr_cert

I don’t have a /etc/openvpn/easy-rsa/openssl-1.0.0.cnf, so take this with a grain of salt…

opensslconf.h from OpenSSL’s distribution does include that section:

openssl-1.0.1h$ grep -R usr_cert *
apps/openssl-vms.cnf:x509_extensions    = usr_cert      # The extensions to add to the cert
apps/openssl-vms.cnf:[ usr_cert ]
apps/openssl.cnf:x509_extensions    = usr_cert      # The extensions to add to the cert
apps/openssl.cnf:[ usr_cert ]

Can you restore an old version of /etc/openvpn/easy-rsa/openssl-1.0.0.cnf?

Here’s the section from apps/openssl.cnf. You might consider adding it to Easy RSA’s configuration file if its missing. First, try an empty section. Then try adding the original code back.

[ usr_cert ]

# These extensions are added when 'ca' signs a request.

# This goes against PKIX guidelines but some CAs do it and some software
# requires this to avoid interpreting an end user certificate as a CA.

basicConstraints=CA:FALSE

# Here are some examples of the usage of nsCertType. If it is omitted
# the certificate can be used for anything *except* object signing.

# This is OK for an SSL server.
# nsCertType            = server

# For an object signing certificate this would be used.
# nsCertType = objsign

# For normal client use this is typical
# nsCertType = client, email

# and for everything including object signing:
# nsCertType = client, email, objsign

# This is typical in keyUsage for a client certificate.
# keyUsage = nonRepudiation, digitalSignature, keyEncipherment

# This will be displayed in Netscape's comment listbox.
nsComment           = "OpenSSL Generated Certificate"

# PKIX recommendations harmless if included in all certificates.
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid,issuer

# This stuff is for subjectAltName and issuerAltname.
# Import the email address.
# subjectAltName=email:copy
# An alternative to produce certificates that aren't
# deprecated according to PKIX.
# subjectAltName=email:move

# Copy subject details
# issuerAltName=issuer:copy

#nsCaRevocationUrl      = http://www.domain.dom/ca-crl.pem
#nsBaseUrl
#nsRevocationUrl
#nsRenewalUrl
#nsCaPolicyUrl
#nsSslServerName

# This is required for TSA certificates.
# extendedKeyUsage = critical,timeStamping

answered Jun 17, 2014 at 7:26

jww's user avatar

jwwjww

95k88 gold badges397 silver badges861 bronze badges

1

By comparing an earlier Ubuntu 14.04 install that did not have this problem, it seems the specific issue is with «subjectAltName». I didn’t read up on what this does, but the command below will fix your «openssl-1.0.0.cnf» file:

perl -p -i -e 's|^(subjectAltName=)|#$1|;' /etc/openvpn/easy-rsa/openssl-1.0.0.cnf

I should probably file a bug report.

answered Sep 27, 2014 at 19:41

expebition's user avatar

expebitionexpebition

811 silver badge3 bronze badges

3

I finally got his working (on my machine) Firstly my setup is a little different, I’m on Windows10, running OpenSSL 1.0.2h. I’m trying to generate multiple certificates, CAs and other things for tests, I am getting the error:

configuration file routines:NCONF_get_string:no value:.cryptoconfconf_lib.c:324:group=CA_default name=email_in_dn

To fix it I found placing the entry email_in_dn = no in CA_Default openssl.cfg section as bellow

####################################################################
[ CA_default ]
dir     = ./demoCA              # Where everything is kept
certs       = $dir/certs        # Where the issued certs are kept
crl_dir     = $dir/crl          # Where the issued crl are kept
database    = $dir/index.txt    # database index file.
new_certs_dir   = $dir/newcerts # default place for new certs.

certificate = $dir/ca.crt       # The CA certificate
serial      = $dir/serial       # The current serial number
crl     = $dir/crl.pem          # The current CRL
private_key = $dir/private/caprivkey.pem# The private key
RANDFILE    = $dir/private/.rand    # private random number file
x509_extensions = usr_cert      # The extentions to add to the cert
email_in_dn = no                # <-- fixes CONF_get_string:no value

I hope this helps someone else.

answered Aug 25, 2016 at 9:17

Dai Bok's user avatar

Dai BokDai Bok

3,3732 gold badges53 silver badges69 bronze badges

This is filed as a bug in Ubuntu. See SSL certificate creation crashes without subjectAltName.

The work-around described by Yuriy seems to work (copied from launchpad):

in the file /usr/share/easy-rsa/pkitool

just replace expressions:

KEY_ALTNAMES=»$KEY_CN»

to:

KEY_ALTNAMES=»DNS:${KEY_CN}»

In my version of the file this is line 284, just after the string «Using Common Name»

answered Feb 17, 2016 at 11:47

David's user avatar

DavidDavid

1,17912 silver badges15 bronze badges

To get rid of this error:

3074119356:error:0E06D06C:configuration file routines:NCONF_get_string:no value:conf_lib.c:335:group=CA_default name=email_in_dn

use

-noemailDN 

in the openssl command.

For example:

$  openssl ca -batch -config openssl.cnf -extensions usr_cert -noemailDN -days 375 -notext -md sha256 -in csr/www.example8.com.csr.pem -out certs/www.example8.com.cert.pem -verbose -passin pass:changeit

answered Oct 31, 2017 at 19:56

user674669's user avatar

user674669user674669

9,96814 gold badges70 silver badges98 bronze badges

The system is Fedora fc21. The objective is to run the examples shown here: “APACHE web server and SSL authentication”

The openssl.cnf file has been created and the following command run:

openssl x509 -req -in server.req -CA ca.cer -CAkey ca.key  -set_serial 100 -extfile openssl.cnf -extensions server -days 365 -outform PEM -out server.cer

The result is:

Error Loading extension section server
140131294459760:error:22097069:X509 V3 routines:DO_EXT_NCONF:invalid extension string:v3_conf.c:139:name=crlDistributionPoints,section=@crl
140131294459760:error:22098080:X509 V3 routines:X509V3_EXT_nconf:error in extension:v3_conf.c:93:name=crlDistributionPoints, value=@crl

Similar errors occur with the examples with -extension client and -extension certauth commands.

What is the cause of this error, how can it be remediated?

Giacomo1968's user avatar

Giacomo1968

51.6k18 gold badges162 silver badges205 bronze badges

asked Apr 3, 2015 at 3:53

1

This appears to be a known bug. There is a resolution posted, copied here for simplicity. In the file «pkitool» replace all occurrences of:

KEY_ALTNAMES=»$KEY_CN»

with:

KEY_ALTNAMES=»DNS:${KEY_CN}»

This solution worked for me.

answered Oct 3, 2015 at 19:32

Christopher's user avatar

Содержание

  1. Error Loading extension ‘copy_extensions’ in Openssl
  2. 1 Answer 1
  3. openssl: generate certificate request with non-DNS subject alternative names
  4. 3 Answers 3
  5. Provide subjectAltName to openssl directly on the command line
  6. 18 Answers 18
  7. Generate a PKCS12 keystore with keytool
  8. Export Certificate and Key with openssl
  9. First, you would need to create an OpenSSL configuration file .cnf .
  10. Once you have configured well your .cnf , let’s proceed to generate the CSR
  11. Under [req] section,
  12. Under [req_distinguished_name]
  13. Under [v3_req]
  14. Under [alt_names]

Error Loading extension ‘copy_extensions’ in Openssl

While running the following command on Ubuntu 19.10, with OpenSSl 1.1.1c 28 May 2019:

I receive the following output:

Error Loading extension section v3_ca

140710502360256:error:22097082:X509 V3 routines:do_ext_nconf:unknown extension name. /crypto/x509v3/v3_conf.c:78:

140710502360256:error:22098080:X509 V3 routines:X509V3_EXT_nconf:error in extension. /crypto/x509v3/v3_conf.c:47:name=copy_extensions, value=copy

With the following config file:

The error eludes me, and to give some background, my attempt to is use copy_extensions so that when I pass in a subjectAltName via -addext (or via any means) to the CSR, the subjectAltName will pass into the signed cert when executing the following (the following are openssl commands for the Intermediate Cert to sign and create a client or server based cert, and it all functions fine, except for what I just stated):

1 Answer 1

You’re not far off — copy_extensions is not an extension, it needs to be in the CA_Default section to instruct the CA to copy extensions from the CSR to the signed certificate.

Example below, see the last line:

Some useful resources on openssl can be found at the links below:

(These links all point to www.phildev.net — I am not associated with this site in anyway, but have found the content informative and easy to understand.)

To quote one part:

The «ca» section defines the way the CA acts when using the ca command to sign certificates.

In your case, the default CA’s section is CA_default (your actual «ca» section points to this).

Your best resource for specific commands is the Openssl docs themselves. On the linked page, you’ll find the explanation for how to use -addext. As far as I can tell your usage is accurate, but it is possible the issue is in the variable. There’s also a good answer on this here: Provide subjectAltName to openssl directly on the command line.

If your extensions are consistent, you can simply add them into the config file under whichever section $ refers to. You can of course specify multiple sections in the config file and select the correct section in each command using the -extensions flag.

Источник

openssl: generate certificate request with non-DNS subject alternative names

To create a certificate request containing subject alternative names (SANs) for a host, with openssl, I can use a config file like this (snipped):

If I need to provide a distinguished name or a user principal name, how should I configure the alt_names section for a user certificate request?
For example, I tried

But I got this error:

3 Answers 3

You can specify pretty much anything that your CA allows.

The relevant RFC is RFC5280. It says in section 4.2.1.6. «Subject Alternative Name»

The subject alternative name extension allows identities to be bound to the subject of the certificate. These identities may be included in addition to or in place of the identity in the subject field of the certificate. Defined options include an Internet electronic mail address, a DNS name, an IP address, and a Uniform Resource Identifier (URI). Other options exist, including completely local definitions. Multiple name forms, and multiple instances of each name form, MAY be included. Whenever such identities are to be bound into a certificate, the subject alternative name (or issuer alternative name) extension MUST be used; however, a DNS name MAY also be represented in the subject field using the domainComponent attribute as described in Section 4.1.2.4. Note that where such names are represented in the subject field implementations are not required to convert them into DNS names.

You should read the rest of that section, and then check with your CA what they support. It’s worth noting that your CA must verify that all subject alternative names are correct.

To use an email address, the RFC says in section 4.1.2.6

Conforming implementations generating new certificates with electronic mail addresses MUST use the rfc822Name in the subject alternative name extension (Section 4.2.1.6) to describe such identities. Simultaneous inclusion of the emailAddress attribute in the subject distinguished name to support legacy implementations is deprecated but permitted.

So instead of UPI, you should use rfc822Name.

Источник

Provide subjectAltName to openssl directly on the command line

Is it possible to provide a subjectAltName-Extension to the openssl req module directly on the command line?

I know it’s possible via a openssl.cnf file, but that’s not really elegant for batch-creation of CSRs.

18 Answers 18

As of OpenSSL 1.1.1, providing subjectAltName directly on command line becomes much easier, with the introduction of the -addext flag to openssl req (via this commit).

The commit adds an example to the openssl req man page:

This has been merged into the master branch of the openssl command on Github, and as of April 18 2018 can be installed via a git pull + compile (or via Homebrew if on OS X: brew install —devel openssl@1.1 ).

Note that if you have set the config attribute «req_extensions» at section «[req]» in openssl.cfg, it will ignore the command-line parameter

Based on link from DarkLighting, here’s the command I came up with using nested subshells.

This is my solution to finally generate a working self signed cert, based on the answers above(The accepted answer don’t work for me):

openssl x509 -in server.crt -text -noout :

Repro step for «The accepted answer don’t work for me» (On OSX 10.12.4, with system openssl):

My solution was to pass subjectAltName via an environment variable.

First have this added to openssl.conf :

Then set the environment variable before invoking openssl:

Note: the -extensions san_env parameter needs to be present when signing the CSR as well as when generating it. Therefore, for CA-signed CSRs add -extensions san_env to the openssl ca command as well.

As of 2022, with OpenSSL ≥ 1.1.1, the following command demonstrates how to generate a self-signed certificate with SAN for example.com and example.net :

Here we are using the -addext option.

If you are stuck to OpenSSL ≤ 1.1.0, e.g. on Debian ≤ 9 or CentOS ≤ 7, you can apply instead a tiny hack via -extensions and -config . The following command is portable in the sense that we don’t have to mess around with (or even know about) the location of the openssl.cnf file:

The trick here is to include a minimal [req] section that is good enough for OpenSSL to get along without its main openssl.cnf file.

Either way, don’t forget to verify the contents of the generated certificate:

So I had a heck of a time getting this working right, and putting at all in Ansible. As Ansible’s command module doesn’t allow file-redirects ( ), I had to use a small .cnf file as a template, but it’s all working now. Here’s what I did to make it work:

The san.cnf template (generated for each CSR/CRT pair):

Some Variables

These Ansible variables used in the following commands, but you can substitute as needed in your scripts:

key ssl_certs_local_caserial_path: The CA’s serial numbering file ssl_certs_local_cert_path: The final generated certificate file.

The CSR Generation Command

Self-Signing the CSR to create the Certificate

To Verify the Result

That should include a section that appears as follows:

The 2nd post in this link says that it not possible to do that only from command line, but the 4th post in the same link provides a workaround using bash’s ability of referencing data as if it was in a file.

Taking a further look into it, someone mentioned the reqexts parameter used to make additions to certificate request. This blog uses bash’s env as an approach to this.

But i’m just trying to help. Haven’t tested any of this myself.

Tested for RHEL7 (creating a self-signed certificate with a SAN)

I wanted a one line command to create a CSR — worked perfectly with no conf files, but didn’t generate a SubjAltName entry. This version is what I was using Using read -p to request FQDN I wanted this to work with a SAN entry as well — so here’s a working solution.

There is a dependency on the version of openssl, needs to be at least 1.1.1. because you need -addext.

No messing with conf files this way.

My solution to this problem was to create and reference a temporary cnf file by appending my command-line-collected subjectAltName information.

I needed to do this for creating self-signed certs for local testing, but also wanted to be able to pass multiple parameters for extensions, not just SAN. I discovered that doing multiple -extfile commands, just seemed to overwrite each other, and only the last -extfile value ended up in cert.

The solution was just to add more variables to the printf:

That works fine, but our workflow was already generated certs by storing the command in a package.json file, and then running npm run newcert . Attempting to add n to the printf just broke the command. The solution for this was to switch to using a lot of echos, along with explicitly defining an extension name.

  • Note: For running these as an npm script, you’ll have to escape the double quotes, and line continuations can’t be used.

Running openssl x509 -noout -text -in cert.pem shows it worked:

The question has been answered, but I still struggled with getting this into an elegant and useful form to automate CSR generation. The one liner is nice so I incorporated it into a routine that allows the subject alternative names as command arguments rather than values in a file also the flexibility to SAN or not to SAN. Try it with one argument then with many.

This has been answered, but if anyone’s still looking for a no-prompt, cli-only method to create a self-signed root cert (without CAs or CSRs) and don’t mind using Java keytool , here’s an alternative:

Generate a PKCS12 keystore with keytool

Export Certificate and Key with openssl

As an addition to the answer by @Excalibur (btw. thank you for your work!)

I find this form a bit more suited for Ansible. It sidesteps the problems of the official module openssl_csr that is somewhat difficult to work with due to library dependency and version problems.

The following is an adaptation of a part of the script generation by @Excalibur. You don’t need to create a file. This particular playbook outputs the certificate to stdin which you can show with ( ansible-playbook -vvvv

) or dump to a variable and output using the debug module.

The domain.key needs to be in the same directory as the playbook.

Simple answer is: you need two separate sections for requesting and signing certificates.

In signing section, REMOVE subjectAltName specification altogether.

Then it’ll pass from the request.

Create a copy of the default openssl.cnf file and add the line below in the [req] section:

Then, add the content below under the req_extensions section:

Once the custom config file is created, explicitly specify this config file while creating a CSR:

Link to my working modified openssl config file:

Shout out to Thiyagarajen’s solution

[Background] Was trying to generate CSR with adding in SAN

After few experiments, here’s what I did after reading all useful solutions here and various sources.

If the OpenSSL configuration file is defined well, then we could use -config myopenssl.cnf without the need of -reqexts param.

First, you would need to create an OpenSSL configuration file .cnf .

For example, nano myopenssl.cnf

Below is a template OpenSSL configuration file

Once you have configured well your .cnf , let’s proceed to generate the CSR

// Generate Certificate Signing Request(CSR) using existing key without creating a new key

// Generate CSR with «new» RSA 2048 key

Based on my current understanding, I will try my best to explain the above configuration. Please correct me if I’m wrong

Under [req] section,

  1. distinguished_name = req_distinguished_name
    First, we need to understand what distinguished name is?
    Distinguished Name (DN) is a set of values entered during enrollment and the creation of a Certificate Signing Request (CSR) such as:
    • C= Country (2 character country code such as US)
    • ST = State (must be spelled out completely such as New York or California)
    • L = Locality/City
    • O = Organization (legal company name)
    • OU = Organizational Unit (division or department of company but this is an optional field)
    • CN = Common Name (the fully qualified domain name such as www.digicert.com)

So, distinguished_name = req_distinguished_name will point the OpenSSL to find the set of values under [req_distinguished_name] section and there’s no need for us to use -subj param.

req_extensions = v3_req
Will point to [v3_req] section, whereby you could define any of the extension attributes you wish to add, in our case is just the subjectAltName . So, we could take out the keyUsage and extendedKeyUsage attributes. So, there’s no need to use -reqexts anymore to point to the SAN section when you define «req_extensions = v3_req» and at which you subjectAltName resides in this [v3_req] section!(When generating a CSR, like this, ‘req’ could use the commandline option -reqexts or straight from the defined configuration file entry req_extensions.)

prompt = no
Will not prompt you to enter the Distinguised name like usual, instead it will used the one configured inside this cnf file [req_distinguished_name] section.

Under [req_distinguished_name]

From the OpenSSL commandline return message,

What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.

However, from my testing, it seem like could not leave country (C) with ‘.’, else will hit error like: 140027926083488:error:0D07A098:asn1 encoding routines:ASN1_mbstring_ncopy:string too short:a_mbstr.c:151:minsize=2

Below is a sample snippet of leaving blank for the distinguished name.

Under [v3_req]

We could either define subjectAltName in just one line like the upvoted solutions given in this thread or we could point subjectAltName to a «section» we created as shown in the template OpenSSL configuration file shown above.

Either
subjectAltName=DNS:example.com,DNS:www.example.com,IP:10.0.0.1,IP:10.0.0.2

Or

Under [alt_names]

IP address must be in range of 0.0.0.0 — 255.255.255.255

Источник

When generating the OVPN configuration with easy_RSA, the following error occurred:

[ root: /usr/share/easy-rsa] #/usr/share/easy-rsa/build-key --batch zzzz.29761
Using Common Name: zzzz.29761
Generating a 2048 bit RSA private key
...............+++
.................................................................+++
writing new private key to 'zzzz.29761.key'
-----
Using configuration from /usr/share/easy-rsa/openssl-1.0.0.cnf
Error Loading extension section usr_cert
140516636624544:error:0E06D06C:configuration file routines:NCONF_get_string:no value:conf_lib.c:335:group=CA_default name=email_in_dn
140516636624544:error:2207507C:X509 V3 routines:v2i_GENERAL_NAME_ex:missing value:v3_alt.c:537:
140516636624544:error:22098080:X509 V3 routines:X509V3_EXT_nconf:error in extension:v3_conf.c:93:name=subjectAltName, value=zzzz.29761

View the version information of OpenVPN:

# openvpn --version
OpenVPN 2.3.2 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [EPOLL] [PKCS11] [eurephia] [MH] [IPv6] built on Dec  1 2014
Originally developed by James Yonan
Copyright (C) 2002-2010 OpenVPN Technologies, Inc. <[email protected]>

in the configuration file openssl-1.0.0.cnf, the [usr_cert] section contains an additional parameter: subjectAltName=email:copy.
Openssl – 1.0.0. CNF content:

[[email protected] 2.0]# cat openssl-1.0.0.cnf
# For use with easy-rsa version 2.0 and OpenSSL 1.0.0*

# This definition stops the following lines choking if HOME isn't
# defined.
HOME                    = .
RANDFILE                = $ENV::HOME/.rnd
openssl_conf            = openssl_init

[ openssl_init ]
# Extra OBJECT IDENTIFIER info:
#oid_file               = $ENV::HOME/.oid
oid_section             = new_oids
engines                 = engine_section

# To use this configuration file with the "-extfile" option of the
# "openssl x509" utility, name here the section containing the
# X.509v3 extensions to use:
# extensions            =
# (Alternatively, use a configuration file that has only
# X.509v3 extensions in its main [= default] section.)

[ new_oids ]

# We can add new OIDs in here for use by 'ca' and 'req'.
# Add a simple OID like this:
# testoid1=1.2.3.4
# Or use config file substitution like this:
# testoid2=${testoid1}.5.6

####################################################################
[ ca ]
default_ca      = CA_default            # The default ca section

####################################################################
[ CA_default ]

dir             = $ENV::KEY_DIR         # Where everything is kept
certs           = $dir                  # Where the issued certs are kept
crl_dir         = $dir                  # Where the issued crl are kept
database        = $dir/index.txt        # database index file.
new_certs_dir   = $dir                  # default place for new certs.

certificate     = $dir/ca.crt           # The CA certificate
serial          = $dir/serial           # The current serial number
crl             = $dir/crl.pem          # The current CRL
private_key     = $dir/ca.key           # The private key
RANDFILE        = $dir/.rand            # private random number file

x509_extensions = usr_cert              # The extentions to add to the cert

# Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs
# so this is commented out by default to leave a V1 CRL.
# crl_extensions        = crl_ext

default_days    = 3650                  # how long to certify for
default_crl_days= 30                    # how long before next CRL
default_md      = sha256                # use public key default MD
preserve        = no                    # keep passed DN ordering

# A few difference way of specifying how similar the request should look
# For type CA, the listed attributes must be the same, and the optional
# and supplied fields are just that :-)
policy          = policy_anything

# For the CA policy
[ policy_match ]
countryName             = match
stateOrProvinceName     = match
organizationName        = match
organizationalUnitName  = optional
commonName              = supplied
name                    = optional
emailAddress            = optional

# For the 'anything' policy
# At this point in time, you must list all acceptable 'object'
# types.
[ policy_anything ]
countryName             = optional
stateOrProvinceName     = optional
localityName            = optional
organizationName        = optional
organizationalUnitName  = optional
commonName              = supplied
name                    = optional
emailAddress            = optional

####################################################################
[ req ]
default_bits            = $ENV::KEY_SIZE
default_keyfile         = privkey.pem
default_md              = sha256
distinguished_name      = req_distinguished_name
attributes              = req_attributes
x509_extensions = v3_ca # The extentions to add to the self signed cert

# Passwords for private keys if not present they will be prompted for
# input_password = secret
# output_password = secret

# This sets a mask for permitted string types. There are several options.
# default: PrintableString, T61String, BMPString.
# pkix   : PrintableString, BMPString (PKIX recommendation after 2004).
# utf8only: only UTF8Strings (PKIX recommendation after 2004).
# nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings).
# MASK:XXXX a literal mask value.
string_mask = nombstr

# req_extensions = v3_req # The extensions to add to a certificate request

[ req_distinguished_name ]
countryName                     = Country Name (2 letter code)
countryName_default             = $ENV::KEY_COUNTRY
countryName_min                 = 2
countryName_max                 = 2

stateOrProvinceName             = State or Province Name (full name)
stateOrProvinceName_default     = $ENV::KEY_PROVINCE

localityName                    = Locality Name (eg, city)
localityName_default            = $ENV::KEY_CITY

0.organizationName              = Organization Name (eg, company)
0.organizationName_default      = $ENV::KEY_ORG

# we can do this but it is not needed normally :-)
#1.organizationName             = Second Organization Name (eg, company)
#1.organizationName_default     = World Wide Web Pty Ltd

organizationalUnitName          = Organizational Unit Name (eg, section)
#organizationalUnitName_default =

commonName                      = Common Name (eg, your name or your server's hostname)
commonName_max                  = 64

name                            = Name
name_max                        = 64

emailAddress                    = Email Address
emailAddress_default            = $ENV::KEY_EMAIL
emailAddress_max                = 40

# JY -- added for batch mode
organizationalUnitName_default = $ENV::KEY_OU
commonName_default = $ENV::KEY_CN
name_default = $ENV::KEY_NAME


# SET-ex3                       = SET extension number 3

[ req_attributes ]
challengePassword               = A challenge password
challengePassword_min           = 4
challengePassword_max           = 20

unstructuredName                = An optional company name

[ usr_cert ]

# These extensions are added when 'ca' signs a request.

# This goes against PKIX guidelines but some CAs do it and some software
# requires this to avoid interpreting an end user certificate as a CA.

basicConstraints=CA:FALSE

# Here are some examples of the usage of nsCertType. If it is omitted
# the certificate can be used for anything *except* object signing.

# This is OK for an SSL server.
# nsCertType                    = server

# For an object signing certificate this would be used.
# nsCertType = objsign

# For normal client use this is typical
# nsCertType = client, email

# and for everything including object signing:
# nsCertType = client, email, objsign

# This is typical in keyUsage for a client certificate.
# keyUsage = nonRepudiation, digitalSignature, keyEncipherment

# This will be displayed in Netscape's comment listbox.
nsComment                       = "Easy-RSA Generated Certificate"

# PKIX recommendations harmless if included in all certificates.
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid,issuer:always
extendedKeyUsage=clientAuth
keyUsage = digitalSignature


# This stuff is for subjectAltName and issuerAltname.
# Import the email address.
# subjectAltName=email:copy

# Copy subject details
# issuerAltName=issuer:copy

#nsCaRevocationUrl              = http://www.domain.dom/ca-crl.pem
#nsBaseUrl
#nsRevocationUrl
#nsRenewalUrl
#nsCaPolicyUrl
#nsSslServerName

[ server ]

# JY ADDED -- Make a cert with nsCertType set to "server"
basicConstraints=CA:FALSE
nsCertType                     = server
nsComment                      = "Easy-RSA Generated Server Certificate"
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid,issuer:always
extendedKeyUsage=serverAuth
keyUsage = digitalSignature, keyEncipherment

[ v3_req ]

# Extensions to add to a certificate request

basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment

[ v3_ca ]


# Extensions for a typical CA


# PKIX recommendation.

subjectKeyIdentifier=hash

authorityKeyIdentifier=keyid:always,issuer:always

# This is what PKIX recommends but some broken software chokes on critical
# extensions.
#basicConstraints = critical,CA:true
# So we do this instead.
basicConstraints = CA:true

# Key usage: this is typical for a CA certificate. However since it will
# prevent it being used as an test self-signed certificate it is best
# left out by default.
# keyUsage = cRLSign, keyCertSign

# Some might want this also
# nsCertType = sslCA, emailCA

# Include email address in subject alt name: another PKIX recommendation
# subjectAltName=email:copy
# Copy issuer details
# issuerAltName=issuer:copy

# DER hex encoding of an extension: beware experts only!
# obj=DER:02:03
# Where 'obj' is a standard or added object
# You can even override a supported extension:
# basicConstraints= critical, DER:30:03:01:01:FF

[ crl_ext ]

# CRL extensions.
# Only issuerAltName and authorityKeyIdentifier make any sense in a CRL.

# issuerAltName=issuer:copy
authorityKeyIdentifier=keyid:always,issuer:always

[ engine_section ]
#
# If you are using PKCS#11
# Install engine_pkcs11 of opensc (www.opensc.org)
# And uncomment the following
# verify that dynamic_path points to the correct location
#
#pkcs11 = pkcs11_section

[ pkcs11_section ]
engine_id = pkcs11
dynamic_path = /usr/lib/engines/engine_pkcs11.so
MODULE_PATH = $ENV::PKCS11_MODULE_PATH
PIN = $ENV::PKCS11_PIN
init = 0

Reference:
1 Error Loading the extension section usr_cert:http://stackoverflow.com/questions/24255205/error-loading-extension-section-usr-cert openvpn configuration file
2 a: http://www-2w.blog.163.com/blog/static/9793151820111010253869/

Read More:

While running the following command on Ubuntu 19.10, with OpenSSl 1.1.1c 28 May 2019:

openssl req -config ${CNF_FILE} -key ${PRIVATE_FILE} -new -x509 -days 10950 -sha384 -extensions v3_ca -out ${CERT_FILE}

I receive the following output:

Error Loading extension section v3_ca

140710502360256:error:22097082:X509 V3 routines:do_ext_nconf:unknown extension name:../crypto/x509v3/v3_conf.c:78:

140710502360256:error:22098080:X509 V3 routines:X509V3_EXT_nconf:error in extension:../crypto/x509v3/v3_conf.c:47:name=copy_extensions, value=copy

With the following config file:

[ca ]
# `man ca`
default_ca = CA_default

[ CA_default ]
# Directory and file locations.
dir               = /home/ca
certs             = $dir/certs
crl_dir           = $dir/crl
new_certs_dir     = $dir/newcerts
database          = $dir/index.txt
serial            = $dir/serial
RANDFILE          = $dir/private/.rand

# The root key and root certificate.
private_key       = $dir/private/ca_ecc.key.pem
certificate       = $dir/certs/ca_ecc.cert.pem

# For certificate revocation lists.
crlnumber         = $dir/crlnumber
crl               = $dir/crl/ca.crl.pem
crl_extensions    = crl_ext
default_crl_days  = 30

# SHA-1 is deprecated, so use SHA-2 instead.
default_md        = sha256

name_opt          = ca_default
cert_opt          = ca_default
default_days      = 375
preserve          = no
policy            = policy_strict

[ policy_strict ]
# The root CA should only sign intermediate certificates that match.
# See the POLICY FORMAT section of `man ca`.
countryName             = match
stateOrProvinceName     = match
organizationName        = match
organizationalUnitName  = optional
commonName              = supplied
emailAddress            = optional

[ policy_loose ]
# Allow the intermediate CA to sign a more diverse range of certificates.
# See the POLICY FORMAT section of the `ca` man page.
countryName             = optional
stateOrProvinceName     = optional
localityName            = optional
organizationName        = optional
organizationalUnitName  = optional
commonName              = supplied
emailAddress            = optional

[ req ]
# Options for the `req` tool (`man req`).
default_bits        = 2048
distinguished_name  = req_distinguished_name
string_mask         = utf8only

# SHA-1 is deprecated, so use SHA-2 instead.
default_md          = sha256

# Extension to add when the -x509 option is used.
x509_extensions     = v3_ca

[ req_distinguished_name ]
# See <https://en.wikipedia.org/wiki/Certificate_signing_request>.
countryName                     = Country Name (2 letter code)
stateOrProvinceName             = State or Province Name
localityName                    = Locality Name
0.organizationName              = Organization Name
organizationalUnitName          = Organizational Unit Name
commonName                      = Common Name
emailAddress                    = Email Address

# Optionally, specify some defaults.
countryName_default             = US
stateOrProvinceName_default     = My State
localityName_default            = My City
0.organizationName_default      = My Company
organizationalUnitName_default  = My Office
emailAddress_default            = certificates@certificates.com

[ v3_ca ]
# Extensions for a typical CA (`man x509v3_config`).
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = critical, CA:true
keyUsage = critical, digitalSignature, cRLSign, keyCertSign
copy_extensions = copy
preserve = yes

The error eludes me, and to give some background, my attempt to is use copy_extensions so that when I pass in a subjectAltName via -addext (or via any means) to the CSR, the subjectAltName will pass into the signed cert when executing the following (the following are openssl commands for the Intermediate Cert to sign and create a client or server based cert, and it all functions fine, except for what I just stated):

openssl ${algo_GEN} -out $PRIVATE_FILE

openssl req -config $CNF_FILE -key $PRIVATE_FILE -new -addext "subjectAltName = ${SAN_LIST}" -sha384 -out $CSR_FILE << EOF





${CERT_ID}

EOF

openssl ca -batch -config $CNF_FILE -extensions ${EXTENSION} -days 375 -notext -md sha384 -in 

Trying to create the root certificate using:

openssl req -config openssl.cnf 
    -key private/ca.key.pem 
    -new -x509 -days 7300 -sha256 -extensions v3_ca 
    -out certs/ca.cert.pem

I am getting the following error.

Error Loading extension section v3_ca

I have looked over the config to make sure I didn’t fat finger anything but the section v3_ca is there and has all the parameters it needs. I’ve never set this up before so I’m not familiar with the pitfalls. Could someone point me in the right direction as to what I’m doing wrong? I have pasted my full config file here so you can look it over if you are so inclined.

[ ca ]
# 'man ca'
default_ca = CA_default

[ CA_default ]
# Directory and file locations.
dir                     = /root/ca
certs                   = $dir/certs
crl_dir                 = $dir/crl
new_certs_dir           = $dir/newcerts
database                = $dir/index.txt
serial                  = $dir/serial
RANDFILEq               = $dir/private/.rand

# The root key and root certificate.
private_key             = $dir/crlnumber
crl                     = $dir/crl/ca.crl.pem
crl_entensions          = crl_ext
default_crl_days        = 30

# SHA-1 is depricated, use SHA-2
default_md              = sha256

name_opt                = ca_default
cert_opt                = ca_default
default_days            = 375
preserve                = no
policy                  = policy_strict

[ policy_strict ]
# The root ca should only sign intermediate certificates that match.
# See the POLICY FORMAT section of 'man ca'.
countryName             = match
stateOrProvinceName     = match
organizationName        = match
organizationalUnitName  = optional
commonName              = supplied
emailAddress            = optional

[ policy_loose ]
# Allow the intermediate CA to sign a more diverse range of certificates.
# See the POLICY FORMAT section of the 'man ca'.
countryName             = optional
stateOrProvinceName     = optional
organizationName        = optional
organizationalUnitName  = optional
commonName              = supplied
emailAddress            = optional

[ req ]
# Options for the 'req' tool.
# See 'man req'.
default_bits            = 4096
distinguished_name      = req_distinguished_name
string_mask             = utf8only
default_md              = sha256
x509_extensions         = v3_ca

[ req_distingushed_name ]
# See <https://en.wikipedia.org/wiki/Certificate_signing_request>.
country_Name            = Country Name (2 letter code)
stateOrProvinceName     = State or Province Name
lacalityName            = Locality Name
0.organizationName      = Organization Name
organizationalUnitName  = Organizational Unit Name
commonName              = Common Name
emailAddress            = Email Address

# Here are some default values
countryName_default             = US
stateOrProvinceName_default     = Nebraska
localityName_default            = Minden
0.organizationName_default      = RoyalEng
#organizationalUnitName_default =
#emailAddress_default           =

[v3_ca]
# Extensions for a typical CA (`man x509v3_config`).
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = critical, CA:true
keyUsage = critical, digitalSignature, cRLSign, keyCertSign

[ v3_intermediate_ca ]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = critical, CA:true, pathlen:0
keyUsage = critical, digitalSignature, cRLSign, keyCertSign

[ usr_cert ]
# Extensions for client certificates (`man x509v3_config`).
basicConstraints = CA:FALSE
nsCertType = client, email
nsComment = "OpenSSL Generated Client Certificate"
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
keyUsage = critical, nonRepudiation, digitalSignature, keyEncipherment
extendedKeyUsage = clientAuth, emailProtection

[ server_cert ]
# Extensions for server certificates (`man x509v3_config`).
basicConstraints = CA:FALSE
nsCertType = server
nsComment = "OpenSSL Generated Server Certificate"
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer:always
keyUsage = critical, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth

[ crl_ext ]
# Extension for CRLs (`man x509v3_config`).
authorityKeyIdentifier=keyid:always

[ ocsp ]
# Extension for OCSP signing certificates (`man ocsp`).
basicConstraints = CA:FALSE
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
keyUsage = critical, digitalSignature
extendedKeyUsage = critical, OCSPSigning

Понравилась статья? Поделить с друзьями:
  • Error loading editable poly
  • Error loading driver обновление bios
  • Error loading dll game dll
  • Error loading dll cryrenderd3d11 dll error code 126
  • Error loading dll cryrenderd3d10 dll error code 126 archeage