User Tools

Site Tools


it:it_navody:bezpecnost

This is an old revision of the document!


OpenSSL

Některé z příkazů využívají přepínač -config, za kterým následuje cesta ke konfiguračnímu souboru. Z tohoto souboru jsou načítány některé informace potřebné pro generování certifikátů. Obsah soubor je umístěn na konci textu.

Obousměrné SSL

Vytvoříme self-signed certifikát CA s klíčem

openssl req -config ./openssl.cnf -newkey rsa:2048 -nodes -keyform PEM -keyout firma.CA.key -x509 -days 3650 -extensions certauth -outform PEM -out firmaCA.cer

Vygenerujeme žádost o serverový certifikát pro CA společně s klíčem

openssl req -new -newkey rsa:2048 -nodes -keyout server.firma.cz.key -out server.firma.cz.req

Podobně vygenerujeme žádost o klientský certifikát pro CA společně s klíčem

openssl req -config ./openssl.cnf -new -newkey rsa:2048 -nodes -keyout client.firma.key -out client.firma.req

Naší CA vydáme z žádostí serverový i klientský certifikát

openssl x509 -req -in server.firma.cz.req -CA firmaCA.cer -CAkey firmaCA.key -set_serial 100 -extfile openssl.cnf -extensions server -days 730 -outform PEM -out server.firma.cz.cer

openssl x509 -req -in client.firma.cz.req -CA firmaCA.cer -CAkey firmaCA.key -set_serial 101 -extfile openssl.cnf -extensions client -days 730 -outform PEM -out client.firma.cz.cer

Klientský certifikát a klíč uložíme ve formátu PKCS#12

openssl pkcs12 -export -inkey client.firma.cz.key -in client.firma.cz.cer -out client.firma.cz.p12

Pro vynucení autentizace pomocí klientského certifikátu vložíme do virtualhostu apache následující konfiguraci.

SSLVerifyClient require

SSLVerifyDepth 10

SSLCACertificateFile /cesta/k/certifikatu/CA.cer

Vygenerování privátního klíče a žádosti o certifikát pro CA

Ukázka vygeneruje dva soubory server.firma.cz.key a server.firma.cz.req, kde se na rsa 2Kbit privátní klíč nepoužije passphrase.

openssl req -new -newkey rsa:2048 -nodes -keyout server.firma.cz.key -out server.firma.cz.req

Soubor server.firma.cz.req zašleme jako žádost o certifikát certifikační autoritě a získáme certifikát server.firma.cz.cer. V případě, že již máme privátní klíč, tak k němu můžeme vygenerovat žádost příkazem

openssl req -new -key server.firma.cz.pem -out server.firma.cz.pem

Vygenerování Self-Signed certifikátu a klíče

openssl req -x509 -newkey rsa:2048 -nodes -keyform PEM -keyout firma.key -days 3650 -outform PEM -out firma.cer

Vygenerování Self-Signed certifikátu z žádosti a klíče

openssl x509 -req -days 365 -in server.firma.cz.req -signkey server.firma.cz.key -out server.firma.cz.cer

Kontrola informací z žádosti a její verifikace

openssl req -in server.firma.cz.req -noout -text

openssl req -in server.firma.cz.req -noout -verify -key server.firma.cz.key

Kontrola privátního klíče

openssl rsa -noout -text -in server.firma.cz.key

Kontrola informací v certifikátu a jeho verifikace

openssl x509 -text -in ./server.firma.cz.cer

openssl verify server.firma.cz.cer

openssl pkcs12 -info -in ./server.firma.cz.p12

Konverze formátů

Pokud potřebujeme změnit formát lze vhodně zkombinovat direktivy -inform a -outform. openssl x509 -outform der -in server.firma.cz.req -out server.firma.cz.req.der

Export certifikátu s klíčem z pkcs12.

openssl pkcs12 -in ./file.oksystem.cz.2.p12 -clcerts -nokeys -out ./file.oksystem.cz.2.cer

openssl pkcs12 -in ./file.oksystem.cz.2.p12 -nocerts -nodes -out file.oksystem.cz.2.key

Import certifikátu s klíčem do pkcs12.

openssl pkcs12 -export -inkey client.firma.cz.key -in client.firma.cz.cer -out client.firma.cz.p12

Odstranění passphrase z privátního klíče

openssl rsa -in server.firma.cz.key -out server.firma.cz-bezpassphrase.key

Připojení k smtp serveru

openssl s_client -connect remote.host:25 -starttls smtp

Konfigurační soubor openssl.cnf

[ req ] default_md = sha2 distinguished_name = req_distinguished_name [ req_distinguished_name ] countryName = Country countryName_default = CZ countryName_min = 2 countryName_max = 2 localityName = Locality localityName_default = Prague organizationName = Organization organizationName_default = OKsystem a.s. commonName = Common Name commonName_max = 64 [ certauth ] subjectKeyIdentifier = hash authorityKeyIdentifier = keyid:always,issuer:always basicConstraints = CA:true crlDistributionPoints = @crl [ server ] basicConstraints = CA:FALSE keyUsage = digitalSignature, keyEncipherment, dataEncipherment extendedKeyUsage = serverAuth nsCertType = server crlDistributionPoints = @crl [ client ] basicConstraints = CA:FALSE keyUsage = digitalSignature, keyEncipherment, dataEncipherment extendedKeyUsage = clientAuth nsCertType = client crlDistributionPoints = @crl [ crl ] URI=http://testca.local/ca.crl

it/it_navody/bezpecnost.1519906071.txt.gz · Last modified: 2019/08/02 11:18 (external edit)