How to use the sshpk.parseCertificate function in sshpk

To help you get started, we’ve selected a few sshpk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hyperledger-labs / weaver-dlt-interoperability / sdks / fabric / interoperation-node-sdk / src / InteroperableHelper.ts View on Github external
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;
};
github joyent / sdc-docker / lib / auth.js View on Github external
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');
github SmartThingsCommunity / smartapp-sdk-nodejs / lib / util / authorizer.js View on Github external
transform: body => {
				const cert = sshpk.parseCertificate(body, 'pem')
				if (cert && cert.subjectKey) {
					return cert.subjectKey
				}

				return null
			}
		})

sshpk

A library for finding and using SSH public keys

MIT
Latest version published 1 year ago

Package Health Score

74 / 100
Full package analysis