Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
type: "2.5.4.3", // Common name
value: new asn1js.BmpString({ value: "Test" })
}));
certSimpl.notBefore.value = new Date(2013, 0, 1);
certSimpl.notAfter.value = new Date(2016, 0, 1);
certSimpl.extensions = []; // Extensions are not a part of certificate by default, it's an optional array
//region "KeyUsage" extension
const bitArray = new ArrayBuffer(1);
const bitView = new Uint8Array(bitArray);
bitView[0] |= 0x02; // Key usage "cRLSign" flag
//bitView[0] = bitView[0] | 0x04; // Key usage "keyCertSign" flag
const keyUsage = new asn1js.BitString({ valueHex: bitArray });
certSimpl.extensions.push(new Extension({
extnID: "2.5.29.15",
critical: false,
extnValue: keyUsage.toBER(false),
parsedValue: keyUsage // Parsed value for well-known extensions
}));
//endregion
//endregion
//region Create a new key pair
sequence = sequence.then(() =>
{
//region Get default algorithm parameters for key generation
const algorithm = getAlgorithmParameters(signAlg, "generatekey");
if("hash" in algorithm.algorithm)
algorithm.algorithm.hash.name = hashAlg;
{
if(asn1.result.distributionPoint.idBlock.tagNumber === 0) // GENERAL_NAMES variant
this.distributionPoint = Array.from(asn1.result.distributionPointNames, element => new GeneralName({ schema: element }));
if(asn1.result.distributionPoint.idBlock.tagNumber === 1) // RDN variant
{
this.distributionPoint = new RelativeDistinguishedNames({
schema: new asn1js.Sequence({
value: asn1.result.distributionPoint.valueBlock.value
})
});
}
}
if("reasons" in asn1.result)
this.reasons = new asn1js.BitString({ valueHex: asn1.result.reasons.valueBlock.valueHex });
if("cRLIssuer" in asn1.result)
this.cRLIssuer = Array.from(asn1.result.cRLIssuerNames, element => new GeneralName({ schema: element }));
//endregion
}
//**********************************************************************************
sequence = sequence.then(result =>
{
this.signatureValue = new asn1js.BitString({ valueHex: result });
});
//endregion
* @property {string} [signatureAlgorithm]
* @property {string} [signatureValue]
*/
const names = getParametersValue(parameters, "names", {});
return (new asn1js.Sequence({
value: [
CertificationRequestInfo(names.certificationRequestInfo || {}),
new asn1js.Sequence({
name: (names.signatureAlgorithm || "signatureAlgorithm"),
value: [
new asn1js.ObjectIdentifier(),
new asn1js.Any({ optional: true })
]
}),
new asn1js.BitString({ name: (names.signatureValue || "signatureValue") })
]
}));
}
//**********************************************************************************
const keyLocalIDView = new Uint8Array(keyLocalIDBuffer);
getRandomValues(keyLocalIDView);
const certLocalIDBuffer = new ArrayBuffer(4);
const certLocalIDView = new Uint8Array(certLocalIDBuffer);
getRandomValues(certLocalIDView);
//region "KeyUsage" attribute
const bitArray = new ArrayBuffer(1);
const bitView = new Uint8Array(bitArray);
bitView[0] |= 0x80;
const keyUsage = new asn1js.BitString({
valueHex: bitArray,
unusedBits: 7
});
//endregion
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 });
//region Add "keyUsage" attribute
algorithmParams: new asn1js.ObjectIdentifier({ value: this.parsedKey.namedCurve })
});
break;
case "RSA":
this.parsedKey = new RSAPublicKey({ json });
this.algorithm = new AlgorithmIdentifier({
algorithmId: "1.2.840.113549.1.1.1",
algorithmParams: new asn1js.Null()
});
break;
default:
throw new Error(`Invalid value for "kty" parameter: ${json.kty}`);
}
this.subjectPublicKey = new asn1js.BitString({ valueHex: this.parsedKey.toSchema().toBER(false) });
}
}
//**********************************************************************************
sequence = sequence.then(result =>
{
this.signature = new asn1js.BitString({ valueHex: result });
});
//endregion
}
["x", "y"].forEach((name) => {
if (name in jwk) {
parsedKey[name] = getCoordinate((jwk as any)[name], coordinateLength);
} else {
throw new Error(`Absent mandatory parameter '${name}'`);
}
});
const spki = new PublicKeyInfo();
spki.algorithm = new AlgorithmIdentifier({
algorithmId: "1.2.840.10045.2.1",
algorithmParams: new Asn1Js.ObjectIdentifier({ value: parsedKey.namedCurve }),
});
spki.subjectPublicKey = new Asn1Js.BitString({ valueHex: parsedKey.toSchema().toBER(false) });
return spki.toSchema().toBER(false);
}
static defaultValues(memberName)
{
switch(memberName)
{
case "signatureAlgorithm":
return new AlgorithmIdentifier();
case "signature":
return new asn1js.BitString();
case "certs":
return [];
default:
throw new Error(`Invalid member name for Signature class: ${memberName}`);
}
}
//**********************************************************************************
static defaultValues(memberName)
{
switch(memberName)
{
case "algorithm":
return new AlgorithmIdentifier();
case "subjectPublicKey":
return new asn1js.BitString();
default:
throw new Error(`Invalid member name for PublicKeyInfo class: ${memberName}`);
}
}
//**********************************************************************************