Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 49 additions & 2 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
param (
param (
[string]$tag,
[string]$binDir = ".",
[switch]$insecure
Expand Down Expand Up @@ -37,6 +37,42 @@ function Invoke-WebRequestInsecure {
}
}

function Get-FileHashCompat {
param(
[string]$Path,
[string]$Algorithm = "SHA256"
)

# Check if Get-FileHash is available (PowerShell 4.0+)
if (Get-Command Get-FileHash -ErrorAction SilentlyContinue) {
Write-Host "Using built-in Get-FileHash cmdlet for hash verification" -ForegroundColor Green
return Get-FileHash -Path $Path -Algorithm $Algorithm
}

# Fallback for older PowerShell versions
Write-Host "Get-FileHash not available, using .NET fallback for hash calculation" -ForegroundColor Yellow

try {
$hasher = [System.Security.Cryptography.HashAlgorithm]::Create($Algorithm)
$fileStream = [System.IO.File]::OpenRead($Path)
$hashBytes = $hasher.ComputeHash($fileStream)
$fileStream.Close()
$hasher.Dispose()

$hashString = [System.BitConverter]::ToString($hashBytes).Replace("-", "")

# Return object similar to Get-FileHash
return [PSCustomObject]@{
Algorithm = $Algorithm
Hash = $hashString
Path = $Path
}
} catch {
Write-Error "Failed to calculate hash: $_"
throw
}
}

function Get-LatestVersion {
$url = "https://api.github.com/repos/orcasecurity/orca-cli/releases/latest"
$latestRelease = Invoke-WebRequestInsecure -Uri $url
Expand Down Expand Up @@ -98,8 +134,13 @@ function Download-InstallOrcaCLI {
return
}

$hash = Get-FileHash -Path "$($tempDir)\orca-cli_windows.zip" -Algorithm SHA256
# Use compatible hash function
Write-Output "Verifying SHA256 checksum..."
$hash = Get-FileHashCompat -Path "$($tempDir)\orca-cli_windows.zip" -Algorithm SHA256
Write-Output "File hash: $($hash.Hash)"

if ((Get-Content "$($tempDir)\orca-cli_windows_checksums.txt") -match $hash.Hash) {
Write-Output "SHA256 verification successful"
Expand-Archive -Path "$($tempDir)\orca-cli_windows.zip" -DestinationPath $tempDir
$binexe = "orca-cli.exe"
Copy-Item -Path "$($tempDir)\$binexe" -Destination $binDir -Force
Expand All @@ -110,6 +151,12 @@ function Download-InstallOrcaCLI {
Remove-Item -Path $tempDir -Force -Recurse
}

# Check PowerShell version and warn if too old
Write-Output "PowerShell Version: $($PSVersionTable.PSVersion)"
if ($PSVersionTable.PSVersion.Major -lt 3) {
Write-Warning "PowerShell version is quite old. Some features may not work properly."
}

if (-not $tag) {
$tag = Get-LatestVersion
} elseif (-not (Validate-Tag -tag $tag)) {
Expand Down