Skip to content
Open
Show file tree
Hide file tree
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
32 changes: 32 additions & 0 deletions setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,38 @@ function Set-GitIdentity {
}
}
}

# --- Part 3: Route GitHub SSH over port 443 ---
$routeGh = Read-Host "Route GitHub SSH over port 443? Fixes intermittent port-22 timeouts on restrictive networks. (Y/n)"
if ($routeGh -notmatch "^[Nn]$") {
Set-GitHubSSHOverHttps
}
}

function Set-GitHubSSHOverHttps {
$sshDir = Join-Path $HOME ".ssh"
$configPath = Join-Path $sshDir "config"

if (-not (Test-Path $sshDir)) {
New-Item -ItemType Directory -Path $sshDir -Force | Out-Null
}

if ((Test-Path $configPath) -and (Select-String -Path $configPath -Pattern '^\s*Host\s+github\.com\b' -Quiet)) {
Log-Info "A 'Host github.com' block already exists in ~/.ssh/config — leaving it untouched."
return
}

$block = @"

# Route GitHub SSH over port 443 (port 22 is blocked/reset on some networks).
# ssh.github.com:443 is GitHub's official SSH-over-HTTPS endpoint.
Host github.com
Hostname ssh.github.com
Port 443
User git
"@
Add-Content -Path $configPath -Value $block
Log-Success "Configured GitHub SSH to use port 443 in ~/.ssh/config"
}

function Set-SSHKeys {
Expand Down
31 changes: 31 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,37 @@ configure_identity() {
;;
esac
fi

# --- Part 3: Route GitHub SSH over port 443 ---
echo -n "Route GitHub SSH over port 443? Fixes intermittent port-22 timeouts on restrictive networks. (Y/n): "
read route_gh
if [[ ! "$route_gh" =~ ^[Nn]$ ]]; then
configure_github_ssh_over_https
fi
}

configure_github_ssh_over_https() {
local ssh_dir="$HOME/.ssh"
local config_path="$ssh_dir/config"

mkdir -p "$ssh_dir"

if [ -f "$config_path" ] && grep -qE '^[[:space:]]*Host[[:space:]]+github\.com\b' "$config_path"; then
log_info "A 'Host github.com' block already exists in ~/.ssh/config — leaving it untouched."
return
fi

cat >> "$config_path" <<'EOF'

# Route GitHub SSH over port 443 (port 22 is blocked/reset on some networks).
# ssh.github.com:443 is GitHub's official SSH-over-HTTPS endpoint.
Host github.com
Hostname ssh.github.com
Port 443
User git
EOF
chmod 600 "$config_path" 2>/dev/null || true
log_success "Configured GitHub SSH to use port 443 in ~/.ssh/config"
}

setup_ssh() {
Expand Down
20 changes: 20 additions & 0 deletions tests/Test-GitHubSSHOverHttps.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Write-Host "Running content verification for GitHub SSH-over-443 in setup.ps1..."

$content = Get-Content "./setup.ps1" -Raw

$checks = @(
"function Set-GitHubSSHOverHttps",
"Route GitHub SSH over port 443?",
"Hostname ssh.github.com",
"Port 443",
"Host github.com"
)

foreach ($check in $checks) {
if ($content -notmatch [regex]::Escape($check)) {
Write-Error "FAIL: Expected string '$check' not found in setup.ps1"
exit 1
}
}

Write-Host "PASS: setup.ps1 contains GitHub SSH-over-443 logic"
26 changes: 26 additions & 0 deletions tests/test_github_ssh_over_https.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
# Content verification for GitHub SSH-over-443 in setup.sh

echo "Running content verification for GitHub SSH-over-443 in setup.sh..."

if [ ! -f "./setup.sh" ]; then
echo "FAIL: setup.sh not found"
exit 1
fi

checks=(
"configure_github_ssh_over_https()"
"Route GitHub SSH over port 443?"
"Hostname ssh.github.com"
"Port 443"
"Host github.com"
)

for check in "${checks[@]}"; do
if ! grep -qF "$check" ./setup.sh; then
echo "FAIL: Expected string '$check' not found in setup.sh"
exit 1
fi
done

echo "PASS: setup.sh contains GitHub SSH-over-443 logic"