Repository navigation
Closed
Description
When ext-ssh2 is loaded, SshClient connects with ssh2_connect() and authenticates without checking the server's host key (
pitmaster/src/Protocol/SshClient.php
Lines 152 to 186 in 5beb97d
| { | |
| $connection = @ssh2_connect($host, $port); | |
| if ($connection === false) { | |
| throw new ProtocolException("SSH connection failed: {$host}:{$port}"); | |
| } | |
| // Try key-based auth from default locations | |
| $homeDir = getenv('HOME') ?: (getenv('USERPROFILE') ?: '/root'); | |
| $keyFile = $homeDir . '/.ssh/id_rsa'; | |
| $pubKeyFile = $homeDir . '/.ssh/id_rsa.pub'; | |
| if (is_file($keyFile) && is_file($pubKeyFile)) { | |
| if (!@ssh2_auth_pubkey_file($connection, $user, $pubKeyFile, $keyFile)) { | |
| // Try ed25519 | |
| $keyFile = $homeDir . '/.ssh/id_ed25519'; | |
| $pubKeyFile = $homeDir . '/.ssh/id_ed25519.pub'; | |
| if (is_file($keyFile) && is_file($pubKeyFile)) { | |
| if (!@ssh2_auth_pubkey_file($connection, $user, $pubKeyFile, $keyFile)) { | |
| throw new ProtocolException("SSH authentication failed for {$user}@{$host}"); | |
| } | |
| } else { | |
| // Try ssh-agent | |
| if (!@ssh2_auth_agent($connection, $user)) { | |
| throw new ProtocolException("SSH authentication failed for {$user}@{$host}"); | |
| } | |
| } | |
| } | |
| } else { | |
| if (!@ssh2_auth_agent($connection, $user)) { | |
| throw new ProtocolException("SSH authentication failed for {$user}@{$host}"); | |
| } | |
| } | |
ssh2_fingerprint() is never called and no known_hosts file is consulted. The fallback path through the system ssh binary does verify host keys (and honours PITMASTER_SSH_KNOWN_HOSTS and PITMASTER_SSH_STRICT_HOST_KEY_CHECKING), but the ssh2 path is always preferred when the extension is present.
The ssh2 path also only tries ~/.ssh/id_rsa, then ~/.ssh/id_ed25519 (only when id_rsa exists and fails), then the agent, and ignores PITMASTER_SSH_IDENTITY_FILE.
Expected
Verify the host key against known_hosts (or a configured fingerprint) before authenticating, and apply the same PITMASTER_SSH_* settings on both paths.
Metadata
Metadata
Assignees
Labels
No labels
Activity