PeculiarVentures / asn1-schema

asn1-schema is a collection of TypeScript schemas that make working with common ASN.1 objects easy
33 stars 11 forks source link

id_ct_tstInfo is not passed testing, + expected - actual -1.2.840.113549.1.7.2 +1.2.840.113549.1.9.16.1.4 #89

Open codewithmecoder opened 1 year ago

codewithmecoder commented 1 year ago

I have faced this problem for days I could not find any solution. Any ideas? Thanks

GitHub repo

error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

If I comment assert.strictEqual(contentInfo.contentType, id_ct_tstInfo); out. It is giving me a new error:

`TSP 1) parse TSTInfo

0 passing (870ms) 1 failing

1) TSP parse TSTInfo: TypeError: Argument 'asn' is not instance of ASN.1 OctetString at OctetString.fromASN (node_modules\@peculiar\asn1-schema\build\cjs\types\octet_string.js:31:19) at Function.fromASN (node_modules\@peculiar\asn1-schema\build\cjs\parser.js:24:30) at Function.parse (node_modules\@peculiar\asn1-schema\build\cjs\parser.js:16:26) at Function.parse (node_modules\@peculiar\asn1-schema\build\cjs\convert.js:13:35) at C:\projects\tsr\src\test\index.ts:36:32 at Generator.next () at fulfilled (src\test\index.ts:28:58)

error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.`

microshine commented 1 year ago

contentType should be id-signedData. contentInfo.content keeps the content of OCTET_STRING

const contentInfo = AsnConvert.parse(file, TimeStampToken);
assert.strictEqual(contentInfo.contentType, id_signedData);

const tstInfo = AsnConvert.parse(contentInfo.content, TSTInfo);
SEQUENCE (2 elem)
  OBJECT IDENTIFIER 1.2.840.113549.1.7.2 signedData (PKCS #7)
  [0] (1 elem)
    SEQUENCE (5 elem)
      INTEGER 3
      SET (1 elem)
        SEQUENCE (1 elem)
          OBJECT IDENTIFIER 2.16.840.1.101.3.4.2.1 sha-256 (NIST Algorithm)
      SEQUENCE (2 elem)
        OBJECT IDENTIFIER 1.2.840.113549.1.9.16.1.4 tSTInfo (S/MIME Content Types)
codewithmecoder commented 1 year ago

id_signedData and id_ct_tstInfo are the same. contentInfo.contentType the value was 1.2.840.113549.1.9.16.1.4 it's not 1.2.840.113549.1.7.2.

codewithmecoder commented 1 year ago

That's what make the test failed

microshine commented 1 year ago

id_signedData and id_ct_tstInfo are the same.

This is wrong. They are different

id-signedData OBJECT IDENTIFIER ::= { iso(1) member-body(2)
   us(840) rsadsi(113549) pkcs(1) pkcs7(7) 2 }

id-ct-TSTInfo  OBJECT IDENTIFIER ::= { iso(1) member-body(2)
   us(840) rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) ct(1) 4}
microshine commented 1 year ago

Please look at this TimeStamp ASN.1 structure. Use this website https://lapo.it/asn1js to parse your files

image
codewithmecoder commented 1 year ago

Here is my update code.

import { AsnConvert, AsnParser, OctetString } from "@peculiar/asn1-schema";
import * as assert from "assert";
import path from "path";
import fs from "fs/promises";
import { TimeStampToken, TSTInfo } from "@peculiar/asn1-tsp";
import { id_signedData } from "@peculiar/asn1-cms";
context("TSP", () => {
  it("parse TSTInfo", async () => {
    const file = await fs.readFile(
      path.join(__dirname, "../resoures/response.tsr")
    );
    const contentInfo = AsnParser.parse(file, TimeStampToken);
    console.log(contentInfo.contentType);
    assert.strictEqual(contentInfo.contentType, id_signedData);
    const tstInfo = AsnConvert.parse(contentInfo.content, TSTInfo);
    console.log(tstInfo);
  });
});

And got this error. 2023-03-15_08h59_02