@ozyman42/ozy-cli 0.4.6-linux-x64.0 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/ozy +191 -0
- package/bin/ozy-signing-agent +191 -0
- package/bin/ozy-ssh-keygen +191 -0
- package/bin/ozy-virtual-security-key +191 -0
- package/dist/commands/git/hosts.js +18 -0
- package/dist/commands/git/hosts.js.map +1 -0
- package/dist/commands/git/index.js +8 -0
- package/dist/commands/git/index.js.map +1 -0
- package/dist/commands/git/setup.js +145 -0
- package/dist/commands/git/setup.js.map +1 -0
- package/dist/commands/index.js +13 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/npm/index.js +7 -0
- package/dist/commands/npm/index.js.map +1 -0
- package/dist/commands/npm/setup/git-remote.js +66 -0
- package/dist/commands/npm/setup/git-remote.js.map +1 -0
- package/dist/commands/npm/setup/index.js +168 -0
- package/dist/commands/npm/setup/index.js.map +1 -0
- package/dist/commands/npm/setup/npm-auth.js +62 -0
- package/dist/commands/npm/setup/npm-auth.js.map +1 -0
- package/dist/commands/npm/setup/package-json-validate.js +47 -0
- package/dist/commands/npm/setup/package-json-validate.js.map +1 -0
- package/dist/commands/npm/setup/package-registry.js +20 -0
- package/dist/commands/npm/setup/package-registry.js.map +1 -0
- package/dist/commands/npm/setup/setup.test.js +95 -0
- package/dist/commands/npm/setup/setup.test.js.map +1 -0
- package/dist/commands/npm/setup/trusted-publishing.js +84 -0
- package/dist/commands/npm/setup/trusted-publishing.js.map +1 -0
- package/dist/commands/npm/setup/workflow.js +19 -0
- package/dist/commands/npm/setup/workflow.js.map +1 -0
- package/dist/commands/ssh/get-sk-credential.js +104 -0
- package/dist/commands/ssh/get-sk-credential.js.map +1 -0
- package/dist/commands/ssh/index.js +7 -0
- package/dist/commands/ssh/index.js.map +1 -0
- package/dist/commands/upgrade.js +81 -0
- package/dist/commands/upgrade.js.map +1 -0
- package/dist/common/command.js +15 -0
- package/dist/common/command.js.map +1 -0
- package/dist/common/constants.js +25 -0
- package/dist/common/constants.js.map +1 -0
- package/dist/common/effective-modules-extensions.js +13 -0
- package/dist/common/effective-modules-extensions.js.map +1 -0
- package/dist/common/log.js +4 -0
- package/dist/common/log.js.map +1 -0
- package/dist/common/render-caller-tree.js +20 -0
- package/dist/common/render-caller-tree.js.map +1 -0
- package/dist/entrypoints/ozy-signing-agent.js +48 -0
- package/dist/entrypoints/ozy-signing-agent.js.map +1 -0
- package/dist/entrypoints/ozy-ssh-keygen.js +9 -0
- package/dist/entrypoints/ozy-ssh-keygen.js.map +1 -0
- package/dist/entrypoints/ozy-virtual-security-key.js +18 -0
- package/dist/entrypoints/ozy-virtual-security-key.js.map +1 -0
- package/dist/entrypoints/ozy.js +3 -0
- package/dist/entrypoints/ozy.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/thing.js +4 -0
- package/dist/internal/thing.js.map +1 -0
- package/dist/modules/cli/agent-client/impl.js +109 -0
- package/dist/modules/cli/agent-client/impl.js.map +1 -0
- package/dist/modules/cli/agent-client/interface.js +11 -0
- package/dist/modules/cli/agent-client/interface.js.map +1 -0
- package/dist/modules/cli/git/impl.js +124 -0
- package/dist/modules/cli/git/impl.js.map +1 -0
- package/dist/modules/cli/git/interface.js +3 -0
- package/dist/modules/cli/git/interface.js.map +1 -0
- package/dist/modules/cli/git/submodule/fix.js +257 -0
- package/dist/modules/cli/git/submodule/fix.js.map +1 -0
- package/dist/modules/cli/git/submodule/git-state.js +154 -0
- package/dist/modules/cli/git/submodule/git-state.js.map +1 -0
- package/dist/modules/cli/git/submodule/gitmodules.js +113 -0
- package/dist/modules/cli/git/submodule/gitmodules.js.map +1 -0
- package/dist/modules/cli/git/submodule/printer.js +232 -0
- package/dist/modules/cli/git/submodule/printer.js.map +1 -0
- package/dist/modules/cli/git/submodule/resolve-git-dir.js +16 -0
- package/dist/modules/cli/git/submodule/resolve-git-dir.js.map +1 -0
- package/dist/modules/cli/github/impl.js +137 -0
- package/dist/modules/cli/github/impl.js.map +1 -0
- package/dist/modules/cli/github/interface.js +2 -0
- package/dist/modules/cli/github/interface.js.map +1 -0
- package/dist/modules/cli/index.js +9 -0
- package/dist/modules/cli/index.js.map +1 -0
- package/dist/modules/common/crypto/impl.js +133 -0
- package/dist/modules/common/crypto/impl.js.map +1 -0
- package/dist/modules/common/crypto/interface.js +2 -0
- package/dist/modules/common/crypto/interface.js.map +1 -0
- package/dist/modules/common/index.js +10 -0
- package/dist/modules/common/index.js.map +1 -0
- package/dist/modules/common/kep-map-store/impl.js +42 -0
- package/dist/modules/common/kep-map-store/impl.js.map +1 -0
- package/dist/modules/common/kep-map-store/interface.js +2 -0
- package/dist/modules/common/kep-map-store/interface.js.map +1 -0
- package/dist/modules/common/os-platform/caller-info.js +132 -0
- package/dist/modules/common/os-platform/caller-info.js.map +1 -0
- package/dist/modules/common/os-platform/impl.js +87 -0
- package/dist/modules/common/os-platform/impl.js.map +1 -0
- package/dist/modules/common/os-platform/interface.js +2 -0
- package/dist/modules/common/os-platform/interface.js.map +1 -0
- package/dist/modules/common/os-platform/virtual-hid/index.js +12 -0
- package/dist/modules/common/os-platform/virtual-hid/index.js.map +1 -0
- package/dist/modules/common/os-platform/virtual-hid/linux.js +5 -0
- package/dist/modules/common/os-platform/virtual-hid/linux.js.map +1 -0
- package/dist/modules/common/os-platform/virtual-hid/mac.js +119 -0
- package/dist/modules/common/os-platform/virtual-hid/mac.js.map +1 -0
- package/dist/modules/common/os-platform/virtual-hid/windows.js +5 -0
- package/dist/modules/common/os-platform/virtual-hid/windows.js.map +1 -0
- package/dist/modules/common/ssh-config/impl.js +116 -0
- package/dist/modules/common/ssh-config/impl.js.map +1 -0
- package/dist/modules/common/ssh-config/interface.js +10 -0
- package/dist/modules/common/ssh-config/interface.js.map +1 -0
- package/dist/modules/ssh-agent/index.js +8 -0
- package/dist/modules/ssh-agent/index.js.map +1 -0
- package/dist/modules/ssh-agent/session/impl.js +265 -0
- package/dist/modules/ssh-agent/session/impl.js.map +1 -0
- package/dist/modules/ssh-agent/session/interface-rpc.js +20 -0
- package/dist/modules/ssh-agent/session/interface-rpc.js.map +1 -0
- package/dist/modules/ssh-agent/session/interface.js +32 -0
- package/dist/modules/ssh-agent/session/interface.js.map +1 -0
- package/dist/modules/ssh-agent/session/passkey-prf-page.js +204 -0
- package/dist/modules/ssh-agent/session/passkey-prf-page.js.map +1 -0
- package/dist/modules/ssh-agent/session/prf-flow.js +103 -0
- package/dist/modules/ssh-agent/session/prf-flow.js.map +1 -0
- package/dist/modules/ssh-agent/ssh-agent/impl.js +117 -0
- package/dist/modules/ssh-agent/ssh-agent/impl.js.map +1 -0
- package/dist/modules/ssh-agent/ssh-agent/interface.js +2 -0
- package/dist/modules/ssh-agent/ssh-agent/interface.js.map +1 -0
- package/dist/scripts/build.js +412 -0
- package/dist/scripts/build.js.map +1 -0
- package/dist/scripts/check-npm-version.js +8 -0
- package/dist/scripts/check-npm-version.js.map +1 -0
- package/dist/scripts/kill-existing-agent.js +21 -0
- package/dist/scripts/kill-existing-agent.js.map +1 -0
- package/dist/scripts/publish.js +46 -0
- package/dist/scripts/publish.js.map +1 -0
- package/package.json +52 -11
- package/src/commands/git/hosts.ts +20 -0
- package/src/commands/git/index.ts +9 -0
- package/src/commands/git/setup.ts +182 -0
- package/src/commands/index.ts +15 -0
- package/src/commands/npm/index.ts +8 -0
- package/src/commands/npm/setup/git-remote.ts +78 -0
- package/src/commands/npm/setup/index.ts +189 -0
- package/src/commands/npm/setup/npm-auth.ts +58 -0
- package/src/commands/npm/setup/package-json-validate.ts +68 -0
- package/src/commands/npm/setup/package-registry.ts +24 -0
- package/src/commands/npm/setup/publish-workflow.yml +35 -0
- package/src/commands/npm/setup/setup.test.ts +117 -0
- package/src/commands/npm/setup/trusted-publishing.ts +106 -0
- package/src/commands/npm/setup/workflow.ts +20 -0
- package/src/commands/ssh/get-sk-credential.ts +110 -0
- package/src/commands/ssh/index.ts +8 -0
- package/src/commands/upgrade.ts +90 -0
- package/src/common/command.ts +16 -0
- package/src/common/constants.ts +26 -0
- package/src/common/effective-modules-extensions.ts +24 -0
- package/src/common/log.ts +3 -0
- package/src/common/render-caller-tree.ts +22 -0
- package/src/entrypoints/ozy-signing-agent.ts +48 -0
- package/src/entrypoints/ozy-ssh-keygen.ts +10 -0
- package/src/entrypoints/ozy-virtual-security-key.ts +21 -0
- package/src/entrypoints/ozy.ts +2 -0
- package/src/index.ts +1 -0
- package/src/internal/thing.ts +3 -0
- package/src/modules/cli/agent-client/impl.ts +152 -0
- package/src/modules/cli/agent-client/interface.ts +17 -0
- package/src/modules/cli/git/impl.ts +133 -0
- package/src/modules/cli/git/interface.ts +23 -0
- package/src/modules/cli/git/submodule/fix.ts +298 -0
- package/src/modules/cli/git/submodule/git-state.ts +217 -0
- package/src/modules/cli/git/submodule/gitmodules.ts +126 -0
- package/src/modules/cli/git/submodule/printer.ts +256 -0
- package/src/modules/cli/git/submodule/resolve-git-dir.ts +14 -0
- package/src/modules/cli/github/impl.ts +169 -0
- package/src/modules/cli/github/interface.ts +29 -0
- package/src/modules/cli/index.ts +16 -0
- package/src/modules/common/crypto/impl.ts +173 -0
- package/src/modules/common/crypto/interface.ts +20 -0
- package/src/modules/common/index.ts +19 -0
- package/src/modules/common/kep-map-store/impl.ts +47 -0
- package/src/modules/common/kep-map-store/interface.ts +9 -0
- package/src/modules/common/os-platform/caller-info.ts +152 -0
- package/src/modules/common/os-platform/impl.ts +86 -0
- package/src/modules/common/os-platform/interface.ts +16 -0
- package/src/modules/common/os-platform/virtual-hid/index.ts +12 -0
- package/src/modules/common/os-platform/virtual-hid/linux.ts +7 -0
- package/src/modules/common/os-platform/virtual-hid/mac.ts +150 -0
- package/src/modules/common/os-platform/virtual-hid/windows.ts +7 -0
- package/src/modules/common/ssh-config/impl.ts +130 -0
- package/src/modules/common/ssh-config/interface.ts +33 -0
- package/src/modules/ssh-agent/index.ts +13 -0
- package/src/modules/ssh-agent/session/agent-notes.md +210 -0
- package/src/modules/ssh-agent/session/design.md +2 -0
- package/src/modules/ssh-agent/session/html-refactor.md +23 -0
- package/src/modules/ssh-agent/session/impl.ts +328 -0
- package/src/modules/ssh-agent/session/interface-rpc.ts +24 -0
- package/src/modules/ssh-agent/session/interface.ts +62 -0
- package/src/modules/ssh-agent/session/passkey-prf-page.ts +224 -0
- package/src/modules/ssh-agent/session/prf-flow.ts +152 -0
- package/src/modules/ssh-agent/ssh-agent/impl.ts +136 -0
- package/src/modules/ssh-agent/ssh-agent/interface.ts +9 -0
- package/src/scripts/build.ts +506 -0
- package/src/scripts/check-npm-version.ts +7 -0
- package/src/scripts/command-launcher.js.ejs +168 -0
- package/src/scripts/kill-existing-agent.ts +22 -0
- package/src/scripts/publish.ts +47 -0
- package/src/scripts/windows-bin-shims.md +1104 -0
- package/multi-call-binary +0 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { writeFileSync, existsSync, unlinkSync } from "node:fs";
|
|
3
|
+
import * as net from "node:net";
|
|
4
|
+
import { effunct, implementing, type EffectGen } from "effective-modules";
|
|
5
|
+
import type { IOSPlatform, CallerProcess } from "./interface";
|
|
6
|
+
import { resolveCallerChainUnix, resolveCallerChainWindows } from "./caller-info";
|
|
7
|
+
import { commonModules } from "@/modules/common";
|
|
8
|
+
import { registerVirtualHID } from "./virtual-hid";
|
|
9
|
+
import { log } from "@/common/log";
|
|
10
|
+
|
|
11
|
+
const openCmd = process.platform === 'darwin' ? 'open'
|
|
12
|
+
: process.platform === 'linux' ? 'xdg-open'
|
|
13
|
+
: 'start';
|
|
14
|
+
|
|
15
|
+
const isWindows = process.platform === 'win32';
|
|
16
|
+
|
|
17
|
+
function openBrowserWindow(url: string): Effect.Effect<void, never> {
|
|
18
|
+
return Effect.sync(() => { Bun.spawnSync([openCmd, url]); });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function writeRestrictedFile(path: string, content: string): Effect.Effect<void, string> {
|
|
22
|
+
return Effect.try({
|
|
23
|
+
try: () => {
|
|
24
|
+
if (isWindows) {
|
|
25
|
+
writeFileSync(path, content);
|
|
26
|
+
const result = Bun.spawnSync(['icacls', path, '/inheritance:r', '/grant:r', `${process.env['USERNAME']}:(R,W)`]);
|
|
27
|
+
if (result.exitCode !== 0)
|
|
28
|
+
throw new Error(`icacls failed with exit code ${result.exitCode}`);
|
|
29
|
+
} else {
|
|
30
|
+
writeFileSync(path, content, { mode: 0o600 });
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
catch: (e) => `Failed to write restricted file ${path}: ${e instanceof Error ? e.message : String(e)}`,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function makeConnectionHandler(onData: (data: Buffer, callerChain: CallerProcess[]) => EffectGen<Buffer>, resolveChain: (socket: net.Socket) => CallerProcess[]) {
|
|
38
|
+
return (socket: net.Socket) => {
|
|
39
|
+
let callerChain: CallerProcess[];
|
|
40
|
+
try {
|
|
41
|
+
callerChain = resolveChain(socket);
|
|
42
|
+
} catch (e) {
|
|
43
|
+
log(`[socket-server] ERROR: Failed to get caller info — closing connection. Reason: ${e instanceof Error ? e.message : String(e)}`);
|
|
44
|
+
socket.destroy();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
socket.on('data', async (data) => {
|
|
48
|
+
try {
|
|
49
|
+
socket.write(await Effect.runPromise(effunct(onData)(data, callerChain)));
|
|
50
|
+
} catch (e) {
|
|
51
|
+
log(`[socket-server] ERROR in onData: ${e instanceof Error ? e.message : String(e)}`);
|
|
52
|
+
socket.destroy();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export class OSPlatformImpl extends implementing(commonModules.OSPlatform) implements IOSPlatform {
|
|
59
|
+
openBrowserWindow(url: string) { return openBrowserWindow(url); }
|
|
60
|
+
writeRestrictedFile(path: string, content: string) { return writeRestrictedFile(path, content); }
|
|
61
|
+
*startSocketServer(socketPath: string, onData: (data: Buffer, callerChain: CallerProcess[]) => EffectGen<Buffer>): EffectGen<void, string> {
|
|
62
|
+
return yield* Effect.try({
|
|
63
|
+
try: () => {
|
|
64
|
+
if (existsSync(socketPath)) unlinkSync(socketPath);
|
|
65
|
+
if (isWindows) {
|
|
66
|
+
const pipePath = `\\\\.\\pipe\\${socketPath.replace(/[/\\:]/g, '-')}`;
|
|
67
|
+
const server = net.createServer(makeConnectionHandler(onData, (socket) => {
|
|
68
|
+
const remotePid = (socket as any)._handle?.remotePid as number | undefined;
|
|
69
|
+
if (remotePid == null) throw new Error('socket._handle.remotePid unavailable on this Windows/Bun version');
|
|
70
|
+
return resolveCallerChainWindows(remotePid);
|
|
71
|
+
}));
|
|
72
|
+
server.listen(pipePath);
|
|
73
|
+
} else {
|
|
74
|
+
const server = net.createServer(makeConnectionHandler(onData, (socket) => {
|
|
75
|
+
const fd = (socket as any)._handle?.fd as number | undefined;
|
|
76
|
+
if (fd == null) throw new Error('socket._handle.fd unavailable — cannot resolve peer PID');
|
|
77
|
+
return resolveCallerChainUnix(fd);
|
|
78
|
+
}));
|
|
79
|
+
server.listen(socketPath);
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
catch: (e) => `Failed to start socket server at ${socketPath}: ${e instanceof Error ? e.message : String(e)}`,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
registerVirtualHID(onMessage: (data: Buffer) => Effect.Effect<Buffer>) { return registerVirtualHID(onMessage); }
|
|
86
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { Option } from "effect";
|
|
3
|
+
import type { EffectGen } from "effective-modules";
|
|
4
|
+
|
|
5
|
+
export interface CallerProcess {
|
|
6
|
+
pid: number;
|
|
7
|
+
command: string;
|
|
8
|
+
directory: Option.Option<string>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface IOSPlatform {
|
|
12
|
+
openBrowserWindow(url: string): Effect.Effect<void, never>;
|
|
13
|
+
writeRestrictedFile(path: string, content: string): Effect.Effect<void, string>;
|
|
14
|
+
startSocketServer(socketPath: string, onData: (data: Buffer, callerChain: CallerProcess[]) => EffectGen<Buffer>): EffectGen<void, string>;
|
|
15
|
+
registerVirtualHID(onMessage: (data: Buffer) => Effect.Effect<Buffer>): Effect.Effect<void, string>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { registerVirtualHIDMac } from "./mac";
|
|
3
|
+
import { registerVirtualHIDLinux } from "./linux";
|
|
4
|
+
import { registerVirtualHIDWindows } from "./windows";
|
|
5
|
+
|
|
6
|
+
export function registerVirtualHID(
|
|
7
|
+
onMessage: (data: Buffer) => Effect.Effect<Buffer>
|
|
8
|
+
): Effect.Effect<void, string> {
|
|
9
|
+
if (process.platform === 'darwin') return registerVirtualHIDMac(onMessage);
|
|
10
|
+
if (process.platform === 'win32') return registerVirtualHIDWindows(onMessage);
|
|
11
|
+
return registerVirtualHIDLinux(onMessage);
|
|
12
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { Effect, Option, pipe } from "effect";
|
|
2
|
+
import { JSCallback, dlopen, FFIType, ptr, toArrayBuffer } from "bun:ffi";
|
|
3
|
+
import type { Pointer } from "bun:ffi";
|
|
4
|
+
|
|
5
|
+
// FIDO Alliance usage page (0xF1D0), 64-byte in/out reports, no report IDs
|
|
6
|
+
const FIDO2_HID_DESCRIPTOR = new Uint8Array([
|
|
7
|
+
0x06, 0xD0, 0xF1, // Usage Page (FIDO Alliance 0xF1D0, little-endian)
|
|
8
|
+
0x09, 0x01, // Usage (U2F HID Authenticator Device)
|
|
9
|
+
0xA1, 0x01, // Collection (Application)
|
|
10
|
+
0x09, 0x20, // Usage (Input report data)
|
|
11
|
+
0x15, 0x00, // Logical Minimum (0)
|
|
12
|
+
0x26, 0xFF, 0x00, // Logical Maximum (255)
|
|
13
|
+
0x75, 0x08, // Report Size (8 bits)
|
|
14
|
+
0x95, 0x40, // Report Count (64)
|
|
15
|
+
0x81, 0x02, // Input (Data, Variable, Absolute)
|
|
16
|
+
0x09, 0x21, // Usage (Output report data)
|
|
17
|
+
0x15, 0x00, // Logical Minimum (0)
|
|
18
|
+
0x26, 0xFF, 0x00, // Logical Maximum (255)
|
|
19
|
+
0x75, 0x08, // Report Size (8 bits)
|
|
20
|
+
0x95, 0x40, // Report Count (64)
|
|
21
|
+
0x91, 0x02, // Output (Data, Variable, Absolute)
|
|
22
|
+
0xC0, // End Collection
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
const kIOHIDReportTypeOutput = 1;
|
|
26
|
+
const kIOReturnSuccess = 0;
|
|
27
|
+
const kCFStringEncodingUTF8 = 0x08000100;
|
|
28
|
+
const kCFPropertyListImmutable = 0;
|
|
29
|
+
|
|
30
|
+
// Kept at module scope to prevent GC while the virtual device is running
|
|
31
|
+
let _vhidCallback: JSCallback | null = null;
|
|
32
|
+
_vhidCallback;
|
|
33
|
+
|
|
34
|
+
const fromPtr = (label: string, p: Pointer | null): Effect.Effect<Pointer, string> =>
|
|
35
|
+
pipe(
|
|
36
|
+
Option.fromNullishOr(p),
|
|
37
|
+
Effect.fromOption,
|
|
38
|
+
Effect.mapError(() => `${label} returned NULL`),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
// Build the device properties as an XML plist. CFPropertyListCreateWithData parses this
|
|
42
|
+
// into a fully-initialized CFDictionary (with correct hash/equal callbacks), avoiding
|
|
43
|
+
// the need to pass raw CFDictionaryKeyCallBacks structs via FFI.
|
|
44
|
+
function buildDevicePropertiesPlist(): Uint8Array {
|
|
45
|
+
const descriptorB64 = Buffer.from(FIDO2_HID_DESCRIPTOR).toString('base64');
|
|
46
|
+
const xml = [
|
|
47
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
48
|
+
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
|
|
49
|
+
'<plist version="1.0">',
|
|
50
|
+
'<dict>',
|
|
51
|
+
' <key>ReportDescriptor</key>',
|
|
52
|
+
` <data>${descriptorB64}</data>`,
|
|
53
|
+
' <key>VendorID</key>',
|
|
54
|
+
' <integer>4617</integer>', // 0x1209 - pid.codes open-source VID
|
|
55
|
+
' <key>ProductID</key>',
|
|
56
|
+
' <integer>1</integer>',
|
|
57
|
+
' <key>VersionNumber</key>',
|
|
58
|
+
' <integer>256</integer>', // 0x0100
|
|
59
|
+
' <key>Product</key>',
|
|
60
|
+
' <string>Ozy Virtual FIDO2 Key</string>',
|
|
61
|
+
'</dict>',
|
|
62
|
+
'</plist>',
|
|
63
|
+
].join('\n');
|
|
64
|
+
return new TextEncoder().encode(xml);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function registerVirtualHIDMac(
|
|
68
|
+
onMessage: (data: Buffer) => Effect.Effect<Buffer>
|
|
69
|
+
): Effect.Effect<void, string> {
|
|
70
|
+
return Effect.gen(function* () {
|
|
71
|
+
console.log('[vhid] loading frameworks');
|
|
72
|
+
|
|
73
|
+
const IOKit = yield* Effect.try({
|
|
74
|
+
try: () => dlopen('/System/Library/Frameworks/IOKit.framework/IOKit', {
|
|
75
|
+
IOHIDUserDeviceCreate: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
76
|
+
IOHIDUserDeviceRegisterSetReportCallback: { args: [FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.void },
|
|
77
|
+
IOHIDUserDeviceScheduleWithRunLoop: { args: [FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.void },
|
|
78
|
+
IOHIDUserDeviceHandleReport: { args: [FFIType.ptr, FFIType.ptr, FFIType.i64], returns: FFIType.i32 },
|
|
79
|
+
}),
|
|
80
|
+
catch: (e) => `Failed to load IOKit: ${e}`,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const CF = yield* Effect.try({
|
|
84
|
+
try: () => dlopen('/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation', {
|
|
85
|
+
CFRunLoopGetCurrent: { args: [], returns: FFIType.ptr },
|
|
86
|
+
CFRunLoopRunInMode: { args: [FFIType.ptr, FFIType.f64, FFIType.bool], returns: FFIType.i32 },
|
|
87
|
+
CFStringCreateWithCString: { args: [FFIType.ptr, FFIType.ptr, FFIType.u32], returns: FFIType.ptr },
|
|
88
|
+
CFDataCreate: { args: [FFIType.ptr, FFIType.ptr, FFIType.i64], returns: FFIType.ptr },
|
|
89
|
+
CFPropertyListCreateWithData: { args: [FFIType.ptr, FFIType.ptr, FFIType.u64, FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
90
|
+
CFRelease: { args: [FFIType.ptr], returns: FFIType.void },
|
|
91
|
+
}),
|
|
92
|
+
catch: (e) => `Failed to load CoreFoundation: ${e}`,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
console.log('[vhid] frameworks loaded');
|
|
96
|
+
|
|
97
|
+
const encoder = new TextEncoder();
|
|
98
|
+
|
|
99
|
+
const makeCFString = (s: string): Effect.Effect<Pointer, string> =>
|
|
100
|
+
// TextEncoder gives a Uint8Array with its own ArrayBuffer (byteOffset=0, pool-safe)
|
|
101
|
+
fromPtr(`CFStringCreateWithCString("${s}")`,
|
|
102
|
+
CF.symbols.CFStringCreateWithCString(null, ptr(encoder.encode(s + '\0')), kCFStringEncodingUTF8));
|
|
103
|
+
|
|
104
|
+
const makeCFData = (data: Uint8Array): Effect.Effect<Pointer, string> =>
|
|
105
|
+
fromPtr('CFDataCreate', CF.symbols.CFDataCreate(null, ptr(data), BigInt(data.length)));
|
|
106
|
+
|
|
107
|
+
console.log('[vhid] building device properties plist');
|
|
108
|
+
const plistBytes = buildDevicePropertiesPlist();
|
|
109
|
+
const plistData = yield* makeCFData(plistBytes);
|
|
110
|
+
|
|
111
|
+
const dict = yield* fromPtr('CFPropertyListCreateWithData',
|
|
112
|
+
CF.symbols.CFPropertyListCreateWithData(null, plistData, BigInt(kCFPropertyListImmutable), null, null));
|
|
113
|
+
CF.symbols.CFRelease(plistData);
|
|
114
|
+
console.log('[vhid] device properties dict =', dict);
|
|
115
|
+
|
|
116
|
+
console.log('[vhid] creating IOHIDUserDevice');
|
|
117
|
+
const device = yield* fromPtr('IOHIDUserDeviceCreate', IOKit.symbols.IOHIDUserDeviceCreate(null, dict));
|
|
118
|
+
CF.symbols.CFRelease(dict);
|
|
119
|
+
console.log('[vhid] IOHIDUserDeviceCreate =', device);
|
|
120
|
+
|
|
121
|
+
const callback = yield* Effect.try({
|
|
122
|
+
try: () => new JSCallback(
|
|
123
|
+
(_refcon: number, _result: number, _sender: number, type: number, _reportID: number, report: number, reportLength: number) => {
|
|
124
|
+
if (type !== kIOHIDReportTypeOutput) return kIOReturnSuccess;
|
|
125
|
+
const incoming = Buffer.from(toArrayBuffer(report as unknown as Pointer, 0, reportLength));
|
|
126
|
+
console.log(`[vhid] received ${incoming.length} bytes: ${incoming.toString('hex')}`);
|
|
127
|
+
Effect.runPromise(onMessage(incoming)).then(response => {
|
|
128
|
+
const responseBuf = new Uint8Array(64);
|
|
129
|
+
response.copy(Buffer.from(responseBuf.buffer), 0, 0, Math.min(response.length, 64));
|
|
130
|
+
IOKit.symbols.IOHIDUserDeviceHandleReport(device, ptr(responseBuf), BigInt(responseBuf.length));
|
|
131
|
+
}).catch(() => {});
|
|
132
|
+
return kIOReturnSuccess;
|
|
133
|
+
},
|
|
134
|
+
{ returns: 'i32', args: ['ptr', 'i32', 'ptr', 'i32', 'u32', 'ptr', 'i64'] },
|
|
135
|
+
),
|
|
136
|
+
catch: (e) => `Failed to create JSCallback: ${e}`,
|
|
137
|
+
});
|
|
138
|
+
_vhidCallback = callback;
|
|
139
|
+
|
|
140
|
+
IOKit.symbols.IOHIDUserDeviceRegisterSetReportCallback(device, callback.ptr, null);
|
|
141
|
+
|
|
142
|
+
const runLoop = CF.symbols.CFRunLoopGetCurrent();
|
|
143
|
+
const runLoopMode = yield* makeCFString('kCFRunLoopDefaultMode');
|
|
144
|
+
IOKit.symbols.IOHIDUserDeviceScheduleWithRunLoop(device, runLoop, runLoopMode);
|
|
145
|
+
|
|
146
|
+
console.log('[vhid] virtual FIDO2 device active, pumping run loop');
|
|
147
|
+
// Pump CFRunLoop from Bun's libuv event loop without blocking
|
|
148
|
+
setInterval(() => CF.symbols.CFRunLoopRunInMode(runLoopMode, 0.0, false), 10);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import * as fs from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { writeFileSync } from "node:fs";
|
|
4
|
+
import { Effect, Option, Schema } from "effect";
|
|
5
|
+
import SSHConfig, { LineType } from "ssh-config";
|
|
6
|
+
import expandTilde from "expand-tilde";
|
|
7
|
+
import { implementing, type EffectGen } from "effective-modules";
|
|
8
|
+
import { commonModules } from "@/modules/common";
|
|
9
|
+
|
|
10
|
+
import { SSHConfigSection, type ISSHConfig, type SSHConfigHosts, type WriteHostInput, type WritePubkeyInput } from "./interface";
|
|
11
|
+
|
|
12
|
+
const SSH_CONFIG_PATH = "~/.ssh/config";
|
|
13
|
+
const SSH_DIR = "~/.ssh";
|
|
14
|
+
|
|
15
|
+
export class SSHConfigImpl extends implementing(commonModules.SSHConfig) implements ISSHConfig {
|
|
16
|
+
private *loadSSHConfigRaw(): EffectGen<SSHConfig, string> {
|
|
17
|
+
const configPath = expandTilde(SSH_CONFIG_PATH);
|
|
18
|
+
const exists = yield* Effect.promise(() => fs.exists(configPath));
|
|
19
|
+
const text = exists
|
|
20
|
+
? yield* Effect.tryPromise({
|
|
21
|
+
try: () => fs.readFile(configPath, "utf8"),
|
|
22
|
+
catch: (e) => `Failed to read ssh config at ${configPath}: ${e instanceof Error ? e.message : String(e)}`,
|
|
23
|
+
})
|
|
24
|
+
: "";
|
|
25
|
+
return yield* Effect.try({
|
|
26
|
+
try: () => SSHConfig.parse(text),
|
|
27
|
+
catch: (e) => `ParseError: unable to parse ssh config at ${configPath}\n${e instanceof Error ? e.message : String(e)}`,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
*getSSHConfig(): EffectGen<SSHConfigHosts, string> {
|
|
32
|
+
const configPath = expandTilde(SSH_CONFIG_PATH);
|
|
33
|
+
const exists = yield* Effect.promise(() => fs.exists(configPath));
|
|
34
|
+
if (!exists)
|
|
35
|
+
return yield* Effect.fail(`SSHConfigFileMissingError: No file found at ${configPath}`);
|
|
36
|
+
|
|
37
|
+
const parsed = yield* this.loadSSHConfigRaw();
|
|
38
|
+
|
|
39
|
+
const hosts: SSHConfigHosts = {};
|
|
40
|
+
for (const line of parsed) {
|
|
41
|
+
if (line.type === LineType.COMMENT) continue;
|
|
42
|
+
const { param, value: host } = line;
|
|
43
|
+
if (param !== "Host")
|
|
44
|
+
return yield* Effect.fail(`EntryNotAHostKeyValuePairError: unexpected top-level entry '${param}=${JSON.stringify(host)}'`);
|
|
45
|
+
if (typeof host !== "string")
|
|
46
|
+
return yield* Effect.fail(`EntryNotAHostKeyValuePairError: Host value is not a string: ${JSON.stringify(host)}`);
|
|
47
|
+
if (!("config" in line))
|
|
48
|
+
return yield* Effect.fail(`EntryNotAHostKeyValuePairError: non-section Host entry '${host}'`);
|
|
49
|
+
if (host in hosts)
|
|
50
|
+
return yield* Effect.fail(`DuplicateHostError: duplicate Host '${host}' in ${configPath}`);
|
|
51
|
+
|
|
52
|
+
const kv: Record<string, string> = {};
|
|
53
|
+
for (const inner of line.config) {
|
|
54
|
+
if (inner.type === LineType.COMMENT) continue;
|
|
55
|
+
if (typeof inner.value !== "string")
|
|
56
|
+
return yield* Effect.fail(`MalformedError: Host '${host}' key '${inner.param}' has non-string value`);
|
|
57
|
+
kv[inner.param] = inner.value;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const section = yield* Schema.decodeUnknownEffect(SSHConfigSection)(kv).pipe(
|
|
61
|
+
Effect.mapError(e => `MalformedError: malformed section at Host '${host}': ${String(e)}`)
|
|
62
|
+
);
|
|
63
|
+
hosts[host] = section;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return hosts;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
*writeHost({ section }: WriteHostInput): EffectGen<void, string> {
|
|
70
|
+
const configPath = expandTilde(SSH_CONFIG_PATH);
|
|
71
|
+
const cfg = yield* this.loadSSHConfigRaw();
|
|
72
|
+
const newEntries = Object.entries(section)
|
|
73
|
+
.filter(([, v]) => v !== undefined)
|
|
74
|
+
.map(([k, v]) => ({ type: LineType.DIRECTIVE, before: ' ', param: k, separator: ' ', value: v as string, after: '\n' }));
|
|
75
|
+
|
|
76
|
+
const existingIdx = cfg.findIndex((e: any) => e.param === "Host" && e.value === section.HostName);
|
|
77
|
+
if (existingIdx >= 0) {
|
|
78
|
+
(cfg[existingIdx] as any).config = newEntries;
|
|
79
|
+
} else {
|
|
80
|
+
const record: Record<string, string> = { Host: section.HostName };
|
|
81
|
+
for (const [k, v] of Object.entries(section)) {
|
|
82
|
+
if (v !== undefined) record[k] = v;
|
|
83
|
+
}
|
|
84
|
+
cfg.append(record);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
yield* Effect.try({
|
|
88
|
+
try: () => writeFileSync(configPath, SSHConfig.stringify(cfg), { mode: 0o600 }),
|
|
89
|
+
catch: (e) => `Failed to write ssh config: ${e instanceof Error ? e.message : String(e)}`,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
*listPubkeyFiles(): EffectGen<{name: string, content: string}[], string> {
|
|
94
|
+
const sshDir = expandTilde(SSH_DIR);
|
|
95
|
+
const entries = yield* Effect.tryPromise({
|
|
96
|
+
try: () => fs.readdir(sshDir),
|
|
97
|
+
catch: (e) => `Failed to read ${sshDir}: ${e instanceof Error ? e.message : String(e)}`,
|
|
98
|
+
});
|
|
99
|
+
const pubkeyFiles = entries.filter(f => f.endsWith('.pub'));
|
|
100
|
+
const results: {name: string, content: string}[] = [];
|
|
101
|
+
for (const file of pubkeyFiles) {
|
|
102
|
+
const content = yield* Effect.tryPromise({
|
|
103
|
+
try: () => fs.readFile(join(sshDir, file), 'utf8'),
|
|
104
|
+
catch: (e) => `Failed to read ${file}: ${e instanceof Error ? e.message : String(e)}`,
|
|
105
|
+
});
|
|
106
|
+
results.push({ name: file.slice(0, -'.pub'.length), content: content.trim() });
|
|
107
|
+
}
|
|
108
|
+
return results;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
getPubkeyPath(name: string): string {
|
|
112
|
+
return `${expandTilde(SSH_DIR)}/${name}.pub`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
*writePubkey({ name, comment, pubkey }: WritePubkeyInput): EffectGen<{pubkeyPath: string}, string> {
|
|
116
|
+
const sshDir = expandTilde(SSH_DIR);
|
|
117
|
+
const pubkeyPath = `${sshDir}/${name}.pub`;
|
|
118
|
+
const content = Option.match(comment, {
|
|
119
|
+
onNone: () => pubkey.authorizedKey,
|
|
120
|
+
onSome: (c) => `${pubkey.authorizedKey} ${c}`,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
yield* Effect.try({
|
|
124
|
+
try: () => writeFileSync(pubkeyPath, content + "\n", { mode: 0o600 }),
|
|
125
|
+
catch: (e) => `Failed to write pubkey to ${pubkeyPath}: ${e instanceof Error ? e.message : String(e)}`,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
return {pubkeyPath};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import type { Option } from "effect";
|
|
3
|
+
import type { EffectGen } from "effective-modules";
|
|
4
|
+
import type { SSHPubkey } from "@/modules/common/crypto/impl";
|
|
5
|
+
|
|
6
|
+
export const SSHConfigSection = Schema.Struct({
|
|
7
|
+
HostName: Schema.String,
|
|
8
|
+
User: Schema.String,
|
|
9
|
+
IdentityFile: Schema.optional(Schema.String),
|
|
10
|
+
AddKeysToAgent: Schema.optional(Schema.String),
|
|
11
|
+
IdentitiesOnly: Schema.optional(Schema.String),
|
|
12
|
+
IdentityAgent: Schema.optional(Schema.String),
|
|
13
|
+
});
|
|
14
|
+
export type SSHConfigSection = Schema.Schema.Type<typeof SSHConfigSection>;
|
|
15
|
+
export type SSHConfigHosts = Record<string, SSHConfigSection>;
|
|
16
|
+
|
|
17
|
+
export interface WriteHostInput {
|
|
18
|
+
section: SSHConfigSection;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface WritePubkeyInput {
|
|
22
|
+
name: string;
|
|
23
|
+
comment: Option.Option<string>;
|
|
24
|
+
pubkey: SSHPubkey;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ISSHConfig {
|
|
28
|
+
getSSHConfig(): EffectGen<SSHConfigHosts, string>;
|
|
29
|
+
writeHost(input: WriteHostInput): EffectGen<void, string>;
|
|
30
|
+
writePubkey(input: WritePubkeyInput): EffectGen<{pubkeyPath: string}, string>;
|
|
31
|
+
listPubkeyFiles(): EffectGen<{name: string, content: string}[], string>;
|
|
32
|
+
getPubkeyPath(name: string): string;
|
|
33
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { interfaces } from "effective-modules";
|
|
2
|
+
import type { ISSHAgent } from "./ssh-agent/interface";
|
|
3
|
+
import type { ISession } from "./session/interface";
|
|
4
|
+
|
|
5
|
+
export enum AgentModules {
|
|
6
|
+
SSHAgent = "SSHAgent",
|
|
7
|
+
Session = "Session"
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const agentModules = interfaces<AgentModules, {
|
|
11
|
+
SSHAgent: ISSHAgent;
|
|
12
|
+
Session: ISession;
|
|
13
|
+
}>(AgentModules);
|