asn1-schema icon indicating copy to clipboard operation
asn1-schema copied to clipboard

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

Open codewithmecoder opened this issue 2 years ago • 6 comments

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

GitHub repo

  • actual - expected

  • '1.2.840.113549.1.7.2'

  • '1.2.840.113549.1.9.16.1.4' ^ + expected - actual

    -1.2.840.113549.1.7.2
    +1.2.840.113549.1.9.16.1.4
    
    at C:\projects\tsr\src\test\index.ts:30:12
    at Generator.next (<anonymous>)
    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.

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.`

codewithmecoder avatar Feb 22 '23 07:02 codewithmecoder

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)

microshine avatar Mar 10 '23 11:03 microshine

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 avatar Mar 14 '23 04:03 codewithmecoder

That's what make the test failed

codewithmecoder avatar Mar 14 '23 04:03 codewithmecoder

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 avatar Mar 14 '23 12:03 microshine

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

image

microshine avatar Mar 14 '23 12:03 microshine

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

codewithmecoder avatar Mar 15 '23 01:03 codewithmecoder