GuiguiAbloc

Tag: pki

Gestion d’une PKI : Installation d’un répondeur OCSP

par guiguiabloc le 05 jan, 2009, sous cisco, linux, sécurité

Déjà avant tout, Excellente Année 2009 à vous tous :-D

La gestion des certificats SSL et/ou X509 est une très bonne chose pour le contrôle et la sécurité de l’accès à vos systèmes d’informations.

Je ne parlerais pas de la façon de monter une PKI chez soi, j’avais écris un précédent billet ICI sur lequel vous pouvez vous baser.

OSCP ??? C’est quoi ce truc encore ….

OCSP signifie Online Certificate Status Protocol. C’est un protocole définit dans la RFC 2560 qui permet de valider un Certificat numérique X509.

En clair, cela vous permet d’offrir à vos « clients, amis, potes…. » une fonction de vérification en ligne de la validité d’une certificat.

Petit exemple (source Wikipédia) :

  1. Alice et Bob sont des clients d’Ivan, l’autorité de certification (AC). Ils possèdent le certificat de clé publique d’Ivan.
  2. Alice et Bob possèdent chacun un certificat de clé publique émis par Ivan.
  3. Alice veut effectuer une transaction avec Bob. Elle lui envoie donc son certificat contenant sa clé publique.
  4. Bob veut s’assurer que le certificat d’Alice n’a pas été révoqué. Il crée une requête OCSP contenant l’empreinte du certificat d’Alice et l’envoi à Ivan.
  5. Le répondeur OCSP d’Ivan vérifie le statut du certificat d’Alice dans la base de données de la CA.
  6. Le répondeur OCSP confirme la validité du certificat d’Alice en envoyant une réponse OCSP positive signée à Bob.
  7. Bob vérifie la signature cryptographique de la réponse.
  8. Bob effectue sa transaction avec Alice.

Je vous invite donc fortement, avant de continuer, à lire cet article explicatif.

Il existe un projet libre de répondeur OCSP , qui est inclus dans l’excellentissime projet OpenCA :

http://www.openca.org/projects/ocspd/

Commencons donc par télécharger les sources ICI (dernière version disponible, la 1.5.1-rc1).

L’installation est des plus basiques (a vous de voir pour le prefix) :

$ ./configure --prefix=/opt/ocspd
$ make
$ su
# make install

On créer un groupe et un user dédié et on affecte les droits :

pki:/opt/ocspd# groupadd ocspd
pki:/opt/ocspd# useradd -d /opt/ocspd -g ocspd -s /bin/false ocspd
pki:/opt/ocspd# chown -R ocspd:ocspd /opt/ocspd

Avec votre système de PKI préférée, générer un certificat publique et un certificat privé pour votre serveur OCSP. (attention au hostname, dans mon cas, ocsp.guiguiabloc.fr)

Copier les, ainsi que votre certificat CA, dans /opt/ocspd/etc/ocspd/certs

Il ne reste qu’a configurer votre répondeur :

cat /opt/ocspd/etc/ocspd/ocspd.conf
 
[ ocspd ]
default_ocspd   = OCSPD_default         # The default ocspd section
 
####################################################################
[ OCSPD_default ]
 
dir              = /opt/ocspd/etc/ocspd         # Where everything is kept
db               = $dir/index.txt               # database index file.
md               = sha1
 
ca_certificate    = $dir/certs/CA_Guiguiabloc-cert.pem      # The CA certificate
ocspd_certificate = $dir/certs/ocsp-cert.crt    # The OCSP server cert
ocspd_key         = $dir/certs/ocsp-key.pem   # The OCSP server key
pidfile           = $dir/ocspd.pid              # Main process pid
 
user                    = ocspd
group                   = ocspd
 
