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 0000000..ccae213 Binary files /dev/null and b/tests/dgs/EF_CardSecurity.bin differ diff --git a/tests/index.test.ts b/tests/index.test.ts index 9e5572b..1f690de 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -1,6 +1,6 @@ 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