Skip to content

Instantly share code, notes, and snippets.

@DustinD2
Created December 8, 2012 01:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DustinD2/4238022 to your computer and use it in GitHub Desktop.
Save DustinD2/4238022 to your computer and use it in GitHub Desktop.
This script creates a CA using openssl on a mac. Creates a client certificate and signs it with the CA. Then creates the server certificate for the client.
#!/bin/bash
#This script creates a ca and signs a client key and configures
# the database.
#Configure the Root CA
mkdir ca
cd ca
mkdir certs crl newcerts private
echo "01" > serial
cp /dev/null ./index.txt
#this is the mac path
#be sure ca_default dir is .
cp /opt/local/etc/openssl/openssl.cnf .
#generate the key
openssl genrsa -des3 -out private/cakey.pem 4096
#generate a self-signed cert
openssl req -new -x509 -nodes -sha1 -key private/cakey.pem -out cacert.pem
#We are now ready to make an intermediate CA
mkdir ca2012
cd ca2012
cp ../openssl.cnf .
mkdir certs crl newcerts private
echo "01" > serial
cp /dev/null ./index.txt
openssl genrsa -des3 -out private/cakey.pem 4096
openssl req -new -sha1 -key private/cakey.pem -out ca2012.csr
#move our new signing request to the root and sign it
mv ca2012.csr ..
cd ..
openssl ca -extensions v3_ca -out ca2012.crt -in ca2012.csr -config openssl.cnf
mv ca2012.* ca2012
cd ca2012
mv ca2012.crt ca2012.pem
#create our ca chain file
cat ca2012.pem > chain.cert
cat ../cacert.pem >> chain.cert
#edit the path of the ca_default dir in the ca2012 openssl.cnf file
# change the path from . to ..
vi openssl.cnf
#create our server certificate
openssl genrsa -des3 -out myServer.key 4096
openssl req -new -key myServer.key -out myServer.csr
openssl ca -config openssl.cnf -policy policy_anything -out myServer.crt -infiles myServer.csr
mkdir certs/myServer
mv myServer.key myServer.csr myServer.crt certs
@cleitonpena
Copy link

Hi, @DustinD2
Thanks for script.
Line 35 returns the following error:

Using configuration from openssl.cnf Could not open file or uri for loading CA private key from ./demoCA/private/cakey.pem 40B6AA4AF87F0000:error:16000069:STORE routines:ossl_store_get0_loader_int:unregistered scheme:crypto/store/store_register.c:237:scheme=file 40B6AA4AF87F0000:error:80000002:system library:file_open:No such file or directory:providers/implementations/storemgmt/file_store.c:267:calling stat(./demoCA/private/cakey.pem)

Can you help me solve this problem?
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment