PKI et répondeur ocsp sous debian

Par lours , 11 novembre, 2015

Mise en place d'un pki.

Devant gérer plusieurs type de certificats (mail, web , wifi, ldap, ...) la mise en place d'une gestion centralisée des certificats devient donc impératif.

Le public utilisateur étant bien définit la mise en place du certificat racine n'est pas bloquant, aucun service vers le public n'étant offert, et un certificat autosigné est suffisant.

Afin de créer les certificats facilement, j'ai longtemps utilisé tinyca2. Les nouvelle recommandation de certificat rendant obsolète mes "vieux certificat" et tinyca2 ne supportant (sans patch) que ssl et pas tls j'ai donc opté pour xca .

Ce logiciel permet de générer les certificats dans un système de base de donné sécurisé par mot de passe. Un système d'exportation permet d'obetnir un dump de la base et donc l'ensemble des fichiers devient accéssible dans le répertoire de dump.

Mise en place d'oscp.

La nouveauté étant de mettre en place un ocspd qui indique la validité des certificats, je me penche donc sur le problème.

Ajout d'information dans la CA:

La première chose est de créer un certificat d'authorité contenant le lieu ou l'on peut trouver le répondeur ocsp:

Authority Information Access:
                OCSP - URI:http://ocspd.mondomaine.lan/

Création du certificat de signature.

Il faut pour que tout fonction un certificat signé par la CA et pouvant signer donc contenant au moins les tags suivants:

Netscape Cert Type:
SSL Client, SSL Server, S/MIME, Object Signing
X509v3 Extended Key Usage:
OCSP Signing,

==> création du certificat oscpd.domain.lan

Le serveur ocsp:

Simple a mettre en place avec openssl sous linux :

openssl ocsp -index /path_to/index.txt \
             -port 80 \
             -rsigner /path_to/ocspd.crt \
             -rkey /path_to/ocspd.pem \
             -CApath /etc/ssl/certs/ \
             -CA /etc/ssl/certs/ca.crt 
             -text -out /path_to/log.txt

Le serveur ocspd.domain.lan sera donc à l'écoute sur le port 80

Le problème du index.txt :

xca ne génère pas de fichier index.txt , donc impossible de faire fonctionner openssl. Heureusement je trouve le script de janjust sur forums.openvpn.net qui met permet de crée ce fichier index.txt de même que serial les deux fichier manquant à xca:

cd

#!/bin/sh

##############################################################################
#Modif par
#              ,===,._
#              |      `",
#              |        /
#         ,-..-"-.=-,,_/
#        /,- \.""-`\    )_
#        \_       - '--'  \
#         /       0 __0 7_/
#         |/  _    (__)  \           /`|
#          |/(@)         |`   _.-"\-;  '.
#           \ #    \/   /'_.-"     \ \ `)\
#          .="#,_ __ _,'`           ;-'-.`)
#        __`;.#/|/  \/ \.           |
#      /`     # |   ()  |\    _.-"``
#     |    .--# |'--' `-`\|-'`
#     \   /   `)\   `./   \|
#      '. | .-#\ \    \    \
#        `\__/# \ |_  /`-. /|
#          /  #  \|`-`  . ` }
#         /  .#-, |     ;  ,}
#        /  / #  `'    ,  .}
#       / /`\ #        _,-'
#      //`   `#_   ,--'{
#     ((   _,;`    {   }
#      `""`  /     }   {
#        ,-'`      }    `-._
#      .'      _,-``,       `\
#      (_(_(_.'      `-.__)_)/
#                     lours974
#
###############################################################################
#
# Creation du fichier index.txt 
#E|R|VExpiry[RevocationDate]SerialunknownSubjectDN

path_todb="/path_tofile"

rm -rf ${path_todb}/index.txt.tmp
touch ${path_todb}/index.txt.tmp
for cert in ${path_todb}/certificates/*crt
do

  enddate=`openssl x509 -enddate -noout -in $cert | sed 's/notAfter=//' | awk '\
    { year=$4-2000;
      months="JanFebMarAprMayJunJulAugSepOctNovDec" ;
      month=1+index(months, $1)/3 ;
      day=$2;
      hour=substr($3,1,2) ;
      minutes=substr($3,4,2);
      seconds=substr($3,7,2);
      printf "%02d%02d%02d%02d%02d%02dZ", year, month, day, hour, minutes, seconds}'`

  serial=`openssl x509 -serial -noout -in $cert  |sed 's/serial=//'`
  subject=`openssl x509 -subject -noout -in $cert  |sed 's/subject= //'`

#ATTENTION TABULATION :=>
  echo "V	$enddate		$serial	unknown	$subject" >> ${path_todb}/index.txt.tmp
done

cat ${path_todb}/index.txt.tmp | sort -n -k3 -t\t | sort -u > ${path_todb}/index.txt
tail -n1 ${path_todb}/index.txt|cut -f 4 >${path_todb}/serial
rm -rf ${path_todb}/index.txt.tmp

Le client ocsp

Afin de tester le client on peut de nouveau utiliser openssl :

openssl ocsp -CApath /etc/ssl/certs/ \
             -CA /etc/ssl/certs/ca.crt \
             -issuer /path_to/ca.crt \
             -cert /path_to/cert_totest.crt \
             -url http://ocspd.domain.lan

done

Response verify OK
/path_to/cert_totest.crt: good

Utilisation de systemd

Pour mettre en place le daemon ocsp, j'utilise une commande systemd /etc/systemd/system/ocspd.service

[Unit]
Description=Serveur Ocsp
After=syslog.target

[Service]
Type=simple
ExecStart=/usr/bin/openssl ocsp -index /path_to/index.txt \
        -port 80 \
        -rsigner /path_to/ocsp.crt \
        -rkey /path_to/ocsp.pem \
        -CApath /etc/ssl/certs/ \
        -CA /etc/ssl/certs/ca.crt \
        -text
Restart=on-abort
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process

[Install]
WantedBy=multi-user.target
Alias=ocspd.service

 

Image attachée
xca