mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-16 20:11:08 +00:00
* feat(ssh): restore FIDO2 security key support (#2308) Consolidate the restored feature and its review fixes before rebasing onto current main. Original PR head: 5d0a0c6c9a550364d3ec5c2331395cedfc9ea7ae. * fix(ssh): verify and repair FIDO authentication with simulated hardware Preserve complete OpenSSH SK signature payloads, classify combined PIN/presence prompts correctly, expand IdentityFile tokens, retain certificate selectors, and route shared-agent signing prompts to their originating window. Dismiss prompts when notification helpers exit. Add a software SK provider and opt-in real OpenSSH integration coverage for both algorithms, certificates, SFTP, forwarding, and concurrent windows. * refactor(ui): refine security key forms and authentication motion Use shared Select and Switch controls, concise localized copy and compact token-based dialogs. Add scoped enter/exit, field transition and presence animations with reduced-motion support. Preserve raw prompt details and visible PIN errors. * fix(ssh): align security key prompts with hardware presence and verify Docker logins * fix(ui): keep security key dialog above its remounted overlay * fix: address Codex review on PR #2823 * feat(ssh): guide security key recovery and explicit authentication fallback * test(ssh): exercise security key authentication on native Windows * test(ssh): verify Windows fixture signatures and explicit fallback * test(ssh): configure Windows OpenSSH toolchain and document coverage --------- Co-authored-by: netcatty-bot <308658023+netcatty-bot@users.noreply.github.com>
200 lines
6.7 KiB
JavaScript
200 lines
6.7 KiB
JavaScript
"use strict";
|
|
|
|
const test = require("node:test");
|
|
const assert = require("node:assert/strict");
|
|
|
|
const {
|
|
resolveUnlockedEncryptedKeysForAuth,
|
|
applyAgentForwarding,
|
|
shouldOfferAgentForLogin,
|
|
shouldPrepareSystemAgentForLogin,
|
|
shouldPromoteCachedAuthMethod,
|
|
prepareAgentForwardingOptions,
|
|
} = require("./startSession.cjs");
|
|
|
|
test("forwarding agent selection is resolved before connection reuse", async () => {
|
|
const calls = [];
|
|
const prepared = await prepareAgentForwardingOptions(
|
|
{ agentForwarding: true, identityAgent: "none" },
|
|
async (identityAgent) => {
|
|
calls.push(identityAgent);
|
|
return "/Users/alice/.bitwarden-ssh-agent.sock";
|
|
},
|
|
);
|
|
|
|
assert.deepEqual(calls, ["none"]);
|
|
assert.equal(prepared._resolvedForwardingAgentSocket, "/Users/alice/.bitwarden-ssh-agent.sock");
|
|
assert.equal(prepared.forwardingAgentSocket, "/Users/alice/.bitwarden-ssh-agent.sock");
|
|
});
|
|
|
|
test("pre-resolved forwarding agent selection is reused during SSH setup", async () => {
|
|
const connectOptions = {};
|
|
await applyAgentForwarding(
|
|
{
|
|
agentForwarding: true,
|
|
_resolvedForwardingAgentSocket: "/Users/alice/.bitwarden-ssh-agent.sock",
|
|
},
|
|
connectOptions,
|
|
async () => {
|
|
throw new Error("forwarding socket should not be resolved twice");
|
|
},
|
|
);
|
|
|
|
assert.equal(connectOptions.agent, "/Users/alice/.bitwarden-ssh-agent.sock");
|
|
assert.equal(connectOptions.agentForward, true);
|
|
});
|
|
|
|
test("agent forwarding resolves the forwarding socket independently from login auth", async () => {
|
|
const connectOptions = { password: "login-password" };
|
|
const resolved = [];
|
|
|
|
await applyAgentForwarding(
|
|
{ agentForwarding: true, useSshAgent: false },
|
|
connectOptions,
|
|
async (identityAgent) => {
|
|
resolved.push(identityAgent);
|
|
return "/Users/alice/.bitwarden-ssh-agent.sock";
|
|
},
|
|
);
|
|
|
|
assert.deepEqual(resolved, [undefined]);
|
|
assert.equal(connectOptions.agent, "/Users/alice/.bitwarden-ssh-agent.sock");
|
|
assert.equal(connectOptions.agentForward, true);
|
|
});
|
|
|
|
test("agent forwarding replaces an automatically discovered empty login agent", async () => {
|
|
const connectOptions = { agent: "/private/tmp/com.apple.launchd.test/Listeners" };
|
|
|
|
await applyAgentForwarding(
|
|
{ agentForwarding: true },
|
|
connectOptions,
|
|
async () => "/Users/alice/.bitwarden-ssh-agent.sock",
|
|
{ replaceExistingAgent: true },
|
|
);
|
|
|
|
assert.equal(connectOptions.agent, "/Users/alice/.bitwarden-ssh-agent.sock");
|
|
assert.equal(connectOptions.agentForward, true);
|
|
});
|
|
|
|
test("agent forwarding configures ssh2 separately from an explicitly prepared login agent", async () => {
|
|
const explicitAgent = { kind: "selected-agent" };
|
|
const connectOptions = { agent: explicitAgent };
|
|
let resolutions = 0;
|
|
|
|
await applyAgentForwarding(
|
|
{ agentForwarding: true, identityAgent: "/tmp/selected-agent.sock" },
|
|
connectOptions,
|
|
async () => {
|
|
resolutions += 1;
|
|
return "/tmp/other-agent.sock";
|
|
},
|
|
);
|
|
|
|
assert.equal(connectOptions.agent, "/tmp/other-agent.sock");
|
|
assert.equal(connectOptions.agentForward, true);
|
|
assert.equal(resolutions, 1);
|
|
});
|
|
|
|
test("agent forwarding does not enable agent login after an explicit opt-out", () => {
|
|
assert.equal(shouldOfferAgentForLogin(
|
|
{ useSshAgent: false, agentForwarding: true },
|
|
{ agent: "/tmp/agent.sock", agentForward: true },
|
|
), false);
|
|
});
|
|
|
|
test("agent login remains available when it is not explicitly disabled", () => {
|
|
assert.equal(shouldOfferAgentForLogin(
|
|
{ agentForwarding: true },
|
|
{ agent: "/tmp/agent.sock", agentForward: true },
|
|
), true);
|
|
});
|
|
|
|
test("direct SSH allows only a restricted selected agent-backed key", () => {
|
|
const selectedAgentKey = {
|
|
authMethod: "key",
|
|
useSshAgent: true,
|
|
identitiesOnly: true,
|
|
agentPublicKeys: ["ssh-ed25519 AAAASELECTED"],
|
|
};
|
|
assert.equal(shouldPrepareSystemAgentForLogin(selectedAgentKey), true);
|
|
assert.equal(shouldOfferAgentForLogin(selectedAgentKey, { agent: {} }), true);
|
|
|
|
const selectedReferencedKey = {
|
|
...selectedAgentKey,
|
|
agentPublicKeys: [],
|
|
identityFilePaths: ["~/.ssh/id_work"],
|
|
};
|
|
assert.equal(shouldPrepareSystemAgentForLogin(selectedReferencedKey), true);
|
|
assert.equal(shouldOfferAgentForLogin(selectedReferencedKey, { agent: {} }), true);
|
|
|
|
assert.equal(shouldPrepareSystemAgentForLogin({
|
|
...selectedAgentKey,
|
|
agentPublicKeys: [],
|
|
identityFilePaths: [],
|
|
}), false);
|
|
assert.equal(shouldOfferAgentForLogin({
|
|
...selectedAgentKey,
|
|
identitiesOnly: false,
|
|
}, { agent: {} }), false);
|
|
});
|
|
|
|
test("FIDO agent login is offered after path/inline sk detection even when renderer opted out of ssh-agent", () => {
|
|
const pathOnlySk = {
|
|
authMethod: "key",
|
|
useSshAgent: false,
|
|
useFidoAgent: true,
|
|
identitiesOnly: true,
|
|
identityFilePaths: ["~/.ssh/id_ed25519_sk"],
|
|
};
|
|
assert.equal(shouldOfferAgentForLogin(pathOnlySk, { agent: {} }), true);
|
|
|
|
const inlineSk = {
|
|
authMethod: "key",
|
|
useSshAgent: false,
|
|
useFidoAgent: true,
|
|
};
|
|
assert.equal(shouldOfferAgentForLogin(inlineSk, { agent: {} }), true);
|
|
|
|
assert.equal(shouldOfferAgentForLogin({
|
|
authMethod: "password",
|
|
useSshAgent: false,
|
|
useFidoAgent: true,
|
|
}, { agent: {} }), false);
|
|
});
|
|
|
|
test("strict agent selection excludes unlocked default keys", () => {
|
|
const unlocked = [{ keyName: "id_other", privateKey: "PRIVATE KEY" }];
|
|
assert.deepEqual(resolveUnlockedEncryptedKeysForAuth({
|
|
_unlockedEncryptedKeys: unlocked,
|
|
}, true), []);
|
|
assert.equal(resolveUnlockedEncryptedKeysForAuth({
|
|
_unlockedEncryptedKeys: unlocked,
|
|
}, false), unlocked);
|
|
});
|
|
|
|
test("explicit auth modes exclude unlocked unrelated default keys", () => {
|
|
const unlocked = [{ keyName: "id_other", privateKey: "PRIVATE KEY" }];
|
|
for (const authMethod of ["password", "key", "certificate"]) {
|
|
assert.deepEqual(resolveUnlockedEncryptedKeysForAuth({
|
|
authMethod,
|
|
_unlockedEncryptedKeys: unlocked,
|
|
}, false), []);
|
|
}
|
|
assert.equal(resolveUnlockedEncryptedKeysForAuth({
|
|
authMethod: "auto",
|
|
_unlockedEncryptedKeys: unlocked,
|
|
}, false), unlocked);
|
|
});
|
|
|
|
test("cached methods cannot override explicit authentication ordering", () => {
|
|
for (const authMethod of ["password", "key", "certificate"]) {
|
|
assert.equal(shouldPromoteCachedAuthMethod(authMethod, "password"), false);
|
|
assert.equal(shouldPromoteCachedAuthMethod(authMethod, "keyboard-interactive"), false);
|
|
}
|
|
assert.equal(shouldPromoteCachedAuthMethod("auto", "password"), false);
|
|
assert.equal(shouldPromoteCachedAuthMethod("auto", "keyboard-interactive"), false);
|
|
assert.equal(shouldPromoteCachedAuthMethod("auto", "agent"), true);
|
|
assert.equal(shouldPromoteCachedAuthMethod("auto", "publickey-default-id_work"), true);
|
|
assert.equal(shouldPromoteCachedAuthMethod(undefined, "password"), true);
|
|
});
|