Configure CA environment

# mkdir -p /etc/pki/LDAP_CA/private
# touch /etc/pki/LDAP_CA/index.txt
# echo 01 > /etc/pki/LDAP_CA/serial

Generate CA key

# cd /etc/pki/LDAP_CA/private
# openssl genrsa -out ca_server.key 4096
Generating RSA private key, 4096 bit long modulus (2 primes)
.......................................++++
.............................................................................................++++
e is 65537 (0x010001)

Generate CA certificate

# cd /etc/pki/LDAP_CA
# openssl req -new -x509 -days 365 -key private/ca_server.key -out ca_server.pem
You are about to be asked to enter information that will be incorporated
into your certificate request.
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.
-----
Country Name (2 letter code) [AU]:GB
State or Province Name (full name) [Some-State]:England
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Intellitect Water
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:ubuntu2004.localdomain
Email Address []:jpmigue@gmail.com

Create certificate extensions configuration file

# cat /root/server_cert_ext.cnf
[v3_ca]
basicConstraints = CA:FALSE
nsCertType = server
nsComment = "OpenSSL Generated Server Certificate"
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer:always
keyUsage = critical, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth

Modify openssl configuration file

dir        = ./LDAP_CA     # Where everything is kept

Generate private key for server certificate

# cd /etc/pki/LDAP_CA/private
# openssl genrsa -out ldap_server.key 4096
Generating RSA private key, 4096 bit long modulus (2 primes)
...................++++
.............++++
e is 65537 (0x010001)

Generate server certificate CSR

# cd /etc/pki/LDAP_CA/
# openssl req -new -key private/ldap_server.key -out ldap_server.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
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.
-----
Country Name (2 letter code) [AU]:GB
State or Province Name (full name) [Some-State]:England
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Intellitect Water
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:ubuntu2004.localdomain
Email Address []:jpmigue@gmail.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

Generate server certificate

# cd /etc/pki
# openssl ca -keyfile LDAP_CA/private/ca_server.key -cert LDAP_CA/ca_server.pem -in LDAP_CA/ldap_server.csr -out LDAP_CA/ldap_server.pem -extensions v3_ca -extfile /root/server_cert_ext.cnf
Using configuration from /usr/lib/ssl/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 1 (0x1)
        Validity
            Not Before: May 31 22:47:44 2022 GMT
            Not After : May 31 22:47:44 2023 GMT
        Subject:
            countryName               = GB
            stateOrProvinceName       = England
            organizationName          = Intellitect Water
            commonName                = ubuntu2004.localdomain
            emailAddress              = jpmigue@gmail.com
        X509v3 extensions:
            X509v3 Basic Constraints: 
                CA:FALSE
            Netscape Cert Type: 
                SSL Server
            Netscape Comment: 
                OpenSSL Generated Server Certificate
            X509v3 Subject Key Identifier: 
                E5:43:BD:82:36:92:3D:2A:E3:7B:6B:EA:EC:DA:E3:32:4B:59:7C:E9
            X509v3 Authority Key Identifier: 
                keyid:ED:1A:20:A8:EC:FB:9E:CB:C8:E0:95:72:4B:0F:3D:61:78:F0:65:F5
                DirName:/C=GB/ST=England/O=Intellitect Water/CN=ubuntu2004.localdomain/emailAddress=jpmigue@gmail.com
                serial:27:03:2E:03:21:F3:7C:BD:1B:FC:B3:3A:AD:F6:A2:CA:2D:79:C4:49 

            X509v3 Key Usage: critical
                Digital Signature, Key Encipherment
            X509v3 Extended Key Usage: 
                TLS Web Server Authentication
Certificate is to be certified until May 31 22:47:44 2023 GMT (365 days)
Sign the certificate? [y/n]:y   

1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated