Skip to content

Instantly share code, notes, and snippets.

@andrewconnell
Created December 20, 2014 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andrewconnell/dab3ba2a204648f0ff10 to your computer and use it in GitHub Desktop.
Save andrewconnell/dab3ba2a204648f0ff10 to your computer and use it in GitHub Desktop.
SharePoint Hosted Apps S2S - Create Self-Signed Certificate for SharePoint App Server
$makecert = "C:\Program Files\Microsoft Office Servers\15.0\Tools\makecert.exe"
$certmgr = "C:\Program Files\Microsoft Office Servers\15.0\Tools\certmgr.exe"
# specify domain name for SSL certificate
$domain = "appserver.wingtip.com"
# create output directory to create SSL certificate file
$outputDirectory = "c:\Certs\"
New-Item $outputDirectory -ItemType Directory -Force -Confirm:$false | Out-Null
# create file name for SSL certificate files
$publicCertificatePath = $outputDirectory + $domain + ".cer"
$privateCertificatePath = $outputDirectory + $domain + ".pfx"
Write-Host
Write-Host "Creating .cer certificate file..."
& $makecert -r -pe -n "CN=$domain" -b 01/01/2012 -e 01/01/2022 -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localMachine -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12 $publicCertificatePath
Write-Host
Write-Host "Registering certificate with IIS..."
& $certmgr /add $publicCertificatePath /s /r localMachine root
# get certificate to obtain thumbprint
$publicCertificate = Get-PfxCertificate -FilePath $publicCertificatePath
$publicCertificateThumbprint = $publicCertificate.Thumbprint
Get-ChildItem cert:\\localmachine\my | Where-Object {$_.Thumbprint -eq $publicCertificateThumbprint} | ForEach-Object {
Write-Host " .. exporting private key for certificate (*.PFK)" -ForegroundColor Gray
$privateCertificateByteArray = $_.Export("PFX", "Password1")
[System.IO.File]::WriteAllBytes($privateCertificatePath, $privateCertificateByteArray)
Write-Host " Certificate exported" -ForegroundColor Gray
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment