Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(pairing): stamp new phone keys nodeterm-mobile-<id>, keep revoking nodeterm-ios-<id>

review9b3084badbe4
diff --git a/src/main/pairing-core.test.ts b/src/main/pairing-core.test.ts
index fa8f8716c..1b1d6b94d 100644
--- a/src/main/pairing-core.test.ts
+++ b/src/main/pairing-core.test.ts
@@ -2,7 +2,10 @@ import { describe, it, expect } from 'vitest'
import { encodePairQr, PAIR_URL_PREFIX } from '@shared/pair-qr'
import {
buildPairingPayload,
+ DEVICE_KEY_COMMENT_PREFIX,
+ LEGACY_DEVICE_KEY_COMMENT_PREFIX,
deviceCommentFor,
+ deviceCommentsFor,
filterAuthorizedKeys,
isValidEd25519PublicKey,
normalizeAuthorizedKeysLine,
@@ -186,34 +189,63 @@ describe('normalizeAuthorizedKeysLine', () => {
})
describe('deviceCommentFor', () => {
- it('builds the attributable comment token', () => {
- expect(deviceCommentFor('abc-123')).toBe('nodeterm-ios-abc-123')
+ it('stamps new keys with the platform-neutral nodeterm-mobile-<id> token', () => {
+ expect(deviceCommentFor('abc-123')).toBe('nodeterm-mobile-abc-123')
+ expect(DEVICE_KEY_COMMENT_PREFIX).toBe('nodeterm-mobile-')
+ })
+})
+
+describe('deviceCommentsFor', () => {
+ it('names the current AND the legacy iOS-era comment, current first', () => {
+ // Every iPhone paired before the Android app existed carries `nodeterm-ios-<id>`; a revoke
+ // that only knew the new prefix would report "removed" and leave that phone's SSH key live.
+ expect(LEGACY_DEVICE_KEY_COMMENT_PREFIX).toBe('nodeterm-ios-')
+ expect(deviceCommentsFor('abc')).toEqual(['nodeterm-mobile-abc', 'nodeterm-ios-abc'])
})
})
describe('rewriteKeyComment', () => {
- it('replaces the phone-sent comment with nodeterm-ios-<deviceId>, keeping type+blob', () => {
+ it('replaces the phone-sent comment with nodeterm-mobile-<deviceId>, keeping type+blob', () => {
expect(rewriteKeyComment('ssh-ed25519 AAAAB3 phone@my-iphone', 'dev1')).toBe(
- 'ssh-ed25519 AAAAB3 nodeterm-ios-dev1'
+ 'ssh-ed25519 AAAAB3 nodeterm-mobile-dev1'
+ )
+ })
+
+ it('rewrites the iOS app’s own `nodeterm-ios` comment too (the phone does not choose it)', () => {
+ expect(rewriteKeyComment('ssh-ed25519 AAAAB3 nodeterm-ios', 'dev3')).toBe(
+ 'ssh-ed25519 AAAAB3 nodeterm-mobile-dev3'
)
})
it('adds a comment when the key had none', () => {
- expect(rewriteKeyComment('ssh-ed25519 AAAAB3', 'dev2')).toBe('ssh-ed25519 AAAAB3 nodeterm-ios-dev2')
+ expect(rewriteKeyComment('ssh-ed25519 AAAAB3', 'dev2')).toBe(
+ 'ssh-ed25519 AAAAB3 nodeterm-mobile-dev2'
+ )
})
it('collapses extra whitespace and multi-word comments', () => {
expect(rewriteKeyComment(' ssh-ed25519 AAAAB3 some long comment\n', 'd')).toBe(
- 'ssh-ed25519 AAAAB3 nodeterm-ios-d'
+ 'ssh-ed25519 AAAAB3 nodeterm-mobile-d'
)
})
})
describe('filterAuthorizedKeys', () => {
- it('removes only lines whose comment is exactly nodeterm-ios-<id>', () => {
+ it('removes only lines whose comment is exactly nodeterm-mobile-<id>', () => {
+ const content = [
+ 'ssh-ed25519 AAAAother laptop@work',
+ 'ssh-ed25519 AAAAtarget nodeterm-mobile-dev1',
+ 'ssh-rsa AAAArsa other-key'
+ ].join('\n')
+ expect(filterAuthorizedKeys(content, 'dev1')).toBe(
+ 'ssh-ed25519 AAAAother laptop@work\nssh-rsa AAAArsa other-key'
+ )
+ })
+
+ it('still removes a LEGACY nodeterm-ios-<id> line (iPhones paired before the rename)', () => {
const content = [
'ssh-ed25519 AAAAother laptop@work',
- 'ssh-ed25519 AAAAtarget nodeterm-ios-dev1',
+ 'ssh-ed25519 AAAAlegacy nodeterm-ios-dev1',
'ssh-rsa AAAArsa other-key'
].join('\n')
expect(filterAuthorizedKeys(content, 'dev1')).toBe(
@@ -221,16 +253,26 @@ describe('filterAuthorizedKeys', () => {
)
})
+ it('removes both forms in one pass when a file somehow holds both for the same id', () => {
+ const content = 'ssh-ed25519 AAAAa nodeterm-ios-x\nssh-ed25519 AAAAb nodeterm-mobile-x\nkeep k me\n'
+ expect(filterAuthorizedKeys(content, 'x')).toBe('keep k me\n')
+ })
+
it('preserves blank lines and the trailing newline of untouched files', () => {
- const content = 'ssh-ed25519 AAAAa keep-me\n\nssh-ed25519 AAAAb nodeterm-ios-x\n'
+ const content = 'ssh-ed25519 AAAAa keep-me\n\nssh-ed25519 AAAAb nodeterm-mobile-x\n'
expect(filterAuthorizedKeys(content, 'x')).toBe('ssh-ed25519 AAAAa keep-me\n\n')
})
- it('does not match a different device id or a substring', () => {
- const content = 'ssh-ed25519 AAAAb nodeterm-ios-dev10'
+ it('does not match a different device id or a substring, in either form', () => {
+ const content = 'ssh-ed25519 AAAAb nodeterm-mobile-dev10\nssh-ed25519 AAAAc nodeterm-ios-dev10'
expect(filterAuthorizedKeys(content, 'dev1')).toBe(content)
})
+ it('does not treat the bare phone-sent `nodeterm-ios` comment as a device stamp', () => {
+ const content = 'ssh-ed25519 AAAAb nodeterm-ios'
+ expect(filterAuthorizedKeys(content, '')).toBe(content)
+ })
+
it('returns content unchanged when nothing matches', () => {
const content = 'ssh-ed25519 AAAAb some@comment\n'
expect(filterAuthorizedKeys(content, 'nope')).toBe(content)
diff --git a/src/main/pairing-core.ts b/src/main/pairing-core.ts
index 5ba786c28..b56e48bcb 100644
--- a/src/main/pairing-core.ts
+++ b/src/main/pairing-core.ts
@@ -100,17 +100,33 @@ export function normalizeAuthorizedKeysLine(line: string): string {
}
/**
- * The attributable comment we stamp onto each paired key. Keeping it a single deterministic
- * token (`nodeterm-ios-<deviceId>`) is what lets revocation find & delete the exact line later.
+ * The attributable comment stamped onto every key paired from now on. One deterministic token
+ * (`nodeterm-mobile-<deviceId>`) is what lets revocation find & delete the exact line later.
+ * Platform-neutral: iOS and Android phones get the same stamp.
*/
+export const DEVICE_KEY_COMMENT_PREFIX = 'nodeterm-mobile-'
+
+/**
+ * The stamp used while the companion was iOS-only. Every iPhone paired before the rename still
+ * carries it in authorized_keys, and revoke MUST keep matching it — a revoke that only knew the
+ * new prefix would report the phone removed while its SSH key stayed live. Never stamped again.
+ */
+export const LEGACY_DEVICE_KEY_COMMENT_PREFIX = 'nodeterm-ios-'
+
export function deviceCommentFor(deviceId: string): string {
- return `nodeterm-ios-${deviceId}`
+ return `${DEVICE_KEY_COMMENT_PREFIX}${deviceId}`
+}
+
+/** Every comment a key for `deviceId` may carry: the current stamp first, then the legacy one. */
+export function deviceCommentsFor(deviceId: string): string[] {
+ return [deviceCommentFor(deviceId), `${LEGACY_DEVICE_KEY_COMMENT_PREFIX}${deviceId}`]
}
/**
- * Rewrite an incoming public-key line so its comment is exactly `nodeterm-ios-<deviceId>`,
- * replacing whatever comment the phone sent while keeping the key type + base64 blob intact.
- * The result is already normalized (single-space separated), ready for authorized_keys.
+ * Rewrite an incoming public-key line so its comment is exactly `nodeterm-mobile-<deviceId>`,
+ * replacing whatever comment the phone sent (the iOS app sends `nodeterm-ios`) while keeping the
+ * key type + base64 blob intact. The result is already normalized (single-space separated),
+ * ready for authorized_keys.
*/
export function rewriteKeyComment(publicKey: string, deviceId: string): string {
const parts = normalizeAuthorizedKeysLine(publicKey).split(' ')
@@ -120,18 +136,18 @@ export function rewriteKeyComment(publicKey: string, deviceId: string): string {
}
/**
- * Remove every authorized_keys line whose comment is exactly `nodeterm-ios-<deviceId>`,
- * preserving all other lines (including blanks, other keys' comments, and the trailing
- * newline) byte-for-byte. The caller writes the result back atomically.
+ * Remove every authorized_keys line whose comment is EXACTLY one of `deviceCommentsFor(deviceId)`
+ * (current or legacy stamp), preserving all other lines (including blanks, other keys' comments,
+ * and the trailing newline) byte-for-byte. The caller writes the result back atomically.
*/
export function filterAuthorizedKeys(content: string, deviceId: string): string {
- const target = deviceCommentFor(deviceId)
+ const targets = new Set(deviceCommentsFor(deviceId))
return content
.split('\n')
.filter((line) => {
const parts = line.trim().split(/\s+/)
// comment = everything after the key type + base64 blob
- return parts.slice(2).join(' ') !== target
+ return !targets.has(parts.slice(2).join(' '))
})
.join('\n')
}
diff --git a/src/main/pairing-service.test.ts b/src/main/pairing-service.test.ts
index 5ca650742..b1c604d04 100644
--- a/src/main/pairing-service.test.ts
+++ b/src/main/pairing-service.test.ts
@@ -70,7 +70,10 @@ function assertTempHome(): void {
assertTempHome()
// Stamped exactly the way pairing minted them, so `filterAuthorizedKeys` really matches.
-const KEY_A = rewriteKeyComment('ssh-ed25519 AAAAblobAAAA phone-a@ios', 'dev-a')
+// dev-a is an iPhone paired BEFORE the rename (legacy `nodeterm-ios-` stamp, written literally);
+// dev-b was paired after it (stamped exactly the way pairing mints keys now). A revoke must find
+// both — the first is what every existing user's authorized_keys looks like.
+const KEY_A = 'ssh-ed25519 AAAAblobAAAA nodeterm-ios-dev-a'
const KEY_B = rewriteKeyComment('ssh-ed25519 AAAAblobBBBB phone-b@ios', 'dev-b')
// Not ours: no revoke may ever touch it (a fix that "passes" by truncating the file must fail).
const KEY_OTHER = 'ssh-rsa AAAAlaptopblob jdub@laptop'
@@ -214,7 +217,7 @@ describe('revokeDevice', () => {
const keys = authKeys()
expect(keys).not.toContain('nodeterm-ios-dev-a')
- expect(keys).not.toContain('nodeterm-ios-dev-b')
+ expect(keys).not.toContain('nodeterm-mobile-dev-b')
expect(keys).toContain(KEY_OTHER) // the user's own key was never in scope
expect(deviceIds()).toEqual([])
expect(agentJson().hostId).toBe('host-keep-me') // fields we don't own survive the rewrite
@@ -236,7 +239,7 @@ describe('revokeDevice', () => {
await service.revokeDevice('dev-b')
const keys = authKeys()
- expect(keys).not.toContain('nodeterm-ios-dev-b')
+ expect(keys).not.toContain('nodeterm-mobile-dev-b')
expect(keys).toContain('nodeterm-ios-dev-a') // the failed revoke really did fail
expect(deviceIds()).toEqual(['dev-a'])
})
@@ -300,7 +303,7 @@ describe('pairing POST vs revoke', () => {
const { deviceId } = JSON.parse(respText) as { deviceId: string }
const keys = authKeys()
expect(keys).not.toContain('nodeterm-ios-dev-a') // the revoke stuck
- expect(keys).toContain(`nodeterm-ios-${deviceId}`) // …and so did the pairing
+ expect(keys).toContain(`nodeterm-mobile-${deviceId}`) // …and so did the pairing
expect(keys).toContain(KEY_OTHER)
expect(deviceIds()).toEqual(['dev-b', deviceId])
} finally {
@@ -350,7 +353,7 @@ describe('pairing remembers the phone’s relay device id', () => {
// The local id still stamps the key line and still identifies the entry — the new field is
// an addition, not a rename.
expect(deviceId).not.toBe('phone-abc')
- expect(authKeys()).toContain(`nodeterm-ios-${deviceId}`)
+ expect(authKeys()).toContain(`nodeterm-mobile-${deviceId}`)
} finally {
service.stop()
}
diff --git a/src/main/pairing-service.ts b/src/main/pairing-service.ts
index 5e89f1b71..08ecc18bb 100644
--- a/src/main/pairing-service.ts
+++ b/src/main/pairing-service.ts
@@ -377,8 +377,8 @@ function probeSsh(): Promise<boolean> {
/**
* Append an already-normalized public-key line to ~/.ssh/authorized_keys with the right
- * permissions. The caller stamps the attributable `nodeterm-ios-<deviceId>` comment via
- * `rewriteKeyComment` before this point.
+ * permissions. The caller stamps the attributable `nodeterm-mobile-<deviceId>` comment via
+ * `rewriteKeyComment` before this point (revoke also matches the legacy `nodeterm-ios-<id>`).
*/
async function appendAuthorizedKey(keyLine: string): Promise<void> {
const sshDir = path.join(os.homedir(), '.ssh')
diff --git a/src/main/pairing-service.windows.test.ts b/src/main/pairing-service.windows.test.ts
index 6f1058759..5055a4cd1 100644
--- a/src/main/pairing-service.windows.test.ts
+++ b/src/main/pairing-service.windows.test.ts
@@ -46,7 +46,7 @@ vi.mock('../core/device-id', () => ({ getDeviceId: () => 'test-host-device-id' }
import os from 'os'
import { createPairingService, type PairingDone, type PairingRelayDeps } from './pairing-service'
-import { rewriteKeyComment, type DeviceEntry } from './pairing-core'
+import { type DeviceEntry } from './pairing-core'
import { genKeyPair } from './remote/e2ee'
import type { Settings } from '../shared/types'
@@ -228,7 +228,8 @@ describe('Windows pairing: relay-only', () => {
})
describe('Windows revoke sweeps the administrators key file', () => {
- const KEY_A = rewriteKeyComment('ssh-ed25519 AAAAblobAAAA phone-a@ios', 'dev-a')
+ // A #758 manual copy made from an iPhone paired before the rename: the legacy stamp.
+ const KEY_A = 'ssh-ed25519 AAAAblobAAAA nodeterm-ios-dev-a'
const OTHER = 'ssh-ed25519 AAAAadminlaptop admin@laptop'
const seed = (): void => {
reset()