I am trying to decode the timestamp which I am receiving from my HTTP post request, but this is a really complex task, I do not even have any proper insight into ASN.1/RFC 3161 so if anyone out there is willing to help me out, I would really be stoked!
Code:
import { Action } from 'kawax-js';
import base64 from 'base-64';
var Ber = require('asn1').Ber;
class Timestamp extends Action {
static type = 'TIMESTAMP';
call = async (data) => {
const authEncoded = base64.encode(username+":"+password);
const formBody = Object.keys(data).map(key =>
encodeURIComponent(key) + '=' +
encodeURIComponent(data[key])).join('&');
const response = await
fetch("https://sign.test.cryptolog.com/tsa/post/", {
method: 'POST',
headers: {
'Accept': 'application/x-www-form-urlencoded',
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic ' + authEncoded,
'Access-Control-Allow-Origin': '*'
},
body: formBody
});
const bodyData = await response.arrayBuffer();
var reader = new Ber.Reader(Buffer.from(bodyData));
if (reader.peek() === Ber.Boolean)
console.log("",reader.readBoolean());
return bodyData;
}
}
export default Timestamp;
I am trying to use the asn1 npm package(https://www.npmjs.com/package/asn1).
This is the response I get when I run the code:
And if I change my await response.arrayBuffer()
to await response.text()
I get this:
I don't really know how to approach this, I tried a lot of different stuff but nothing seems to work, if anyone could point me into right direction that would be great!