« Security/sevices/SSLCertificate/Apache » : différence entre les versions
| Ligne 194 : | Ligne 194 : | ||
== Révoquer un certificat utilisateur == | == Révoquer un certificat utilisateur == | ||
<syntaxhighlight lang="bash"> | |||
cd /etc/pki/httpd/ | |||
./revoke-certificate.sh <USER> | |||
</syntaxhighlight> | |||
Version du 22 décembre 2012 à 17:29
Préparation
Création du répertoire des certificats
mkdir /etc/pki/httpd && cd /etc/pki/httpd
Création du fichier de configuration de nos futurs certificats
On créer le fichier <path>/etc/pki/httpd/ssl.cnf</path>
HOME = . RANDFILE = .rand [ca] default_ca = ca_default [ca_default] dir = . certs = $dir/certs crl_dir = $dir/crl database = $dir/index.txt new_certs_dir = $dir/newcerts certificate = $dir/%s_ca_cert.pem private_key = $dir/private/%s_ca_key.pem serial = $dir/serial crl = $dir/crl.pem x509_extensions = usr_cert name_opt = ca_default cert_opt = ca_default default_days = 3650 default_crl_days = 30 default_md = md5 preserve = no policy = policy_match [policy_match] countryName = match stateOrProvinceName = match organizationName = match organizationalUnitName = optional commonName = supplied emailAddress = optional [req] default_bits = 1024 default_keyfile = privkey.pem distinguished_name = req_distinguished_name attributes = req_attributes x509_extensions = v3_ca # The extentions to add to the self signed cert string_mask = MASK:0x2002 [req_distinguished_name] countryName = Country Name (2 letter code) countryName_default = FR countryName_min = 2 countryName_max = 2 stateOrProvinceName = State or Province Name (full name) stateOrProvinceName_default = Paca localityName = Locality Name (eg, city) localityName_default = Cavaillon 0.organizationName = Organization Name (eg, company) 0.organizationName_default = B2PWeb organizationalUnitName = Organizational Unit Name (eg, section) commonName = Common Name (eg, your name or your server\'s hostname) commonName_max = 64 emailAddress = Email Address 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 Generated Certificate" subjectKeyIdentifier = hash authorityKeyIdentifier = keyid,issuer:always [v3_ca] subjectKeyIdentifier = hash authorityKeyIdentifier = keyid:always,issuer:always basicConstraints = CA:true
Création des scripts de génération de certificats
Par simplicité, on va se servir de ces scripts pour générer les certificats des utilisateurs.
Script de génération des certificats : <path>/etc/pki/httpd/generate-certificate.sh</path>
#!/bin/bash
#if you change your certificate authority name to something else you will need to change the caname value to reflect the change.
caname=httpd
# user is equal to parameter one or the first argument when you actually run the script
user=$1
if [[ "$user" == "" ]]
then
echo "Usage: $(basename $0) USER"
exit
fi
echo "Generate certificates for \"${user}\""
openssl genrsa -out certs/${user}.key 2048
cat ssl.cnf | sed 's/insert_hostname/'${user}'/'> ssl2.cnf
openssl req -config ssl2.cnf -new -nodes -out certs/${user}.csr -key certs/${user}.key
openssl ca -config ssl2.cnf -keyfile private/${caname}_ca_cert.key -cert ${caname}_ca_cert.crt \
-out certs/${user}.crt -outdir certs -infiles certs/${user}.csr
cat certs/${user}.crt certs/${user}.key > ${user}.pem
mv ssl2.cnf confs/${user}-ssl.cnf
Script de génération des certificats pour les navigateurs Web : <path>/etc/pki/httpd/generate-web-certificate.sh</path>
#!/bin/bash
#if you change your certificate authority name to something else you will need to change the caname value to reflect the change.
caname=httpd
# user is equal to parameter one or the first argument when you actually run the script
user=$1
if [[ "$user" == "" ]]
then
echo "Usage: $(basename $0) USER"
exit
fi
echo "Generate web certificates for \"${user}\""
openssl pkcs12 -export -inkey certs/${user}.key -in certs/${user}.crt -CAfile ${caname}_ca_cert.crt \
-out certs/${user}_browser_cert.p12
Script de revocation de certificats : <path>/etc/pki/httpd/revoke-certificate.sh</path>
#!/bin/bash
#if you change your certificate authority name to something else you will need to change the caname value to reflect the change.
caname=httpd
# user is equal to parameter one or the first argument when you actually run the script
user=$1
if [[ "$user" == "" ]]
then
echo "Usage: $(basename $0) USER"
exit
fi
echo "Revoke certificates for \"${user}\""
openssl -revoke ${user}.pem
openssl ca -gencrl -config /etc/openssl.cnf -out crl/sopac-ca.crl
Génération de l'autorité de certification
Toujours depuis le répertoire /etc/pki/httpd, on initialise notre générateur et on génère l’autorité de certification. Celle-ci se compose d'une paire clé/certificat qui servira à signer tous les autres certificats.
Ici, le CN sera obligatoirement le nom d'hôte du serveur (FQDN), les autres renseignements ne sont pas bloquants pour la suite.
cd /etc/pki/httpd/
mkdir {certs,private,confs}
touch index.txt
echo 01 > serial
openssl genrsa -out private/httpd_ca_cert.key 2048
openssl req -config ssl.cnf -new -x509 -days 3650 -key private/httpd_ca_cert.key \
-out httpd_ca_cert.crt -extensions v3_ca
Générer les certificats des utilisateurs
Génération des certificats des utilisateurs. Cette partie est la seule qui est exécuter plusieurs fois
cd /etc/pki/httpd/
./generate-certificate.sh <USER>
./generate-web-certificate.sh <USER>
Révoquer un certificat utilisateur
cd /etc/pki/httpd/
./revoke-certificate.sh <USER>