bind                    = 192.168.1.1 (l'ip sur laquelle écouter ou * pour toutes les interfaces)
port                    = 2560
crl_auto_reload = 3600
crl_reload_expired = yes
response        = ocsp_response
 
....
 
[ ocsp_response ]
dir                     = /opt/ocspd/etc/ocspd
ocsp_add_response_keyid = yes
 
...
 
[ first_ca ]
 
crl_url = file:////opt/ocspd/etc/ocspd/crls/crl-Guiguiabloc.pem (la liste de révocation de certificat)
ca_url  = file:////opt/ocspd/etc/ocspd/certs/CA_Guiguiabloc-cert.pem

Je vous laisse consulter le fichier conf en entier pour en comprendre le contenu et le modifier suivant vos besoins, mais la configuration ci-dessous, très simple, fonctionne pour un premier test.

Ne reste qu’a lancer le démon et verifier le syslog :

pki:#/opt/ocspd/sbin/ocspd -c /opt/ocspd/etc/ocspd/ocspd.conf -v &
 
Jan  5 14:56:15 pki ocspd[22154]: OpenCA OCSPD v1.5.1 - starting.
Jan  5 14:56:15 pki ocspd[22154]: reading certificate file (/opt/ocspd/etc/ocspd/certs/ocsp-cer
t.crt).
Jan  5 14:56:15 pki ocspd[22154]: Reading Private Key file /opt/ocspd/etc/ocspd/private/ocsp-ke
y.pem
Jan  5 14:56:15 pki ocspd[22154]: reading CA certificate file.
Jan  5 14:56:15 pki ocspd[22154]: OCSP Daemon setup completed
Jan  5 14:56:15 pki ocspd[22154]: variable lookup failed for OCSPD_default::chroot_dir
Jan  5 14:56:15 pki ocspd[22154]: Auto CRL reload every 3600 secs
Jan  5 14:56:15 pki ocspd[22154]: Reload on expired CRLs enabled
Jan  5 14:56:15 pki ocspd[22154]: Number of CAs in configuration is 1
Jan  5 14:56:15 pki ocspd[22154]: INFO::FORMAT::CA Cert [//opt/ocspd/etc/ocspd/certs/CA_Guiguiabloc-cert.pem] is PEM formatted
Jan  5 14:56:15 pki ocspd[22154]: CA CERT for first_ca loaded successfully.
Jan  5 14:56:15 pki ocspd[22154]: CA List Entry added (CA list num 0)
Jan  5 14:56:15 pki ocspd[22154]: INFO::CRL RELOAD::File Protocol
Jan  5 14:56:15 pki ocspd[22154]: INFO::FILE::CRL is in PEM format
Jan  5 14:56:15 pki ocspd[22154]: CRL loaded [ first_ca ]
Jan  5 14:56:15 pki ocspd[22154]: CRL and CA cert [0:1] check ok
Jan  5 14:56:15 pki ocspd[22154]: CRL matching CA cert ok [ 1 ]
Jan  5 14:56:15 pki ocspd[22154]: INFO::CRL::Verify 1 [OK=1]
Jan  5 14:56:15 pki ocspd[22154]: INFO::CRL is Valid
Jan  5 14:56:15 pki ocspd[22154]: INFO::CRL::16 Entries [ first_ca ]
Jan  5 14:56:15 pki ocspd[22154]: CRL loaded successfully [first_ca]
Jan  5 14:56:15 pki ocspd[22154]: variable lookup failed for ocsp_response::ocsp_add_response_c
erts
Jan  5 14:56:15 pki ocspd[22154]: variable lookup failed for OCSPD_default::crl_check_validity
Jan  5 14:56:15 pki ocspd[22154]: Configuration loaded and parsed
Jan  5 14:56:15 pki ocspd[22154]: INFO::Local Address 192.168.1.1 [2560]
Jan  5 14:56:15 pki ocspd[22154]: INFO::OPENCA_SRV_INFO_TREAD::new thread created

Bien évidemment, vous fournissez au répondeur OCSP, la Liste de révocation des certificats (fichier CRL) et la database (index.txt).
Si vous utilisez easyCA, ils sont générés sous $DIR et $DIR/crl par défaut (voir votre fichier openssl.cnf).

Et maintenant, interrogeons le serveur OCSP pour savoir si mon Certificat (ici webmail.guiguiabloc.fr) est encore valable :

pki:# openssl ocsp -issuer CA_Guiguiabloc-cert.pem -CAfile CA_Guiguiabloc-cert.pem -cert webmail.guiguiabloc.fr.crt -url http://192.168.1.1:2560 -text
OCSP Request Data:
    Version: 1 (0x0)
    Requestor List:
        Certificate ID:
          Hash Algorithm: sha1
          Issuer Name Hash: 4A694097441CA470D697E82AF367D1F196B59680
          Issuer Key Hash: 6490C296FF639D9B75A899E2DB29DC7DA42EE38D
          Serial Number: 13
    Request Extensions:
        OCSP Nonce:
            0410DDDA8DFEF460BA0C13ACCEBE7CDFDCB9
OCSP Response Data:
    OCSP Response Status: successful (0x0)
    Response Type: Basic OCSP Response
    Version: 1 (0x0)
    Responder Id: C = FR, ST = Bretagne, O = Guiguiabloc, OU = Guiguiabloc, CN = ocsp.guiguiabloc.fr, emailAddress = pki@guiguiabloc.fr
    Produced At: Jan  5 14:21:40 2009 GMT
    Responses:
    Certificate ID:
      Hash Algorithm: sha1
      Issuer Name Hash: 4A694097441CA470D697E82AF367D1F196B59680
      Issuer Key Hash: 6490C296FF639D9B75A899E2DB29DC7DA42EE38D
      Serial Number: 13
    Cert Status: good
    This Update: Jan  5 14:16:51 2009 GMT
    Next Update: Jan  5 14:26:40 2009 GMT
 
    Response Extensions:
        OCSP Nonce:
            0410DDDA8DFEF460BA0C13ACCEBE7CDFDCB9
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number: 16 (0x10)
        Signature Algorithm: md5WithRSAEncryption
        Issuer: C=FR, ST=Bretagne, L=Brest, O=Guiguiabloc, OU=Guiguiabloc, CN=Guiguiabloc CA Authority/emailAddress=pki@guiguiabloc.fr
        Validity
            Not Before: Jul 18 08:08:25 2008 GMT
            Not After : Jul 17 08:08:25 2013 GMT
        Subject: C=FR, ST=Bretagne, O=Guiguiabloc, OU=Guiguiabloc, CN=ocsp.guiguiabloc.fr/emailAddress=pki@guiguiabloc.fr
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
            RSA Public Key: (1024 bit)
                Modulus (1024 bit):
                    00:bb:c8:c3:c0:78:26:88:8c:45:6c:2a:1b:88:fd:
                    71:57:c0:bb:23:e1:1e:40:86:d2:94:af:fc:e7:74:
                    41:3d:41:39:ac:a6:51:dc:4d:e8:80:53:a3:73:5d:
                    74:0e:1f:04:b1:78:dc:ad:45:65:5b:4f:0e:b2:92:
                    3c:bc:64:bb:3e:70:2c:ca:b8:ea:dc:fc:33:31:01:
                    d2:05:b2:e2:60:0c:d2:a6:c1:e9:83:b0:ca:d9:42:
                    98:44:8b:c3:df:63:dc:17:02:51:b6:f2:da:0e:c6:
                    81:fa:78:1c:d2:ca:56:52:f3
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Basic Constraints:
                CA:FALSE
            X509v3 Key Usage:
                Digital Signature
            X509v3 Extended Key Usage:
                OCSP Signing
            X509v3 Issuer Alternative Name:
 
            X509v3 Subject Key Identifier:
                1A:18:4A:7A:BC:DB:3E:CD:60:87:0B:A3:11:4D:4F:E6:CE:19:17:27
            X509v3 Authority Key Identifier:
                keyid:64:90:C2:96:FF:63:9D:9B:75:A8:99:E2:DB:29:DC:7D:A4:2E:E3:8D
                DirName:/C=FR/ST=Bretagne/L=Brest/O=GuiGuiabloc/OU=Guiguiabloc/CN=Guiguiabloc CA Authority/emailAddress=pki@guiguiabloc.fr
                serial:B9:0E:D5:3E:0F:DA:79:FF
 
            Authority Information Access:
                OCSP - URI:http://ocsp.guiguiabloc.fr/
 
    Signature Algorithm: md5WithRSAEncryption
        0c:3a:3f:79:7e:e4:21:be:1b:d1:d4:ef:8f:1d:33:af:f2:88:
        eb:0f:40:cb:24:50:9b:47:cc:61:e2:a9:a3:6e:c5:4f:2a:7c:
        b5:03:f1:a1:b8:b7:23:c7:e1:00:61:3a:c0:7c:8f:c6:2f:c7:
        6a:c9:98:ad:af:ff:28:db:c6:1f:17:d3:54:f3:d7:1a:96:51:
        19:04:6c:f8:92:74:70:de:54:c1:55:d3:9d:27:99:8b:09:be:
        98:27:e6:5b:1e:14:a2:a9:d2:cb:a2:d7:52:8a:e1:ac:9b:a7:
        52:a2:5b:90:dc:cc:8f:33:4b:7a:99:60:4d:5e:b9:e6:71:ed:
        be:92
-----BEGIN CERTIFICATE-----
MIID/DCCA2WgAwIBAgIBEDANBgkqhkiG9w0BAQQFADCBnDELMAkGA1UEBhMCRlIx
ETAPBgNVBAgTCEJyZXRhZ25lMQ4wDAYDVQQHEwVCcmVzdDEVMBMGA1UEChMMU3R5
eCBOZXR3b3JrMRAwDgYDVQQLEwdTdHl4bmV0MSIwIAYDVQQDExlTdHl4IE5ldHdv
cmsgQ0EgQXV0aG9yaXR5MR0wGwYJKoZIhvcNAQkBFg5wa2lAc3R5eG5ldC5mcjAe
Fw0wODA3MTgwODA4MjVaFw0xMzA3MTcwODA4MjVaMIGCMQswCQYDVQQGEwJGUjER
MA8GA1UECBMIQnJldGFnbmUxFTATBgNVBAoTDFN0eXggTmV0d29yazEQMA4GA1UE
CxMHU3R5eG5ldDEYMBYGA1UEAxMPb2NzcC5zdHl4bmV0LmZyMR0wGwYJKoZIhvcN
AQkBFg5wa2lAc3R5eG5ldC5mcjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA
psHpg7DK2UKYRIvD32PcFwJRtvLaDsaB+ngc0spWUvMCAwEAAaOCAWQwggFgMAkG
A1UdEwQCMAAwCwYDVR0PBAQDAgeAMBMGA1UdJQQMMAoGCCsGAQUFBwMJMAkGA1Ud
EgQCMAAwHQYDVR0OBBYEFBoYSnq82z7NYIcLoxFNT+bOGRcnMIHRBgNVHSMEgckw
gcaAFGSQwpb/Y52bdaiZ4tsp3H2kLuONoYGipIGfMIGcMQswCQYDVQQGEwJGUjER
MA8GA1UECBMIQnJldGFnbmUxDjAMBgNVBAcTBUJyZXN0MRUwEwYDVQQKEwxTdHl4
IE5ldHdvcmsxEDAOBgNVBAsTB1N0eXhuZXQxIjAgBgNVBAMTGVN0eXggTmV0d29y
ayBDQSBBdXRob3JpdHkxHTAbBgkqhkiG9w0BCQEWDnBraUBzdHl4bmV0LmZyggkA
uQ7VPg/aef8wMwYIKwYBBQUHAQEEJzAlMCMGCCsGAQUFBzABhhdodHRwOi8vb2Nz
cC5zdHl4bmV0LmZyLzANBgkqhkiG9w0BAQQFAAOBgQAMOj95fuQhvhvR1O+PHTOv
8ojrD0DLJFCbR8xh4qmjbsVPKny1A/GhuLcjx+EAYTrAfI/GL8dqyZitr/8o28Yf
F9NU89callEZBGz4knRw3lTBVdOdJ5mLCb6YJ+ZbHhSiqdLLotdSiuGsm6dSoluQ
3MyPM0t6mWBNXrnmce2+kg==
-----END CERTIFICATE-----
Response verify OK
webmail.guiguiabloc.fr.crt: good

Réponse : GOOD tout va bien :-)

La réponse peut être: GOOD – REVOKED – UNKNOWN

Vous pouvez inclure directement dans votre certificat l’adresse de votre répondeur OCSP en ajoutant des extensions à votre openssl.cnf :

[OCSP]
 
basicConstraints        = CA:FALSE
keyUsage                = digitalSignature
extendedKeyUsage        = OCSPSigning
issuerAltName           = issuer:copy
subjectKeyIdentifier    = hash
authorityKeyIdentifier  = keyid:always,issuer:always
authorityInfoAccess     = OCSP;URI:http://ocsp.guiguiabloc.fr/
 
[SERVEUR_OCSP]
nsComment                       = "Guiguiabloc Certificate"
subjectKeyIdentifier            = hash
authorityKeyIdentifier          = keyid,issuer:always
issuerAltName                   = issuer:copy
basicConstraints                = critical,CA:FALSE
keyUsage                        = digitalSignature, nonRepudiation, keyEncipherment
nsCertType                      = server
extendedKeyUsage                = serverAuth
authorityInfoAccess             = OCSP;URI:http://ocsp.guiguiabloc.fr/
 
[CLIENT_OCSP]
nsComment                       = "Certificat Client SSL"
subjectKeyIdentifier            = hash
authorityKeyIdentifier          = keyid,issuer:always
issuerAltName                   = issuer:copy
basicConstraints                = critical,CA:FALSE
keyUsage                        = digitalSignature, nonRepudiation
nsCertType                      = client
extendedKeyUsage                = clientAuth
authorityInfoAccess             = OCSP;URI:http://ocsp.guiguiabloc.fr/

Puis d’invoquer l’extension lors de la création du certificat avec openssl (-extensions CLIENT_OCSP (par exemple).

Dans Firefox, pour configurer l’interrogation automatique du répondeur OCSP, allez dans Outils/Options/Avance/Chiffrement et cliquez sur « Vérification ».

Génial non ? :-D

Petit bonus, sur votre Cisco préféré, on peut aussi faire de l’OCSP :-) :-)

