Decode Idunn identity byte vectors

This commit is contained in:
Meta Vens 2026-09-28 01:00:52 +02:00
commit 2c5dc3e278
2 changed files with 12 additions and 5 deletions

View file

@ -547,10 +547,10 @@ function openProviderHealthIdentity(credentialBytes: Buffer): crypto.KeyObject {
const [schema, identityId, publicKeyValue, protectedSeedValue, protectorKind, binding, version, assurance, createdAt, enrollmentNonceValue] = fields;
if (schema !== "gamecult.provider_health_identity.private.v1" || version !== "v1") throw new Error("Provider-health identity schema is unsupported.");
string(createdAt, "Provider-health identity creation time");
const enrollmentNonce = bytes(enrollmentNonceValue, "Provider-health enrollment nonce");
const enrollmentNonce = providerIdentityByteVector(enrollmentNonceValue, "Provider-health enrollment nonce");
if (enrollmentNonce.length !== 32) throw new Error("Provider-health enrollment nonce has an invalid length.");
const publicKey = bytesValue(publicKeyValue, "Provider-health public key");
const protectedSeed = bytesValue(protectedSeedValue, "Provider-health protected seed");
const publicKey = Buffer.from(providerIdentityByteVector(publicKeyValue, "Provider-health public key"));
const protectedSeed = Buffer.from(providerIdentityByteVector(protectedSeedValue, "Provider-health protected seed"));
const machineId = fs.readFileSync("/etc/machine-id", "utf8").trim();
if (!machineId) throw new Error("Linux machine-id is unavailable for provider-health identity.");
const expectedBinding = `${PROVIDER_PROTECTOR_CONTEXT}:machine-id-sha256:${sha256Hex(Buffer.from(machineId))}`;
@ -587,6 +587,13 @@ function readProviderHealthIdentityCredential(bytes: Buffer): Uint8Array {
return bytesValue(envelope[2], "Provider-health identity payload");
}
function providerIdentityByteVector(value: unknown, label: string): Uint8Array {
if (!Array.isArray(value) || value.some((byte) => typeof byte !== "number" || !Number.isInteger(byte) || byte < 0 || byte > 255)) {
throw new Error(`${label} is not a byte vector.`);
}
return Uint8Array.from(value as number[]);
}
function readAuthorityRecordBytes(bytes: Buffer, type: string, schemaId: string): Uint8Array {
const decoded = decode(bytes);
if (!Array.isArray(decoded) || decoded[0] !== CULTCACHE_STORE_FORMAT || !Array.isArray(decoded[1]) || !Array.isArray(decoded[2])) {

View file

@ -82,9 +82,9 @@ test("opens Idunn's machine-bound identity and signs the exact Expected incarnat
"gamecult-provider-health-identity",
"gamecult.provider_health_identity.private.v1",
Buffer.from(encode([
"gamecult.provider_health_identity.private.v1", providerIdentity, providerPublic, protectedSeed,
"gamecult.provider_health_identity.private.v1", providerIdentity, Array.from(providerPublic), Array.from(protectedSeed),
"linux_file_mode_machine_id_binding", binding, "v1", "os_installation_file_bound_cloneable_baseline",
"2026-01-01T00:00:00Z", new Uint8Array(32).fill(0x2a),
"2026-01-01T00:00:00Z", Array(32).fill(0x2a),
])),
"2026-01-01T00:00:00Z",
"gamecult.provider_health_identity.private.v1",