carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1import {createECDH, createHash, hkdfSync, createCipheriv} from 'node:crypto';
2import {writeFileSync} from 'node:fs';
3// Fixed synthetic keys; this vector is independent of the Go implementation.
4const scalar = n => { const b=Buffer.alloc(32); b[31]=n; return b; };
5const recipient=createECDH('prime256v1'); recipient.setPrivateKey(scalar(1));
6const ephemeral=createECDH('prime256v1'); ephemeral.setPrivateKey(scalar(2));
7const binding={Version:1,Direction:'input',Account:'bds',App:'home',Host:'test.home.example',RequestID:'request-0001',AttemptID:'attempt-0001',Recipient:createHash('sha256').update(recipient.getPublicKey()).digest('hex')};
8const length = n => {const b=Buffer.alloc(4);b.writeUInt32BE(n);return b;};
9const fields=[Buffer.from('CME1'),length(1),Buffer.from('input'),...['Account','App','Host','RequestID','AttemptID','Recipient'].map(k=>Buffer.from(binding[k]))];
10const aad=Buffer.concat(fields.flatMap(f=>[length(f.length),f]));
11const shared=ephemeral.computeSecret(recipient.getPublicKey());
12const key=Buffer.from(hkdfSync('sha256',shared,Buffer.alloc(0),Buffer.from('carlos-maintenance-v1'),32));
13const nonce=Buffer.from(Array.from({length:12},(_,i)=>i));const plaintext=Buffer.from('maintenance-secret-canary');
14const cipher=createCipheriv('aes-256-gcm',key,nonce);cipher.setAAD(aad);
15const ciphertext=Buffer.concat([cipher.update(plaintext),cipher.final(),cipher.getAuthTag()]);
16const wire=Buffer.concat([Buffer.from('CME1'),ephemeral.getPublicKey(),nonce,ciphertext]);
17const vector={provenance:'Synthetic keys; independently generated with Node/OpenSSL P-256/ECDH/HKDF-SHA256/AES-GCM, not Go output.',recipient_private_hex:scalar(1).toString('hex'),ephemeral_private_hex:scalar(2).toString('hex'),nonce_hex:nonce.toString('hex'),plaintext:plaintext.toString(),binding,aad_hex:aad.toString('hex'),envelope:wire.toString('base64')};
18writeFileSync(new URL('./envelope-vector.json',import.meta.url),JSON.stringify(vector,null,2)+'\n');
19