rt-2611>en
Password:
rt-2611#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
rt-2611(config)#crypto pki trustpoint guiguiabloc
rt-2611(ca-trustpoint)#ocsp url http://ocsp.guiguiabloc.fr:2560
rt-2611(ca-trustpoint)#revocation-check ocsp none

La dernière ligne est la méthode de vérification, l’option none spécifie que le routeur passera la vérification OSCP si le répondeur ne répond pas.
Pour les IOS 12.3 et supérieure (la page chez Cisco LA )

Amusez vous bien :-)

6 Commentairess :, , plus...

PKI, PKI, oh ! PKI, PKI, ah !

par guiguiabloc le 02 déc, 2008, sous sécurité

« Mais qu’est ce tu chiffres DouDou dis donc ? PKI, PKI, c’est bon, c’est bon… »

Bon d’accord.. :oops:

Désolé pour la touche Tarte à la crème et nez rouge, ça m’a échappé :-?

La gestion d’une PKI n’est pas toujours évidente.

On se retrouve vite avec une usine à gaz qui si elle répond a des besoins en entreprise (exemple openCA qui est pour moi un outil très puissant, opensource et parfaitement utilisable en production), pour sa petite gestion personnelle, c’est un peu lourd.

Vous gérez donc vos certificats a la mimine, a coup d’openssl dans tout les sens en stockant a gauche et a droite, et mer…. ou j’ai mis mon CA Root… ou alors grace aux quelques scripts fournis en standard avec OpenVPN par exemple.

