Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getStampingBuffer(cmsSignedData, signerIndex, parameters)
{
//region Initial variables
let sequence = Promise.resolve();
let hashAlgorithm = "SHA-256";
let content = new ArrayBuffer(0);
let aTSHashIndex = new ArrayBuffer(0);
let resultBuffer = new ArrayBuffer(0);
//endregion
//region Get a "crypto" extension
const crypto = getCrypto();
if(typeof crypto === "undefined")
return Promise.reject("Unable to create WebCrypto object");
//endregion
//region Check input parameters
if("hashAlgorithm" in parameters)
hashAlgorithm = parameters.hashAlgorithm;
if("content" in parameters)
content = parameters.content; // ArrayBuffer
else
{
if("eContent" in cmsSignedData.encapContentInfo)
{
if((cmsSignedData.encapContentInfo.eContent.idBlock.tagClass === 1) &&
(cmsSignedData.encapContentInfo.eContent.idBlock.tagNumber === 4))
let ocspResponse;
//endregion
//region Check input parameters
if("hashAlgorithm" in parameters)
hashAlgorithm = parameters.hashAlgorithm;
if("ocspResponse" in parameters)
ocspResponse = parameters.ocspResponse; // in_window.org.pkijs.simpl.OCSP_RESPONSE
else
return Promise.reject("Parameter \"ocspResponse\" is mandatory for making \"OcspResponsesID\"");
//endregion
//region Get a "crypto" extension
const crypto = getCrypto();
if(typeof crypto === "undefined")
return Promise.reject("Unable to create WebCrypto object");
//endregion
//region Fill correct value for "hashIndAlgorithm"
sequence = sequence.then(
() => {
if(hashAlgorithm.toUpperCase() !== "SHA-1")
{
const oid = getOIDByAlgorithm({ name: hashAlgorithm });
if(oid === "")
return Promise.reject(`Incorrect hashing algorithm: ${hashAlgorithm}`);
this.ocspRepHash = new OtherHashAlgAndValue({
hashAlgorithm: new AlgorithmIdentifier({
algorithmId: oid,
getStampingBuffer(cmsSignedData, signerIndex, parameters = {})
{
//region Initial variables
let sequence = Promise.resolve();
let hashAlgorithm = "SHA-256";
let resultBuffer = new ArrayBuffer(0);
let signatureTimeStamp; // SignatureTimeStamp
let completeCertificateReferences; // CompleteCertificateReferences
let completeRevocationReferences; // CompleteRevocationReferences
//endregion
//region Get a "crypto" extension
const crypto = getCrypto();
if(typeof crypto === "undefined")
return Promise.reject("Unable to create WebCrypto object");
//endregion
//region Check input parameters
if("hashAlgorithm" in parameters)
hashAlgorithm = parameters.hashAlgorithm;
if("signatureTimeStamp" in parameters)
signatureTimeStamp = parameters.signatureTimeStamp;
else
return Promise.reject("Parameter \"signatureTimeStamp\" is mandatory for making \"CAdES-C-Timestamp\" attribute");
if("completeCertificateReferences" in parameters)
completeCertificateReferences = parameters.completeCertificateReferences;
else
{
//region Initial variables
const _this = this;
let sequence = Promise.resolve();
let hashAlgorithm = "SHA-256";
//endregion
//region Check input parameters
if("hashAlgorithm" in parameters)
hashAlgorithm = parameters.hashAlgorithm;
//endregion
//region Get a "crypto" extension
const crypto = getCrypto();
if(typeof crypto === "undefined")
return Promise.reject("Unable to create WebCrypto object");
//endregion
//region Fill correct value for "hashIndAlgorithm"
sequence = sequence.then(
() => {
if(hashAlgorithm.toUpperCase() !== "SHA-256")
{
const oid = getOIDByAlgorithm({ name: hashAlgorithm });
if(oid === "")
return Promise.reject(`Incorrect hashing algorithm: ${hashAlgorithm}`);
_this.hashIndAlgorithm = new AlgorithmIdentifier({
algorithmId: oid,
algorithmParams: new asn1js.Null()
async hash(hashName = "SHA-256")
{
//region Get a "crypto" extension
const crypto = getCrypto();
if(typeof crypto === "undefined")
throw new Error("Unable to create WebCrypto object");
//endregion
const prefixedBuffer = utilConcatBuf((new Uint8Array([0x00])).buffer, this.buffer);
return await crypto.digest({ name: hashName }, prefixedBuffer);
}
//**********************************************************************************
async hash(hashName = "SHA-256")
{
//region Get a "crypto" extension
const crypto = getCrypto();
if(typeof crypto === "undefined")
throw new Error("Unable to create WebCrypto object");
//endregion
const prefixedBuffer = utilConcatBuf((new Uint8Array([0x00])).buffer, this.buffer);
return await crypto.digest({ name: hashName }, prefixedBuffer);
}
//**********************************************************************************
//region Initial variables
let sequence = Promise.resolve();
const responses = [];
let basicResponse;
let ocspResponse;
let ocspPublicKey;
let asn1CertSimpl = asn1js.fromBER(stringToArrayBuffer(atob(OCSPcert)));
const certSimpl = new Certificate({ schema: asn1CertSimpl.result });
//endregion
//region Get a "crypto" extension
const crypto = getCrypto();
if(typeof crypto === "undefined")
return Promise.reject("No WebCrypto extension found");
//endregion
sequence = sequence.then(() =>
{
//region Get making OCSP response for each certificate in the request
for(let i = 0; i < request.tbsRequest.requestList.length; i++)
{
//region Initial variables
let valid = false;
//endregion
//region Check the certificate for "to be valid"
for(let j = 0; j < validCertificates.length; j++)
{
let tstInfo;
const signerInfo = new SignerInfo({
version: 1,
sid: new IssuerAndSerialNumber({
issuer: certSimpl.issuer,
serialNumber: certSimpl.serialNumber
})
});
signerInfo.signedAttrs = new SignedAndUnsignedAttributes({
type: 0
});
//endregion
//region Get a "crypto" extension
const crypto = getCrypto();
if(typeof crypto === "undefined")
return Promise.reject("No WebCrypto extension found");
//endregion
sequence = sequence.then(() => certSimpl.getPublicKey());
sequence = sequence.then(result =>
{
tspPublicKey = result;
const parameters = getAlgorithmParameters(result.algorithm.name, "importKey");
return crypto.importKey("pkcs8",
stringToArrayBuffer(atob(TSPkey)),
parameters.algorithm,
true,
static async fromCertificateAndIssuer(parameters)
{
//region Initial variables
const result = new PreCert();
//endregion
//region Get a "crypto" extension
const crypto = getCrypto();
if(typeof crypto === "undefined")
return Promise.reject("Unable to create WebCrypto object");
//endregion
//region Check input parameters
if(("certificate" in parameters) === false)
throw new Error("Missing mandatory parameter: certificate");
if(("issuer" in parameters) === false)
throw new Error("Missing mandatory parameter: issuer");
//endregion
//region Remove certificate extension
for(let i = 0; i < parameters.certificate.extensions.length; i++)
{
switch(parameters.certificate.extensions[i].extnID)
let cmsSignedSimpl;
const ocspRequest = new OCSPRequest();
const aTSHashIndex = new ATSHashIndex();
let asn1 = asn1js.fromBER(stringToArrayBuffer(atob(User10cert)));
const certSimpl = new Certificate({ schema: asn1.result });
asn1 = asn1js.fromBER(stringToArrayBuffer(atob(CAcert)));
const caCertSimpl = new Certificate({ schema: asn1.result });
//endregion
//region Get a "crypto" extension
const crypto = getCrypto();
if(typeof crypto === "undefined")
return Promise.reject("No WebCrypto extension found");
//endregion
sequence = sequence.then(() => certSimpl.getPublicKey());
sequence = sequence.then(result =>
{
userPublicKey = result;
return crypto.importKey("pkcs8",
stringToArrayBuffer(atob(User10key)),
{
name: result.algorithm.name,
hash: result.algorithm.hash || {}
},