From e9f9d48a023d6200fd9eb941ade58a336f5dd473 Mon Sep 17 00:00:00 2001 From: Francesco Date: Thu, 14 Dec 2023 15:44:59 -0800 Subject: [PATCH] setSignature fixes --- package-lock.json | 4 ++-- package.json | 2 +- src/response.ts | 19 ++++++++++++------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 589cefc..6d9089b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@xevolab/timestamping-token", - "version": "1.1.0", + "version": "1.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@xevolab/timestamping-token", - "version": "1.1.0", + "version": "1.1.1", "license": "MIT", "dependencies": { "asn1js": "^3.0.5" diff --git a/package.json b/package.json index a3cd7c0..5db1c21 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xevolab/timestamping-token", - "version": "1.1.0", + "version": "1.1.1", "description": "Time Stamping Authority (TSA) implementation.", "keywords": [ "Timestamping Authority", diff --git a/src/response.ts b/src/response.ts index 527fbf5..70efebf 100644 --- a/src/response.ts +++ b/src/response.ts @@ -2,7 +2,7 @@ * Author : Francesco * Created at: 2023-12-09 17:52 * Edited by : Francesco - * Edited at : 2023-12-13 20:41 + * Edited at : 2023-12-14 15:43 * * Copyright (c) 2023 Xevolab S.R.L. */ @@ -30,6 +30,7 @@ export class TimeStampResp { public signingTime!: Date; public serialNumber!: Buffer; public buffer!: Buffer; + private asn1!: asn1js.Sequence; // Signature public payloadDigest?: Buffer; @@ -552,19 +553,23 @@ export class TimeStampResp { })] })); + this.asn1 = TimeStampResp; return Buffer.from(TimeStampResp.toBER(false)); } public setSignature(signature: Buffer) { - const tmp = asn1js.fromBER(this.buffer); // @ts-ignore - let ref = tmp.result.valueBlock.value[1].valueBlock.value[1].valueBlock.value[0].valueBlock.value; - ref = ref.at(-1).valueBlock.value[0].valueBlock.value.at(-1); - console.log(Buffer.from(ref.valueBlock.valueHexView)); + const index1 = this.asn1.valueBlock.value[1].valueBlock.value[1].valueBlock.value[0].valueBlock.value.length - 1; + // @ts-ignore + const index2 = this.asn1.valueBlock.value[1].valueBlock.value[1].valueBlock.value[0].valueBlock.value[index1].valueBlock.value[0].valueBlock.value.length - 1; + + // @ts-ignore + this.asn1.valueBlock.value[1].valueBlock.value[1].valueBlock.value[0].valueBlock.value[index1].valueBlock.value[0].valueBlock.value[index2] = new asn1js.OctetString({ + valueHex: signature + }); - ref.valueBlock.valueHexView = signature + this.buffer = Buffer.from(this.asn1.toBER(false)); - this.buffer = Buffer.from(tmp.result.toBER(false)); } }