Skip to content

Commit af7f9c2

Browse files
committed
2 parents 28ddfcf + f215f40 commit af7f9c2

3 files changed

+70
-4
lines changed

GetFileHash.ps1

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Get-FileHash has been introduced only in PowerShell 4.0
2+
# Here's a compatible implementation for previous versions (SHA1 only for now)
3+
function Get-FileHash {
4+
[CmdletBinding()]
5+
param
6+
(
7+
[parameter(Mandatory=$true)]
8+
[string]$Path,
9+
10+
[string]$Algorithm = "SHA1"
11+
)
12+
process
13+
{
14+
if ($Algorithm -ne "SHA1") {
15+
throw "Unsupported algorithm: $Algorithm"
16+
}
17+
18+
$fullPath = Resolve-Path $Path
19+
$f = [System.IO.File]::OpenRead($fullPath)
20+
$sham = $null
21+
try {
22+
$sham = new-object System.Security.Cryptography.SHA1Managed
23+
$hash = $sham.ComputeHash($f)
24+
25+
$hashSB = new-object System.Text.StringBuilder -ArgumentList ($hash.Length * 2)
26+
foreach ($b in $hash) {
27+
$sb = $hashSB.AppendFormat("{0:x2}", $b)
28+
}
29+
30+
return [pscustomobject]@{Algorithm="SHA1"; Path=$fullPath; Hash=$hashSB.ToString()}
31+
}
32+
finally {
33+
$f.Close()
34+
if($sham) { $sham.Clear() }
35+
}
36+
}
37+
}

SetupWinRMAccessSelfSigned.ps1

+29-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
11
$ErrorActionPreference = "Stop"
22

3+
Import-Module BitsTransfer
4+
35
$opensslPath = "$ENV:HOMEDRIVE\OpenSSL-Win32"
46

7+
if($PSVersionTable.PSVersion.Major -lt 4) {
8+
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
9+
. "$scriptPath\GetFileHash.ps1"
10+
}
11+
512
function VerifyHash($filename, $expectedHash) {
613
$hash = (Get-FileHash -Algorithm SHA1 $filename).Hash
714
if ($hash -ne $expectedHash) {
8-
throw "SHA1 hash not valid for file: $filename"
15+
throw "SHA1 hash not valid for file: $filename. Expected: $expectedHash Current: $hash"
916
}
1017
}
1118

19+
function InstallVCRedist2008() {
20+
$filename = "vcredist_x86_2008.exe"
21+
$url = "http://download.microsoft.com/download/1/1/1/1116b75a-9ec3-481a-a3c8-1777b5381140/vcredist_x86.exe"
22+
Start-BitsTransfer -Source $url -Destination $filename
23+
24+
VerifyHash $filename "56719288ab6514c07ac2088119d8a87056eeb94a"
25+
26+
Start-Process -Wait -FilePath $filename -ArgumentList "/q"
27+
del $filename
28+
}
29+
1230
function InstallOpenSSL() {
1331
if (!(Test-Path $opensslPath)) {
1432
$filename = "Win32OpenSSL_Light-1_0_1i.exe"
15-
Invoke-WebRequest -Uri "http://slproweb.com/download/$filename" -OutFile $filename
33+
Start-BitsTransfer -Source "http://slproweb.com/download/$filename" -Destination $filename
1634

17-
VerifyHash $filename "303A6010192161C3BA103978DD4D6932CA9340DC"
35+
VerifyHash $filename "439BA19F18803432E39F0056209B010A63B96644"
1836

1937
Start-Process -Wait -FilePath $filename -ArgumentList "/silent /verysilent /sp- /suppressmsgboxes"
2038
del $filename
@@ -70,7 +88,7 @@ function ImportCertificate($certFilePfx, $pfxPassword) {
7088
}
7189

7290
function RemoveExistingWinRMHttpsListener() {
73-
$httpsListener = Get-Item -Path wsman:\localhost\listener\* | where {$_.Keys.Contains("Transport=HTTPS")}
91+
$httpsListener = Get-Item -Path wsman:\localhost\listener\* | where {$_.Keys | where { $_ -eq "Transport=HTTPS"} }
7492
if ($httpsListener) {
7593
Remove-Item -Recurse -Force -Path ("wsman:\localhost\listener\" + $httpsListener.Name)
7694
}
@@ -84,6 +102,11 @@ function CreateWinRMHttpsFirewallRule() {
84102
$certFilePfx = "server_cert.p12"
85103
$pfxPassword = "Passw0rd"
86104

105+
$osVer = [System.Environment]::OSVersion.Version
106+
if ($osVer.Major -eq 6 -and $osVer.Minor -le 1) {
107+
InstallVCRedist2008
108+
}
109+
87110
InstallOpenSSL
88111

89112
GenerateSelfSignedCertificate $certFilePfx $pfxPassword
@@ -97,6 +120,8 @@ RemoveExistingWinRMHttpsListener
97120
New-Item -Path wsman:\localhost\listener -transport https -address * -CertificateThumbPrint $certThumbprint -Force
98121

99122
Set-Item wsman:\localhost\service\Auth\Basic -Value $true
123+
# Increase the timeout for long running scripts
124+
Set-Item wsman:\localhost\MaxTimeoutms -Value 1800000
100125

101126
CreateWinRMHttpsFirewallRule
102127

github_apply_pull_req.cmd

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set n=%1%
2+
3+
git fetch origin pull/%n%/head
4+
git checkout -b "pull%n%" FETCH_HEAD

0 commit comments

Comments
 (0)