Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
document.getElementById("cms-dgst-algos").innerHTML = "";
document.getElementById("cms-certs").style.display = "none";
document.getElementById("cms-crls").style.display = "none";
const certificatesTable = document.getElementById("cms-certificates") as HTMLTableElement;
while (certificatesTable.rows.length > 1)
certificatesTable.deleteRow(certificatesTable.rows.length - 1);
const crlsTable = document.getElementById("cms-rev-lists") as HTMLTableElement;
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 });
// endregion
// region Put information about digest algorithms in the CMS Signed Data
const dgstmap: { [oid: string]: string } = {
"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",
"2.16.840.1.101.3.4.2.3": "SHA-512"
};
for (let i = 0; i < cmsSignedSimpl.digestAlgorithms.length; i++) {
let typeval = dgstmap[cmsSignedSimpl.digestAlgorithms[i].algorithmId];
if (typeof typeval === "undefined")
typeval = cmsSignedSimpl.digestAlgorithms[i].algorithmId;
function passwordPrivacyInternal(password)
{
//region Initial variables
let sequence = Promise.resolve();
const passwordConverted = stringToArrayBuffer(password);
//endregion
//region Create simplified structires for certificate and private key
let asn1 = asn1js.fromBER(stringToArrayBuffer(fromBase64(certificateBASE64)));
const certSimpl = new Certificate({ schema: asn1.result });
asn1 = asn1js.fromBER(stringToArrayBuffer(fromBase64(privateKeyBASE64)));
const pkcs8Simpl = new PrivateKeyInfo({ schema: asn1.result });
//endregion
//region Put initial values for PKCS#12 structures
const pkcs12 = new PFX({
parsedValue: {
integrityMode: 0, // Password-Based Integrity Mode
authenticatedSafe: new AuthenticatedSafe({
parsedValue: {
safeContents: [
{
privacyMode: 1, // Password-Based Privacy Protection Mode
value: new SafeContents({
safeBags: [
new SafeBag({
bagId: "1.2.840.113549.1.12.10.1.1",
toSchema(encodeFlag = false)
{
let tbsSchema = {};
//region Decode stored TBS value
if(encodeFlag === false)
{
if(this.tbs.length === 0) // No stored certificate TBS part
return Certificate.schema().value[0];
tbsSchema = asn1js.fromBER(this.tbs).result;
}
//endregion
//region Create TBS schema via assembling from TBS parts
else
tbsSchema = this.encodeTBS();
//endregion
//region Construct and return new ASN.1 schema for this object
return (new asn1js.Sequence({
value: [
tbsSchema,
this.signatureAlgorithm.toSchema(),
this.signatureValue
]
}));
//endregion
toSchema()
{
//region Decode stored TBS value
if(this.valueBeforeDecode.byteLength === 0) // No stored encoded array, create "from scratch"
{
return (new asn1js.Sequence({
value: [new asn1js.Set({
value: Array.from(this.typesAndValues, element => element.toSchema())
})]
}));
}
const asn1 = asn1js.fromBER(this.valueBeforeDecode);
//endregion
//region Construct and return new ASN.1 schema for this object
return asn1.result;
//endregion
}
//**********************************************************************************
const accurTable = document.getElementById("resp-accuracy");
while(accurTable.rows.length > 1)
accurTable.deleteRow(accurTable.rows.length - 1);
const tsTable = document.getElementById("resp-tsa");
while(tsTable.rows.length > 1)
tsTable.deleteRow(tsTable.rows.length - 1);
const extTable = document.getElementById("resp-extensions");
while(extTable.rows.length > 1)
extTable.deleteRow(extTable.rows.length - 1);
//endregion
//region Decode existing TSP response
const asn1 = asn1js.fromBER(tspResponseBuffer);
const tspRespSimpl = new TimeStampResp({ schema: asn1.result });
//endregion
//region Put information about TSP response status
let status = "";
switch(tspRespSimpl.status.status)
{
case 0:
status = "granted";
break;
case 1:
status = "grantedWithMods";
break;
case 2:
status = "rejection";
case 2:
this.signatureAlgorithm = "dsa";
break;
case 3:
this.signatureAlgorithm = "ecdsa";
break;
default:
throw new Error("Object's stream was not correct for SignedCertificateTimestamp");
}
//endregion
//region Signature
const signatureLength = stream.getUint16();
const signatureData = (new Uint8Array(stream.getBlock(signatureLength))).buffer.slice(0);
const asn1 = asn1js.fromBER(signatureData);
if(asn1.offset === (-1))
throw new Error("Object's stream was not correct for SignedCertificateTimestamp");
this.signature = asn1.result;
//endregion
if(blockLength !== (47 + extensionsLength + signatureLength))
throw new Error("Object's stream was not correct for SignedCertificateTimestamp");
}
}
//**********************************************************************************
const revokedTable = document.getElementById("crl-rev-certs");
while(revokedTable.rows.length > 1)
revokedTable.deleteRow(revokedTable.rows.length - 1);
const extensionTable = document.getElementById("crl-extn-table");
while(extensionTable.rows.length > 1)
extensionTable.deleteRow(extensionTable.rows.length - 1);
const issuerTable = document.getElementById("crl-issuer-table");
while(issuerTable.rows.length > 1)
issuerTable.deleteRow(issuerTable.rows.length - 1);
//endregion
//region Decode existing CRL
const asn1 = asn1js.fromBER(crlBuffer);
const crlSimpl = new CertificateRevocationList({
schema: asn1.result
});
//endregion
//region Put information about CRL issuer
const rdnmap = {
"2.5.4.6": "C",
"2.5.4.10": "O",
"2.5.4.11": "OU",
"2.5.4.3": "CN",
"2.5.4.7": "L",
"2.5.4.8": "S",
"2.5.4.12": "T",
"2.5.4.42": "GN",
"2.5.4.43": "I",
//endregion
//region Initial activities
document.getElementById("tsp-req-extn-div").style.display = "none";
const imprintTable = document.getElementById("tsp-req-imprint");
while(imprintTable.rows.length > 1)
imprintTable.deleteRow(imprintTable.rows.length - 1);
const extensionTable = document.getElementById("tsp-req-extn-table");
while(extensionTable.rows.length > 1)
extensionTable.deleteRow(extensionTable.rows.length - 1);
//endregion
//region Decode existing TSP request
const asn1 = asn1js.fromBER(tspReqBuffer);
const tspReqSimpl = new TimeStampReq({ schema: asn1.result });
//endregion
//region Put information about message imprint
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",
"2.16.840.1.101.3.4.2.3": "SHA-512"
};
let hashAlgorithm = dgstmap[tspReqSimpl.messageImprint.hashAlgorithm.algorithmId];
if(typeof hashAlgorithm === "undefined")
hashAlgorithm = tspReqSimpl.messageImprint.hashAlgorithm.algorithmId;
const row = imprintTable.insertRow(imprintTable.rows.length);
exportedKey =>
{
const asn1 = asn1js.fromBER(exportedKey);
try
{
_this.fromSchema(asn1.result);
}
catch(exception)
{
return Promise.reject("Error during initializing object from schema");
}
return undefined;
},
error => Promise.reject(`Error during exporting public key: ${error}`)
const issuerTable = document.getElementById("cert-issuer-table");
while(issuerTable.rows.length > 1)
issuerTable.deleteRow(issuerTable.rows.length - 1);
const subjectTable = document.getElementById("cert-subject-table");
while(subjectTable.rows.length > 1)
subjectTable.deleteRow(subjectTable.rows.length - 1);
const extensionTable = document.getElementById("cert-extn-table");
while(extensionTable.rows.length > 1)
extensionTable.deleteRow(extensionTable.rows.length - 1);
//endregion
//region Decode existing X.509 certificate
const asn1 = asn1js.fromBER(certificateBuffer);
const certificate = new Certificate({ schema: asn1.result });
//endregion
//region Put information about X.509 certificate issuer
const rdnmap = {
"2.5.4.6": "C",
"2.5.4.10": "O",
"2.5.4.11": "OU",
"2.5.4.3": "CN",
"2.5.4.7": "L",
"2.5.4.8": "S",
"2.5.4.12": "T",
"2.5.4.42": "GN",
"2.5.4.43": "I",
"2.5.4.4": "SN",
"1.2.840.113549.1.9.1": "E-mail"