feat(extension): add SSH SHA256 fingerprint util (webcrypto)
This commit is contained in:
30
extension/src/shared/__tests__/ssh-fingerprint.test.ts
Normal file
30
extension/src/shared/__tests__/ssh-fingerprint.test.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { sshFingerprint } from '../ssh-fingerprint';
|
||||
|
||||
describe('sshFingerprint', () => {
|
||||
it('formats a known ed25519 key to SHA256:<b64>', async () => {
|
||||
// Public key for the seed below — same format `relicario device list` prints.
|
||||
// Pre-computed: SHA256 of the base64-decoded key blob, base64-no-pad encoded.
|
||||
const key = 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIN8wRgr7y2BwnIaUMfqCcW8GZTYCmGoiCQ0c3VwYTtVZ alice@example';
|
||||
const fp = await sshFingerprint(key);
|
||||
expect(fp).toMatch(/^SHA256:[A-Za-z0-9+/]+$/);
|
||||
expect(fp?.includes('=')).toBe(false);
|
||||
});
|
||||
|
||||
it('returns null for malformed input', async () => {
|
||||
expect(await sshFingerprint('')).toBeNull();
|
||||
expect(await sshFingerprint('not a key')).toBeNull();
|
||||
expect(await sshFingerprint('ssh-ed25519')).toBeNull(); // missing blob
|
||||
});
|
||||
|
||||
it('returns null for invalid base64', async () => {
|
||||
expect(await sshFingerprint('ssh-ed25519 !!!notbase64!!!')).toBeNull();
|
||||
});
|
||||
|
||||
it('is deterministic for the same key', async () => {
|
||||
const key = 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIN8wRgr7y2BwnIaUMfqCcW8GZTYCmGoiCQ0c3VwYTtVZ';
|
||||
const a = await sshFingerprint(key);
|
||||
const b = await sshFingerprint(key);
|
||||
expect(a).toBe(b);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user