Olaf Sweekhorst

robotic - web applications

Rüttenscheider Platz 10
45130 Essen
0201 800 950 24
info@skurrilewelt.de
USt ID DE 228 788 976

Lokales SSL Zertifikat für XAMPP

Wenn man einen SSL vhost auf einem Windows Rechner, um z.B. einen WebApp lokal zu entwickeln und zu testen, benötig man dafür ein SSL Zertifikat.

Die Domain soll zum Beispiel meinepwa.local heißen

Für alle benötigt man eine PowerShell Instanz, die als Administrator gestartet ist.

Root Zertifikat erstellen

$root = New-SelfSignedCertificate `
-DnsName "DEV-LOCAL-CA" `
-Type Custom `
-KeyExportPolicy Exportable `
-KeyUsageProperty Sign `
-KeyUsage CertSign,CRLSign `
-KeyAlgorithm RSA `
-KeyLength 2048 `
-NotAfter (Get-Date).AddYears(10) `
-CertStoreLocation "Cert:\LocalMachine\My" `
-FriendlyName "DEV-LOCAL-CA"

$store = New-Object System.Security.Cryptography.X509Certificates.X509Store("Root","LocalMachine")
$store.Open("ReadWrite")
$store.Add($root)
$store.Close()

Oder, falls bereits ein Root Zertifikat erstellt wurde, nur laden und anzeigen

$rootCert = Get-ChildItem Cert:\LocalMachine\My | Where-Object {
$_.FriendlyName -eq "DEV-LOCAL-CA"
} | Select-Object -First 1

und

$rootCert

Zertifikat

$domain = "meinepwa.local"
$rootCert = Get-ChildItem Cert:\LocalMachine\My | Where-Object { $_.FriendlyName -eq "DEV-LOCAL-CA" } | Select-Object -First 1

$server = New-SelfSignedCertificate `
-DnsName $domain `
-Signer $rootCert `
-CertStoreLocation "Cert:\LocalMachine\My" `
-KeyExportPolicy Exportable `
-KeyAlgorithm RSA `
-KeyLength 2048 `
-NotAfter (Get-Date).AddYears(3) `
-FriendlyName "$domain (DEV)"

$pwd = ConvertTo-SecureString -String "changeit" -AsPlainText -Force

Export-PfxCertificate `
-Cert "Cert:\LocalMachine\My\$($server.Thumbprint)" `
-FilePath "C:\xampp\apache\conf\meinepwa.local.pfx" `
-Password $pwd

$openssl = "C:\xampp\apache\bin\openssl.exe"

& $openssl pkcs12 -in "C:\xampp\apache\conf\meinepwa.local.pfx" -nocerts -nodes -out "C:\xampp\apache\conf\meinepwa.local.key" -passin pass:changeit
& $openssl pkcs12 -in "C:\xampp\apache\conf\meinepwa.local.pfx" -clcerts -nokeys -out "C:\xampp\apache\conf\meinepwa.local.crt" -passin pass:changeit

VHost und hosts

<VirtualHost *:443>
ServerName meinepwa.local
DocumentRoot "D:/htdocs/meinepwa/build"

SSLEngine on
SSLCertificateFile "C:/xampp/apache/conf/meinepwa.local.crt"
SSLCertificateKeyFile "C:/xampp/apache/conf/meinepwa.local.key"

<Directory "D:/htdocs/meinepwa/build">
Require all granted
AllowOverride All
</Directory>
</VirtualHost>

Die Pfade sind entsprechend anzupassen

und in die hosts Datei eintragen

127.0.0.1   meinepwa.local

Apache neu starten.