Skip to content

Commit

Permalink
Handle OpenSSL stderr (Azure#1626)
Browse files Browse the repository at this point in the history
Redirect openssl stderr to stdout in order to avoid red text show in vsts console.
  • Loading branch information
philipktlin authored Aug 27, 2019
1 parent f2c9d6f commit a556262
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tools/CACertificates/ca-certs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ function New-PrivateKey([string]$prefix, [string]$keyPass=$NULL)
}

$keyFile = Get-KeyPathForPrefix($prefix)
$cmd = "openssl $algorithm $passwordCreateCmd -out '$keyFile' $cmdEpilog"
$cmd = "openssl $algorithm $passwordCreateCmd -out '$keyFile' $cmdEpilog 2>&1"
Invoke-External -verbose $cmd
return $keyFile
}
Expand Down Expand Up @@ -395,7 +395,7 @@ function New-IntermediateCertificate
$cmd += "-config '$_opensslRootConfigFile' "
$cmd += "-subj $subject "
$cmd += "-key '$keyFile' "
$cmd += "-out '$csrFile' "
$cmd += "-out '$csrFile' 2>&1"
Invoke-External -verbose $cmd

Write-Host ("Signing the certificate for $prefix with issuer certificate $issuerPrefix")
Expand All @@ -413,19 +413,19 @@ function New-IntermediateCertificate
$cmd += "-days $expirationDays -notext -md sha256 "
$cmd += "-cert '$issuerCertFile' "
$cmd += "$keyPassUseCmd -keyfile '$issuerKeyFile' -keyform PEM "
$cmd += "-in '$csrFile' -out '$certFile' "
$cmd += "-in '$csrFile' -out '$certFile' 2>&1"
Invoke-External -verbose $cmd

Write-Host ("Verifying the certificate for $prefix with issuer certificate $issuerPrefix")
Write-Host ("---------------------------------")
$rootCertFile = Get-CertPathForPrefix($_rootCAPrefix)
$cmd = "openssl verify -CAfile '$rootCertFile' -untrusted '$issuerCertFile' '$certFile'"
$cmd = "openssl verify -CAfile '$rootCertFile' -untrusted '$issuerCertFile' '$certFile' 2>&1"
Invoke-External -verbose $cmd

Write-Host ("Certificate for prefix $prefix generated at:")
Write-Host ("---------------------------------")
Write-Host (" $certFile`r`n")
$cmd = "openssl x509 -noout -text -in '$certFile'"
$cmd = "openssl x509 -noout -text -in '$certFile' 2>&1"
Invoke-External $cmd

New-CertFullChain $certFile $prefix $issuerPrefix $subject
Expand Down Expand Up @@ -456,7 +456,7 @@ function New-IntermediateCertificate
$cmd += "-in '$certFile' -certfile '$issuerChain' "
$cmd += "-inkey '$keyFile' $keyPassUseCmd "
$cmd += "-name $prefix "
$cmd += "-out '$certFilePfx' "
$cmd += "-out '$certFilePfx' 2>&1"
Invoke-External -verbose $cmd
Write-Host ("$prefix PFX Certificate Generated At:")
Write-Host ("----------------------------------------")
Expand Down Expand Up @@ -557,13 +557,13 @@ function New-RootCACertificate()
$passwordUseCmd = "-passin pass:$_privateKeyPassword"
$cmd = "openssl req -new -x509 -config $_opensslRootConfigFile $passwordUseCmd "
$cmd += "-key $keyFile -subj $_rootCertSubject -days $_days_until_expiration "
$cmd += "-sha256 -extensions v3_ca -out $certFile "
$cmd += "-sha256 -extensions v3_ca -out $certFile 2>&1"
Invoke-External -verbose $cmd

Write-Host ("CA Root Certificate Generated At:")
Write-Host ("---------------------------------")
Write-Host (" $certFile`r`n")
$cmd = "openssl x509 -noout -text -in $certFile"
$cmd = "openssl x509 -noout -text -in $certFile 2>&1"
Invoke-External $cmd

# Now use splatting to process this
Expand Down

0 comments on commit a556262

Please sign in to comment.