Apache¶
Jūs varat konfigurēt Apache httpd, lai izmantotu NetHSM, izmantojot OpenSSL dzinēju, kas tad izmanto NetHSM PKCS#11 moduli.
Sertifikāta failam jābūt diskā, bet privāto atslēgu var izmantot no NetHSM.
Pilns piemērs ir pieejams zemāk.
OpenSSL konfigurācija¶
Iestatiet OpenSSL dzinēju, sekojot OpenSSL dzinēja iestatīšanas rokasgrāmatai. (OpenSSL pakalpojumu sniedzēji vēl netiek atbalstīti Apache httpd.)
Httpd konfigurācija¶
Pievienojiet httpd.conf šādas rindas :
Listen 443
#...
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
LoadModule ssl_module modules/mod_ssl.so
#...
<VirtualHost *:443>
DocumentRoot /usr/local/apache2/htdocs
SSLEngine on
SSLCertificateFile /certs/certificate.pem
SSLCertificateKeyFile "pkcs11:object=webserver"
ErrorLog /tmp/a-error.log
CustomLog /tmp/a-access.log combined
</VirtualHost>
The SSLCertificateFile must point to a certificate file on the disk.
The SSLCertificateKeyFile should be a PKCS#11 URI pointing to the private key in the NetHSM.
Piezīme
Sertifikāts ir jāģenerē atsevišķi un pēc tam jāielādē NetHSM. Ja sertifikāts diskā un atslēga NetHSM nesakrīt, httpd nesāksies.
libnethsm_pkcs11 konfigurācija¶
slots:
- label: LocalHSM
description: Local HSM (docker)
url: "https://192.168.3.161:8443/api/v1"
operator:
username: "operator"
password: "opPassphrase"
To secure the password you can provide it via an environment variable (see Passwords) or provide it in the httpd configuration:
SSLCertificateKeyFile "pkcs11:object=webserver;type=private;pin=opPassphrase";
Piemērs¶
Ja vēlaties eksperimentēt ar doto piemēru, izmantojiet git, lai klonētu nethsm-pkcs11 repozitoriju un izpildiet šādas komandas:
Brīdinājums
Palaižot ģenerēšanas skriptu, tiek dzēsta webserver atslēga un tā tiek aizstāta.
Configure a NetHSM, either a real one or a container. See the getting-started guide for more information. Besides an administrator, you are going to need an operator account.
Lejupielādējiet un instalējiet jaunāko versiju nethsm-pkcs11 draiveris draiveris ir pieejams šeit.
Instalējiet OpenSSL PKCS11 dzinēju, kā aprakstīts OpenSSL rokasgrāmatā. Jums nav nepieciešams izveidot konfigurācijas failu.
Pielāgojiet mainīgos
HOST,ADMIN_ACCOUNTunADMIN_ACCOUNT_PWDcontainer/apache/generate.shtā, laiHOSTsaturētu jūsu NetHSMs URL un portu,ADMIN_ACCOUNTsaturētu administratora konta lietotājvārdu unADMIN_ACCOUNT_PWDatbilstošo paroli. Tālāk konfigurējiet OpenSSL PKCS11 dzinēja absolūto ceļuOPENSSL_PKCS11_ENGINE_PATHun NetHSM PKCS11 bibliotēkas absolūto ceļuNETHSM_PKCS11_LIBRARY_PATH.Create a NetHSM PKCS11 configuration file in one of the known locations, e.g.,
/etc/nitrokey/p11nethsm.conf. It must have configured an operator account and use the same NetHSM instance specified in the generate script before.Atjauniniet PKCS11 konfigurāciju vietnē
container/apache/p11nethsm.confar savu NetHSMs URL un derīgiem operatora akreditācijas datiem.Sertifikāta un atslēgas ģenerēšana.
./container/apache/generate.sh
Izveidojiet konteineru.
docker build -f container/apache/Dockerfile . -t pkcs-httpd
Palaist konteineru.
docker run -p 9443:443 -p 9080:80 pkcs-httpd
Apache testa lapa būs pieejama https://localhost:9443/. Ņemiet vērā, ka jūsu pārlūkprogramma, cerams, brīdinās jūs, ka vietnes sertifikāts ir pašparakstīts.