Bref, heureusement il existe un petit programme qui répond parfaitement à ce besoin; il s’agit d’easyCA.

Vous trouverez les sources ICI .

Il n’est plus maintenu depuis 2005 mais croyez moi, ce petit programme en simple script shell est une bombe et parfaitement utilisable.

J’ai contacté Ferry, l’auteur du script qui malheureusement semble un peu débordé pour apporter quelques améliorations.

Soit, c’est bien parce que c’est vous, je vous livre donc MA version d’easyCA avec quelques fonctions rajoutées (OCSP, choix du type de certificat serveur/client..)

easyCA Version GuiguiAbloc

Elle est bien entendu perfectible mais convient parfaitement à la gestion de ma pki personnelle.

Le fonctionnement est on ne peut plus basique.

Vous créez un répertoire ou vous déposer le easyCA.sh et l’openssl.cnf (que vous CONFIGUREZ avant !!!). (ps : pensez a supprimez la ligne « # !!!!! remove this line after configuration as it is NOT_CONFIGURED yet !!! »

Les champs sont suffisamment bien commentés pour que vous compreniez les champs à renseigner.

Ne reste qu’a lancer le easyca.sh :

=====================================================================
                      Certificate Management System
      easyCA version 0.9(6) by Ferry Kemps and Guiguiabloc
                              GPL Licensed
=====================================================================
 
   1) Sign a Certificate Signing Request (PKCS#10)
   2) Create a Server Certificate (PEM SelfSigned)
   3) Create a Client Certificate (PKCS#12)
   4) Create a Certificate Signing Request
   5) Generate Certificate Revocation List (CRL)
   6) List, Display and Revoke Certificates
 
   I) Initialize Root Certificate Authority (CA)
   O) Initialize OCSP Server Certificate
   B) Backup & Restore the Certificate environment
   R) Reinstall easyCA (erase)
 
 ==> Make your choice [none]:

