Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # license : WTFPL
- ################################################################################
- #DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
- # Version 2, December 2004 #
- # #
- #Copyright (C) 2014 Fenrir <don't want spam> #
- # #
- #Everyone is permitted to copy and distribute verbatim or modified #
- #copies of this license document, and changing it is allowed as long #
- #as the name is changed. #
- # #
- # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
- # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION #
- # #
- # 0. You just DO WHAT THE FUCK YOU WANT TO. #
- ################################################################################
- # Directory where you want to install the stuff
- baseDir="/volume1/CA"
- # External domain name (from Internet)
- extDomain='publicdomain.name'
- # Internal domain name (from lan)
- intDomain='privatedomaine.name'
- # Server name
- srvName=`hostname -s`
- # External IP (from Internet)
- extIP='0.0.0.0'
- # Internal IP (from lan)
- intIP=`hostname -i`
- # Public server name
- dns1=$srvName.$extDomain
- # Private server name
- dns2=$srvName.$intDomain
- # Short server name
- dns3=$srvName
- # Public IP Address
- ip1=$extIP
- # Public IP Address
- ip2=$intIP
- # Country Name (2 letter code)
- countryName_default='FR'
- # State or Province Name (full name)
- stateOrProvinceName_default='IDF'
- # Locality Name (eg, city)
- localityName_default='My City'
- # Organization Name (eg, company)
- organizationName_default='My Home'
- # Organizational Unit Name (eg, section)
- organizationalUnitName_default='IT'
- # Email Address
- emailAddress_default='my@email.address'
- ###################################################################
- cd $baseDir
- mkdir $baseDir/ca
- mkdir $baseDir/ca/newcerts
- mkdir $baseDir/crt
- mkdir $baseDir/csr
- mkdir $baseDir/key
- mkdir $baseDir/rev
- cat <<EOT > $baseDir/openssl.cnf
- dir = $baseDir
- HOME = $baseDir
- RANDFILE = $baseDir/ca/.rnd
- [ ca ]
- default_ca = CA_default
- [ CA_default ]
- certs = $baseDir/ca/certs
- new_certs_dir = $baseDir/ca/newcerts
- database = $baseDir/ca/index.txt
- certificate = $baseDir/ca/ca.crt
- serial = $baseDir/ca/serial
- private_key = $baseDir/ca/ca.key
- default_days = 3650
- default_md = sha256
- preserve = no
- policy = policy_match
- [ policy_match ]
- countryName = optional
- stateOrProvinceName = optional
- organizationName = optional
- organizationalUnitName = optional
- commonName = supplied
- emailAddress = optional
- [ req ]
- default_md = sha256
- default_bits = 2048
- default_keyfile = privkey.pem
- distinguished_name = req_distinguished_name
- attributes = req_attributes
- req_extensions = v3_req
- string_mask = nombstr
- [ req_distinguished_name ]
- countryName = Country Name (2 letter code)
- countryName_default = ###countryName_default###
- countryName_min = 2
- countryName_max = 2
- stateOrProvinceName = State or Province Name (full name)
- stateOrProvinceName_default = ###stateOrProvinceName_default###
- localityName = Locality Name (eg, city)
- localityName_default = ###localityName_default###
- 0.organizationName = Organization Name (eg, company)
- 0.organizationName_default = ###organizationName_default###
- organizationalUnitName = Organizational Unit Name (eg, section)
- organizationalUnitName_default = ###organizationalUnitName_default###
- commonName = Common Name (eg, YOUR name)
- commonName_max = 64
- emailAddress = Email Address
- emailAddress_default = ###emailAddress_default###
- emailAddress_max = 64
- [ req_attributes ]
- challengePassword = A challenge password
- challengePassword_min = 4
- challengePassword_max = 20
- unstructuredName = An optional company name
- [ usr_cert ]
- basicConstraints = CA:FALSE
- nsComment = "OpenSSL Private Certificat"
- subjectKeyIdentifier = hash
- authorityKeyIdentifier = keyid,issuer
- #nsCaRevocationUrl = http://...
- #nsRevocationUrl = http://...
- [ v3_req ]
- basicConstraints = CA:FALSE
- keyUsage = nonRepudiation, digitalSignature, keyEncipherment
- subjectAltName = @alt_names
- [CA]
- nsComment = "OpenSSL Private Certificat"
- subjectKeyIdentifier = hash
- authorityKeyIdentifier = keyid,issuer:always
- basicConstraints = critical,CA:TRUE,pathlen:0
- keyUsage = keyCertSign, cRLSign
- default_md = sha256
- [SERVER]
- nsComment = "OpenSSL Private Certificat"
- subjectKeyIdentifier = hash
- authorityKeyIdentifier = keyid,issuer:always
- issuerAltName = issuer:copy
- basicConstraints = critical,CA:FALSE
- keyUsage = digitalSignature, nonRepudiation, keyEncipherment
- nsCertType = server
- extendedKeyUsage = serverAuth
- #crlDistributionPoints = URI:http://...
- subjectAltName = @alt_names
- [alt_names]
- DNS.1 = ###dns1###
- DNS.2 = ###dns2###
- DNS.3 = ###dns3###
- IP.1 = ###ip1###
- IP.2 = ###ip2###
- [ v3_ca ]
- subjectKeyIdentifier = hash
- authorityKeyIdentifier = keyid:always,issuer:always
- basicConstraints = CA:true
- [ crl_ext ]
- authorityKeyIdentifier = keyid:always,issuer:always
- [ proxy_cert_ext ]
- basicConstraints = CA:FALSE
- nsComment = "OpenSSL Private Certificat"
- subjectKeyIdentifier = hash
- authorityKeyIdentifier = keyid,issuer:always
- proxyCertInfo = critical,language:id-ppl-anyLanguage,pathlen:3,policy:foo
- EOT
- sed -i "s/###countryName_default###/${countryName_default}/g" $baseDir/openssl.cnf
- sed -i "s/###stateOrProvinceName_default###/${stateOrProvinceName_default}/g" $baseDir/openssl.cnf
- sed -i "s/###localityName_default###/${localityName_default}/g" $baseDir/openssl.cnf
- sed -i "s/###organizationName_default###/${organizationName_default}/g" $baseDir/openssl.cnf
- sed -i "s/###organizationalUnitName_default###/${organizationalUnitName_default}/g" $baseDir/openssl.cnf
- sed -i "s/###emailAddress_default###/${emailAddress_default}/g" $baseDir/openssl.cnf
- sed -i "s/###dns1###/${dns1}/g" $baseDir/openssl.cnf
- sed -i "s/###dns2###/${dns2}/g" $baseDir/openssl.cnf
- sed -i "s/###dns3###/${dns3}/g" $baseDir/openssl.cnf
- sed -i "s/###ip1###/${ip1}/g" $baseDir/openssl.cnf
- sed -i "s/###ip2###/${ip2}/g" $baseDir/openssl.cnf
- touch $baseDir/ca/index.txt
- echo 0001 > $baseDir/ca/serial
- openssl_bin=`which openssl`
- # Create Certificate Authority
- echo "################################################################################"
- echo "# #"
- echo "# Create Certificate Authority #"
- echo "# #"
- echo "################################################################################"
- $openssl_bin req -new -x509 -config ./openssl.cnf -sha256 -newkey rsa:2048 -nodes -days 3650 -keyout ca/ca.key -out ca/ca.crt
- # Create certificat request
- echo "################################################################################"
- echo "# #"
- echo "# Create certificat request : take care about Common name #"
- echo "# #"
- echo "################################################################################"
- $openssl_bin req -new -config ./openssl.cnf -newkey rsa:2048 -nodes -sha256 -keyout key/$srvName.key -out csr/$srvName.csr
- # Signing the certificate
- echo "################################################################################"
- echo "# #"
- echo "# Signing the certificate #"
- echo "# #"
- echo "################################################################################"
- $openssl_bin ca -config ./openssl.cnf -extensions SERVER -in csr/$srvName.csr -notext -out crt/$srvName.crt
- echo "################################################################################"
- echo "# #"
- echo "# !!! PRIVATE !!! key #"
- echo "# #"
- echo "################################################################################"
- cat key/$srvName.key
- echo "################################################################################"
- echo "# #"
- echo "# Certificate #"
- echo "# #"
- echo "################################################################################"
- cat crt/$srvName.crt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement