From d778a2aa0f5240b4de4514a4a12bbaf7b8d19dc5 Mon Sep 17 00:00:00 2001 From: Lizard Date: Sat, 28 Sep 2024 23:31:54 +0600 Subject: [PATCH] feat: v0.1.8 | Add test support for `CardSecurity` --- jsr.json | 2 +- package.json | 2 +- src/cardsecurity.ts | 24 ++++++++++++++++++++++++ src/index.ts | 1 + tests/dgs/EF_CardSecurity.bin | Bin 0 -> 2886 bytes tests/index.test.ts | 7 ++++++- 6 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 src/cardsecurity.ts create mode 100644 tests/dgs/EF_CardSecurity.bin diff --git a/jsr.json b/jsr.json index f0dc52f..309ef9c 100644 --- a/jsr.json +++ b/jsr.json @@ -1,6 +1,6 @@ { "name": "@li0ard/tsemrtd", - "version": "0.1.7", + "version": "0.1.8", "exports": "./src/index.ts", "publish": { "include": [ diff --git a/package.json b/package.json index 84a67db..204f93b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@li0ard/tsemrtd", "main": "dist/index.js", "types": "dist/index.d.ts", - "version": "0.1.7", + "version": "0.1.8", "type": "module", "author": "li0ard", "repository": { diff --git a/src/cardsecurity.ts b/src/cardsecurity.ts new file mode 100644 index 0000000..73079a3 --- /dev/null +++ b/src/cardsecurity.ts @@ -0,0 +1,24 @@ +import { AsnConvert, OctetString } from "@peculiar/asn1-schema"; +import { SecurityInfos } from "./asn1/eac"; +import { CertificateSet, ContentInfo, SignedData } from "@peculiar/asn1-cms"; + +/** + * Class for working with EF.CardSecurity + * @experimental +*/ +export class CardSecurity { + /** + * Get EAC/PACE security informations + * @param data Data of EF.CardSecurity file + */ + static load(data: Buffer) { + let contentInfo = AsnConvert.parse(data, ContentInfo) + let signedData = AsnConvert.parse(contentInfo.content, SignedData) + let securityInfos = AsnConvert.parse(signedData.encapContentInfo.eContent?.single as OctetString, SecurityInfos) + return { + certificates: signedData.certificates as CertificateSet, + securityInfos: securityInfos, + signatures: signedData.signerInfos + } + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 99a4d6c..fa91026 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,6 +11,7 @@ export { DG14 } from "./dg14" export { DG15 } from "./dg15" export { SOD } from "./sod" export { PKD } from "./pkd" +export { CardSecurity } from "./cardsecurity" export * as Enums from "./consts/enums" export * as Interfaces from "./consts/interfaces" export * as Oids from "./consts/oids" diff --git a/tests/dgs/EF_CardSecurity.bin b/tests/dgs/EF_CardSecurity.bin new file mode 100644 index 0000000000000000000000000000000000000000..ccae21388a8bc75cb0ae88d417e3a4b43ffef474 GIT binary patch literal 2886 zcmeHIc~BE)6wmH{B;?>emHQ?t@NFO>h+G3Cqf`()sR)EbMJ^#wEFh4rCMc*-l#W_! zlq(`_3W^9ttT5H8t*8i9q@tn-gNm(MiWcbxiiPPo{ipxco!Oav@BQBU?f1TSK!WB^ zrO%P_r6U>$4V4o#S4hxYPz1xZpazv5E#)I344|kQ1ri94stzc*6dHyiasu%H1j5A$ z1Sf%$dX#(+6zWnL6EGCTCKM>bpQa;&ksuV&n69Hv=}f8gx4w`?rA-JEa8(q+TPsNu zHq(yzQ$S4c%>oKBJAX^uRVp*!*frS>u6N-`Z?g}3q{QJ4Y|Juo>SjL5wf)j>EhjrG zvu^Ml6J7nX`E1d*#&)lJ?~JJa>fboFFJ9Q#40a5gx*{n#5VTGS?EID##q3M#d zyqsb8nCfM{UG+}oT-ji_^bfc3ds}W%q*Yx(Ae(4ucIfsd&mkwkXOI9TkidSIlgT7A z0u+!zRVOdv$|8UP=!Y{Qor}dMXKH zv0}xsF-{vqsfjU3A478^4UQ|sp&OhJ-P|}4MjEcJ&>gyQT)7@xj|dn!lfn#|Oj79k zlN2JcFf~0kUX&_|v*aZT_*0Z>dKk{-;8xILlF~RJIW|2}l$2%}9=9P$lxi6oBNlH? zPE8}LrJj60pwcGJgd(Kiiy{d0`b&c#C{8JCG$+ayBsywECg+6q`}G>Qq|l!%UwKlu zwtH4?gN{v2M-{usY<7x_N72J+kHeu5z^p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 @@ import { test, expect } from "bun:test" import { join } from "path" -import { COM, DG1, DG2, DG3, DG5, DG7, DG11, DG12, SOD, DG15, DG4, DG14, Schemas } from "../src" +import { COM, DG1, DG2, DG3, DG5, DG7, DG11, DG12, SOD, DG15, DG4, DG14, Schemas, CardSecurity } from "../src" const getDGContent = async (name: string): Promise => { return Buffer.from(await Bun.file(join(import.meta.dir, "dgs", name)).bytes()) @@ -106,4 +106,9 @@ test("SOD", async () => { expect(data.ldsObject.version).toBe(0) expect(data.ldsObject.algorithm.algorithm).toBe("1.3.14.3.2.26") expect(data.ldsObject.hashes.length).toBe(4) +}) + +test.todo("CardSecurity", async () => { + let data = CardSecurity.load(await getDGContent("EF_CardSecurity.bin")) + }) \ No newline at end of file