Commencer par initaliser votre Certificat d’Autorité (I)

Puis a vous la création et la gestion de vos certificats :-)

-----------------------------------------------------------------------
--------------- Generate Certificate Signing Request ------------------
-----------------------------------------------------------------------
 
Enter Certificate CN (Common name|FQDN) like www.example.com [none]: blog.guiguiabloc.fr
Generating a 1024 bit RSA private key
......................++++++
..++++++
writing new private key to './private/blog.guiguiabloc.fr-key.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) [NL]:FR
State or Province Name (full name) [Gelderland]:Bretagne
Locality Name (eg, city) [Arnhem]:GuiguiTown
Organization Name (eg, company) [Your Company Name]:Guiguiabloc
Organizational Unit Name (eg, section) [HQ]:Guiguiabloc
Common Name (eg, your name or your server's hostname) []:blog.guiguiabloc.fr
Email Address [postmaster@domain.ext]:guiguiabloc@devnull
 
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
 
Certificate Signing Request (CSR) stored as: ./csr/blog.guiguiabloc.fr.csr
Certificate private-key stored as: ./private/blog.guiguiabloc.fr-key.pem
Press [enter] to continue
-----------------------------------------------------------------------
--------------- Certifiace Signing Request handling -------------------
-----------------------------------------------------------------------
 
 (CSR request files should be copied into directory: ./csr)
 
1: blog.guiguiabloc.fr.csr
 
 ==> Select the CSR to sign [none]: 1
 
 ==> Add OCSP Extension to Certificate ? [y/N]: y
 
 ==> Select the Usage Key [server|client|none]: server

Bref, je vous laisse jouer avec, vous verrez, cela vous simplifiera la vie.

Concernant l’extension OCSP, ce sera le sujet d’un prochain billet ou comment gérer la révocation de vos certificats, on-line :-D

6 Commentairess :, , plus...

Vous cherchez quelque chose ?

Utilisez le formulaire ci-dessous:

Vous ne trouvez pas ce que vous voulez ? Laisser un Commentaire sur un Billet !