Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getSignatoryNodeFromCertificate = async (certBase64: string) => {
const cert = sshpk.parseCertificate(Buffer.from(certBase64, "base64"), "pem");
if (!cert) {
throw new Error("Unable to parse Corda certificate");
}
if (!cert.subjects || !(cert.subjects instanceof Array) || cert.subjects.length === 0) {
throw new Error("No subject found in X.509 certificate");
}
// Filter out the Organization components ('O' attribute)
const subjectComponents = cert.subjects[0].components.filter((subject) => subject.name === "o");
if (!subjectComponents || subjectComponents.length === 0) {
throw new Error("No subject found in X.509 certificate with 'O' (Organization) attribute");
}
return subjectComponents[0].value;
};
function authTls(req, res, next) {
var log = req.log;
var authCache = req.app.authCache;
var ufds = req.app.ufds;
var peerCert = req.connection.getPeerCertificate();
if (!peerCert || !peerCert.raw) {
next(new errors.UnauthorizedError());
return;
}
var cert = sshpk.parseCertificate(peerCert.raw, 'x509');
var peerKey = cert.subjectKey;
var peerKeyFp = peerKey.fingerprint('sha512').toString();
var lookupFp = peerKey.fingerprint('md5').toString('hex');
/*
* As well as a simple self-signed certificate for an actual account key,
* we also accept a certificate for a different key that is validly signed
* by an account key.
*
* If the user is using one of these new types of certificates, enforce
* the expiry time and use the issuer's CN to look up the real account
* key.
*/
if (cert.purposes && cert.purposes.indexOf('joyentDocker') !== -1) {
log.trace('found "joyentDocker" certificate purpose, will treat as '
+ 'new-style certificate');
transform: body => {
const cert = sshpk.parseCertificate(body, 'pem')
if (cert && cert.subjectKey) {
return cert.subjectKey
}
return null
}
})