Skip to content

Instantly share code, notes, and snippets.

@jrusbatch
Created April 28, 2017 16:18
Show Gist options
  • Save jrusbatch/0722c2292dd574440a5e97406f5bb541 to your computer and use it in GitHub Desktop.
Save jrusbatch/0722c2292dd574440a5e97406f5bb541 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
EC_CURVE=secp384r1
SRC=$(pwd)
KEY_FILE="$SRC/$EC_CURVE.private-key"
CSR_FILE="$SRC/localhost.csr"
CERT_FILE="$SRC/localhost.crt"
CONFIG_FILE="$SRC/server.csr.cnf"
OUT_FILE="$SRC/localhost.pfx"
PATH=/usr/local/opt/openssl/bin:$PATH
openssl ecparam -out $KEY_FILE -name $EC_CURVE -genkey
openssl req -new -sha256 -key $KEY_FILE -out $CSR_FILE \
-subj "/C=US/ST=Pennsylvania/CN=localhost" \
-config $CONFIG_FILE
openssl x509 -req -sha256 -days 1825 -in $CSR_FILE -signkey $KEY_FILE -out $CERT_FILE
openssl pkcs12 -export -nodes \
-name "IIS Express Development Certificate" \
-in $CERT_FILE \
-inkey $KEY_FILE \
-out $OUT_FILE
# This requires elevated privileges
$appid = [guid]::NewGuid().ToString("B")
$thumbprint = Get-ChildItem Cert:\LocalMachine\My |
Where-Object { $_.FriendlyName -eq 'IIS Express Development Certificate' } |
Select-Object -ExpandProperty Thumbprint
for ($i=44300; $i -le 44399; $i++)
{
$delete_cmd = "netsh http delete sslcert ipport=0.0.0.0:$i"
$bind_cmd = "netsh http add sslcert ipport='0.0.0.0:$i' certhash='$thumbprint' appid='$appid'"
Write-Host ""
Write-Host $delete_cmd
Invoke-Expression -Command $delete_cmd
Write-Host $bind_cmd
Invoke-Expression -Command $bind_cmd
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment