fix(ssh): store host key buffer in addHostKey so verifyHostKey matches#1361
fix(ssh): store host key buffer in addHostKey so verifyHostKey matches#1361naaa760 wants to merge 1 commit intogeneralaction:mainfrom
Conversation
|
@naaa760 is attempting to deploy a commit to the General Action Team on Vercel. A member of the Team first needs to authorize it. |
Greptile SummaryThis PR fixes a critical TOFU (Trust On First Use) regression in The fix correctly changes Key observations:
Confidence Score: 5/5
Sequence DiagramsequenceDiagram
participant SSH as SSH Connection
participant SVC as SshHostKeyService
participant FS as known_hosts file
Note over SSH,FS: First connection (TOFU - Trust On First Use)
SSH->>SVC: addHostKey(host, port, keyType, rawKeyBuffer)
SVC->>SVC: keyBase64 = rawKeyBuffer.toString('base64')
SVC->>SVC: knownHosts.set(hostPort, { algorithm, keyBase64 })
SVC->>FS: writeFile → "host ssh-ed25519 <base64key>"
Note over SSH,FS: Subsequent connection (verification)
SSH->>SVC: verifyHostKey(host, port, keyType, fingerprint)
SVC->>FS: (already initialized, reads from memory)
SVC->>SVC: stored.keyBase64 → Buffer.from(keyBase64, 'base64')
SVC->>SVC: knownFingerprint = SHA256(rawKeyBuffer)
SVC->>SVC: knownFingerprint === fingerprint?
SVC-->>SSH: 'known' ✓ (previously: always 'changed' ✗)
Note over SSH,FS: OLD BUGGY FLOW (before fix)
SSH->>SVC: addHostKey(host, port, keyType, "SHA256:abc123")
SVC->>SVC: keyBase64 = "SHA256:abc123" (fingerprint string, not key!)
SVC->>FS: writeFile → "host ssh-ed25519 SHA256:abc123"
SSH->>SVC: verifyHostKey(host, port, keyType, "SHA256:abc123")
SVC->>SVC: Buffer.from("SHA256:abc123", 'base64') → garbled bytes
SVC->>SVC: SHA256(garbledBytes) ≠ "SHA256:abc123"
SVC-->>SSH: 'changed' ✗ (TOFU broken)
Last reviewed commit: e8a82ef |
fix: #1360
description
Changes
Testing