Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
runPemToHex: function(input, args) {
if (input.indexOf("-----BEGIN") < 0) {
// Add header so that the KEYUTIL function works
input = "-----BEGIN CERTIFICATE-----" + input;
}
if (input.indexOf("-----END") < 0) {
// Add footer so that the KEYUTIL function works
input = input + "-----END CERTIFICATE-----";
}
let cert = new r.X509();
cert.readCertPEM(input);
return cert.hex;
},
connect: function()
{
// // Set liveid
var pem = '-----BEGIN CERTIFICATE-----'+EOL+this.getCertificate().toString('base64').match(/.{0,64}/g).join('\n')+'-----END CERTIFICATE-----';
var deviceCert = new jsrsasign.X509();
deviceCert.readCertPEM(pem);
// var hSerial = deviceCert.getSerialNumberHex(); // '009e755e" hexadecimal string
// var sIssuer = deviceCert.getIssuerString(); // '/C=US/O=z2'
// var sSubject = deviceCert.getSubjectString(); // '/C=US/O=z2'
// var sNotBefore = deviceCert.getNotBefore(); // '100513235959Z'
// var sNotAfter = deviceCert.getNotAfter(); // '200513235959Z'
this.setLiveid(deviceCert.getSubjectString().slice(4))
// Set uuid
var uuid4 = Buffer.from(uuidParse.parse(uuid.v4()));
// Create public key
var ecKey = jsrsasign.X509.getPublicKeyFromCertPEM(pem);
.digest('base64');
} catch (error) {
console.error(`Certificate verification failed: ${error.message}`, error);
return {decoding: false};
}
const result: PinningResult = {};
const errorMessages: string[] = [];
for (const pin of pins) {
const {url, publicKeyInfo = [], issuerRootPubkeys = []} = pin;
if (url.test(hostname.toLowerCase().trim())) {
if (issuerRootPubkeys.length > 0) {
const x509 = new rs.X509();
x509.readCertHex(issuerCertHex);
result.verifiedIssuerRootPubkeys = issuerRootPubkeys.some(rawPublicKey => {
const x509PublicKey = rs.KEYUTIL.getKey(rawPublicKey);
return x509.verifySignature(x509PublicKey);
});
if (!result.verifiedIssuerRootPubkeys) {
const errorMessage = `Issuer root public key signatures: none of "${issuerRootPubkeys.join(
', '
)}" could be verified.`;
errorMessages.push(errorMessage);
}
}
result.verifiedPublicKeyInfo = publicKeyInfo
.reduce((arr: (boolean | undefined)[], pubkey) => {
constructor(pem) {
const method = 'constructor';
LOG.entry(method, pem);
this.pem = pem;
this.certificate = new X509();
this.certificate.readCertPEM(pem);
this.publicKey = KEYUTIL.getPEM(this.certificate.getPublicKey());
this.identifier = KJUR.crypto.Util.hashHex(this.certificate.getPublicKey().pubKeyHex, 'sha256');
this.issuer = KJUR.crypto.Util.hashHex(this.certificate.getIssuerString(), 'sha256');
this.name = /(\/CN=)(.*?)(\/|,|$)/.exec(this.certificate.getSubjectString())[2];
LOG.exit(method);
}
_updateCertData() {
//get x509 cert data
try {
const x509Path = this.beameStoreServices.getAbsoluteFileName(Config.CertFileNames.X509);
const rs = require('jsrsasign');
const X509 = rs.X509;
const fs = require('fs');
let pemStr = (fs.readFileSync(x509Path)).toString();
let x = new rs.X509();
x.readCertPEM(pemStr);
let hex = X509.pemToHex(pemStr);
let fingerprints = {
'sha1': rs.KJUR.crypto.Util.hashHex(hex, 'sha1'),
'sha256': rs.KJUR.crypto.Util.hashHex(hex, 'sha256')
},
ai = X509.getExtAIAInfo(hex),
alt = X509.getExtSubjectAltName(hex),
keyUsageStr = X509.getExtKeyUsageString(hex),
alg = x.getSignatureAlgorithmField(),
subjectStr = x.getSubjectString();
let subject = {
"commonName": "",
const getCertificateFromPEM = function(pem) {
const normalizedPEM = normalizeX509PEM(pem);
const cert = new X509();
cert.readCertPEM(normalizedPEM);
return cert;
};
runParseX509: function (input, args) {
if (!input.length) {
return "No input";
}
let cert = new r.X509(),
inputFormat = args[0];
switch (inputFormat) {
case "DER Hex":
input = input.replace(/\s/g, "");
cert.readCertHex(input);
break;
case "PEM":
cert.readCertPEM(input);
break;
case "Base64":
cert.readCertHex(Utils.toHex(Utils.fromBase64(input, null, "byteArray"), ""));
break;
case "Raw":
cert.readCertHex(Utils.toHex(Utils.strToByteArray(input), ""));
break;