Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
sequence = sequence.then(result =>
{
userPrivateKey = result;
cmsSignedSimpl = new SignedData({
version: 1,
encapContentInfo: new EncapsulatedContentInfo({
eContentType: "1.2.840.113549.1.7.1" // "data" content type
}),
signerInfos: [
new SignerInfo({
version: 1,
sid: new IssuerAndSerialNumber({
issuer: certSimpl.issuer,
serialNumber: certSimpl.serialNumber
})
})
],
certificates: [certSimpl]
});
fromSchema(schema)
{
super.fromSchema(schema);
//region Check "contentType"
if(this.contentType !== "1.2.840.113549.1.7.2") // signedData
throw new Error("Object's schema was not verified against input data for SignatureTimeStamp");
//endregion
//region Get internal "CMS_SIGNED_DATA"
const cmsSigned = new SignedData({ schema: this.content });
//endregion
//region Get internal TST_INFO
if(cmsSigned.encapContentInfo.eContentType !== "1.2.840.113549.1.9.16.1.4")
throw new Error("Incorrect format for SignatureTimeStamp");
if(("eContent" in cmsSigned.encapContentInfo) === false)
throw new Error("Incorrect format for SignatureTimeStamp");
if((cmsSigned.encapContentInfo.eContent instanceof asn1js.OctetString) === false)
throw new Error("Incorrect format for SignatureTimeStamp");
const asn1 = asn1js.fromBER(cmsSigned.encapContentInfo.eContent.valueBlock.valueHex);
this.tstInfo = new TSTInfo({ schema: asn1.result });
//endregion
}
//endregion
//region Change type of "tspResponse"
const asn1 = asn1js.fromBER(tspResponse);
tspResponse = new TimeStampResp({ schema: asn1.result });
//endregion
//region Initialize internal variables from "tspResponse"
if("timeStampToken" in tspResponse)
this.fromSchema(tspResponse.timeStampToken.toSchema(), false);
else
throw new Error("No neccessary \"timeStampToken\" inside \"tspResponse\"");
//endregion
//region Append "ATSHashIndex" into local unsigned attributes
const cmsSignedData = new SignedData({ schema: this.content });
cmsSignedData.signerInfos[0].unsignedAttrs = new SignedAndUnsignedAttributes({
type: 1, // UnsignedAttributes
attributes: [
this.aTSHashIndex.makeAttribute()
]
});
this.content = cmsSignedData.toSchema();
//endregion
//region Create and return attribute
return new Attribute({
type: "0.4.0.1733.2.4",
values: [
this.toSchema()
document.getElementById("cms-certs").style.display = "none";
document.getElementById("cms-crls").style.display = "none";
const certificatesTable = document.getElementById("cms-certificates");
while(certificatesTable.rows.length > 1)
certificatesTable.deleteRow(certificatesTable.rows.length - 1);
const crlsTable = document.getElementById("cms-rev-lists");
while(crlsTable.rows.length > 1)
crlsTable.deleteRow(crlsTable.rows.length - 1);
//endregion
//region Decode existing CMS Signed Data
const asn1 = asn1js.fromBER(cmsSignedBuffer);
const cmsContentSimpl = new ContentInfo({ schema: asn1.result });
const cmsSignedSimpl = new SignedData({ schema: cmsContentSimpl.content });
for(const signerInfo of cmsSignedSimpl.signerInfos)
{
if("signedAttrs" in signerInfo)
signerInfo.signedAttrs.attributes = Array.from(signerInfo.signedAttrs.attributes, element => new AttributeCAdES(element));
if("unsignedAttrs" in signerInfo)
signerInfo.unsignedAttrs.attributes = Array.from(signerInfo.unsignedAttrs.attributes, element => new AttributeCAdES(element));
}
//endregion
//region Put information about digest algorithms in the CMS Signed Data
const dgstmap = {
"1.3.14.3.2.26": "SHA-1",
"2.16.840.1.101.3.4.2.1": "SHA-256",
"2.16.840.1.101.3.4.2.2": "SHA-384",
fromSchema(schema, initValues = true)
{
super.fromSchema(schema);
if(initValues)
{
if(this.contentType !== "1.2.840.113549.1.7.2")
throw new Error("Incorrect object schema for archive-time-stamp-v3 attribute: incorrect content type");
this.tspResponse = new TimeStampResp({ timeStampToken: schema });
const cmsSignedData = new SignedData({ schema: this.content });
if(cmsSignedData.signerInfos.length !== 1)
throw new Error("Incorrect object schema for archive-time-stamp-v3 attribute: incorrect signerInfos length");
if(("unsignedAttrs" in cmsSignedData.signerInfos[0]) === false)
throw new Error("Incorrect object schema for archive-time-stamp-v3 attribute: missing unsignedAttrs");
if(cmsSignedData.signerInfos[0].unsignedAttrs.attributes.length !== 1)
throw new Error("Incorrect object schema for archive-time-stamp-v3 attribute: incorrect unsignedAttrs length");
const attribute = new Attribute(cmsSignedData.signerInfos[0].unsignedAttrs.attributes[0]);
if(attribute.type !== "0.4.0.1733.2.5")
throw new Error("Incorrect object schema for archive-time-stamp-v3 attribute: incorrect type for aTSHashIndex value");
let parsedValue;