Skip to content

Instantly share code, notes, and snippets.

@dataf3l
Created March 31, 2017 20:42
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 dataf3l/24330e1ca5cac5084118711af94aa236 to your computer and use it in GitHub Desktop.
Save dataf3l/24330e1ca5cac5084118711af94aa236 to your computer and use it in GitHub Desktop.
# Create new ACMEIdentifier for the domain
if ((Test-Path ($WorkDir+"\\1-Identifiers\\"+$Domain)) -eq $FALSE) {
New-Item -ItemType directory -Path ($WorkDir+"\\1-Identifiers\\"+$Domain)
}
New-ACMEIdentifier -Dns $Domain -Alias $Alias > ($WorkDir+"\\1-Identifiers\\"+$Domain+"\\"+$TimeStamp+".txt")
Start-Sleep 5
# Request new challenge for the domain
if ((Test-Path ($WorkDir+"\\2-Challenges\\"+$Domain)) -eq $FALSE) {
New-Item -ItemType directory -Path ($WorkDir+"\\2-Challenges\\"+$Domain)
}
$result = Complete-ACMEChallenge $Alias -ChallengeType http-01 -Handler manual
Start-Sleep 5
# Create HTTP response file for challenge
$Challenges = [Collections.Generic.List[Object]]($result.Challenges.ToArray())
$ChallengeObj=($Challenges[($Challenges.FindIndex( {$args[0].Type -eq "http-01"}))])
$ChallengeObj.Challenge.Answer.KeyAuthorization |Out-File -Encoding UTF8 ($WorkDir+"\\2-Challenges\\"+$Domain+"\\"+$ChallengeObj.Token)
# Upload HTTP response file to webserver
$ftp = [System.Net.FtpWebRequest]::Create($FTPServer+"/.well-known/acme-challenge/"+$ChallengeObj.Token)
$ftp = [System.Net.FtpWebRequest]$ftp
$ftp.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
$ftp.Credentials = new-object System.Net.NetworkCredential($FTPUser,$FTPPassword)
$ftp.UseBinary = $true
$ftp.UsePassive = $true
$content = [System.IO.File]::ReadAllBytes($WorkDir+"\\2-Challenges\\"+$Domain+"\\"+$ChallengeObj.Token)
$ftp.ContentLength = $content.Length
$rs = $ftp.GetRequestStream()
$rs.Write($content, 0, $content.Length)
$rs.Close()
$rs.Dispose()
Start-Sleep 5
# Submit the challenge for approval
Submit-ACMEChallenge $Alias -ChallengeType http-01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment