Skip to content

Instantly share code, notes, and snippets.

@DamianEdwards
Last active March 27, 2020 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DamianEdwards/f1152eda6538989065f2287498e062a9 to your computer and use it in GitHub Desktop.
Save DamianEdwards/f1152eda6538989065f2287498e062a9 to your computer and use it in GitHub Desktop.
Self-signed certificate experiments
# Generate root cert
$cert = New-SelfSignedCertificate -Type Custom -KeySpec Signature `
-Subject "CN=AspNetCoreCertAuthRoot" -KeyExportPolicy Exportable `
-HashAlgorithm sha256 -KeyLength 2048 `
-CertStoreLocation "Cert:\CurrentUser\My" -KeyUsageProperty Sign -KeyUsage CertSign
# Make sure to trust this root cert
# Generate child cert with Client Authentication OID
New-SelfSignedCertificate -Type Custom -DnsName P2SChildCert -KeySpec Signature `
-Subject "CN=AspNetCoreCertAuthClient-CertAuthTest-Client" -KeyExportPolicy Exportable `
-HashAlgorithm sha256 -KeyLength 2048 `
-CertStoreLocation "Cert:\CurrentUser\My" `
-Signer $cert -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.2")
# Generate root cert
$rootCert = New-SelfSignedCertificate -Type Custom -KeySpec Signature `
-Subject "CN=AspNetCoreCertAuthRoot" -KeyExportPolicy Exportable `
-HashAlgorithm sha256 -KeyLength 2048 `
-CertStoreLocation "Cert:\CurrentUser\My" -KeyUsageProperty Sign -KeyUsage CertSign
New-SelfSignedCertificate -Type Custom -Subject "CN=ClientAuthTest-Client" `
-TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.2","2.5.29.17={text}upn=ClientAuthTest-Client") `
-KeyUsage DigitalSignature -KeyAlgorithm RSA -KeyLength 2048 `
-CertStoreLocation "Cert:\CurrentUser\My" `
-Signer $rootCert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment