From 1ecce760830fb463401df0a37f16065e7a01815c Mon Sep 17 00:00:00 2001 From: Lucas Leblow Date: Tue, 9 Apr 2024 11:33:51 -0700 Subject: [PATCH] Make generateUserCertificate backwards compatible --- packages/identity/src/createUserCert.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/identity/src/createUserCert.ts b/packages/identity/src/createUserCert.ts index bf3a250104..725ab49ab9 100644 --- a/packages/identity/src/createUserCert.ts +++ b/packages/identity/src/createUserCert.ts @@ -75,9 +75,24 @@ async function generateUserCertificate({ let altNames try { - nickname = attr?.[1].values[0].valueBlock.value - peerId = attr?.[2].values[0].valueBlock.value - onionAddress = attr?.[3].values[0].valueBlock.value + // MIGRATION: We removed dmPublicKey from the attributes at + // position 1. However, we maintain backwards compatibility for + // existing CSRs, if we ever need to re-issue certificates. + // + // TODO: Perhaps we should retreive values by their field type + // instead of their position. + if (attr?.length === 5) { + // publicKey = attr[0] + // dmPublicKey = attr[1] + nickname = attr?.[2].values[0].valueBlock.value + peerId = attr?.[3].values[0].valueBlock.value + onionAddress = attr?.[4].values[0].valueBlock.value + } else { + // publicKey = attr[0] + nickname = attr?.[1].values[0].valueBlock.value + peerId = attr?.[2].values[0].valueBlock.value + onionAddress = attr?.[3].values[0].valueBlock.value + } altNames = new GeneralNames({ names: [ new GeneralName({