Skip to content
Snippets Groups Projects
index.js 8.75 MiB
Newer Older
  • Learn to ignore specific revisions
  • Romain CREY's avatar
    Romain CREY committed
            var name = 'arrayOf' + _capitalize(k);
            if (ndebug) {
                out[name] = noop;
                return;
            }
            var type = types[k];
            var expected = '[' + k + ']';
            out[name] = function (arg, msg) {
                if (!Array.isArray(arg)) {
                    _toss(msg, expected, type.operator, arg, type.actual);
                }
                var i;
                for (i = 0; i < arg.length; i++) {
                    if (!type.check(arg[i])) {
                        _toss(msg, expected, type.operator, arg, type.actual);
                    }
                }
            };
        });
    
        /* optionalArrayOf checks */
        keys.forEach(function (k) {
            var name = 'optionalArrayOf' + _capitalize(k);
            if (ndebug) {
                out[name] = noop;
                return;
            }
            var type = types[k];
            var expected = '[' + k + ']';
            out[name] = function (arg, msg) {
                if (arg === undefined || arg === null) {
                    return;
                }
                if (!Array.isArray(arg)) {
                    _toss(msg, expected, type.operator, arg, type.actual);
                }
                var i;
                for (i = 0; i < arg.length; i++) {
                    if (!type.check(arg[i])) {
                        _toss(msg, expected, type.operator, arg, type.actual);
                    }
                }
            };
        });
    
        /* re-export built-in assertions */
        Object.keys(assert).forEach(function (k) {
            if (k === 'AssertionError') {
                out[k] = assert[k];
                return;
            }
            if (ndebug) {
                out[k] = noop;
                return;
            }
            out[k] = assert[k];
        });
    
        /* export ourselves (for unit tests _only_) */
        out._setExports = _setExports;
    
        return out;
    }
    
    module.exports = _setExports(process.env.NODE_NDEBUG);
    
    
    /***/ }),
    
    Romain CREY's avatar
    Romain CREY committed
    /***/ (function(module, exports) {
    
    module.exports = require("assert");
    
    /***/ }),
    
    Romain CREY's avatar
    Romain CREY committed
    /***/ (function(module, exports, __webpack_require__) {
    
    // Copyright 2012 Joyent, Inc.  All rights reserved.
    
    
    var assert = __webpack_require__(107);
    var sshpk = __webpack_require__(110);
    var util = __webpack_require__(9);
    
    Romain CREY's avatar
    Romain CREY committed
    
    var HASH_ALGOS = {
      'sha1': true,
      'sha256': true,
      'sha512': true
    };
    
    var PK_ALGOS = {
      'rsa': true,
      'dsa': true,
      'ecdsa': true
    };
    
    function HttpSignatureError(message, caller) {
      if (Error.captureStackTrace)
        Error.captureStackTrace(this, caller || HttpSignatureError);
    
      this.message = message;
      this.name = caller.name;
    }
    util.inherits(HttpSignatureError, Error);
    
    function InvalidAlgorithmError(message) {
      HttpSignatureError.call(this, message, InvalidAlgorithmError);
    }
    util.inherits(InvalidAlgorithmError, HttpSignatureError);
    
    function validateAlgorithm(algorithm) {
      var alg = algorithm.toLowerCase().split('-');
    
      if (alg.length !== 2) {
        throw (new InvalidAlgorithmError(alg[0].toUpperCase() + ' is not a ' +
          'valid algorithm'));
      }
    
      if (alg[0] !== 'hmac' && !PK_ALGOS[alg[0]]) {
        throw (new InvalidAlgorithmError(alg[0].toUpperCase() + ' type keys ' +
          'are not supported'));
      }
    
      if (!HASH_ALGOS[alg[1]]) {
        throw (new InvalidAlgorithmError(alg[1].toUpperCase() + ' is not a ' +
          'supported hash algorithm'));
      }
    
      return (alg);
    }
    
    ///--- API
    
    module.exports = {
    
      HASH_ALGOS: HASH_ALGOS,
      PK_ALGOS: PK_ALGOS,
    
      HttpSignatureError: HttpSignatureError,
      InvalidAlgorithmError: InvalidAlgorithmError,
    
      validateAlgorithm: validateAlgorithm,
    
      /**
       * Converts an OpenSSH public key (rsa only) to a PKCS#8 PEM file.
       *
       * The intent of this module is to interoperate with OpenSSL only,
       * specifically the node crypto module's `verify` method.
       *
       * @param {String} key an OpenSSH public key.
       * @return {String} PEM encoded form of the RSA public key.
       * @throws {TypeError} on bad input.
       * @throws {Error} on invalid ssh key formatted data.
       */
      sshKeyToPEM: function sshKeyToPEM(key) {
        assert.string(key, 'ssh_key');
    
        var k = sshpk.parseKey(key, 'ssh');
        return (k.toString('pem'));
      },
    
    
      /**
       * Generates an OpenSSH fingerprint from an ssh public key.
       *
       * @param {String} key an OpenSSH public key.
       * @return {String} key fingerprint.
       * @throws {TypeError} on bad input.
       * @throws {Error} if what you passed doesn't look like an ssh public key.
       */
      fingerprint: function fingerprint(key) {
        assert.string(key, 'ssh_key');
    
        var k = sshpk.parseKey(key, 'ssh');
        return (k.fingerprint('md5').toString('hex'));
      },
    
      /**
       * Converts a PKGCS#8 PEM file to an OpenSSH public key (rsa)
       *
       * The reverse of the above function.
       */
      pemToRsaSSHKey: function pemToRsaSSHKey(pem, comment) {
        assert.equal('string', typeof (pem), 'typeof pem');
    
        var k = sshpk.parseKey(pem, 'pem');
        k.comment = comment;
        return (k.toString('ssh'));
      }
    };
    
    
    /***/ }),
    
    Romain CREY's avatar
    Romain CREY committed
    /***/ (function(module, exports, __webpack_require__) {
    
    // Copyright 2015 Joyent, Inc.
    
    
    var Key = __webpack_require__(111);
    var Fingerprint = __webpack_require__(114);
    var Signature = __webpack_require__(117);
    var PrivateKey = __webpack_require__(116);
    var Certificate = __webpack_require__(143);
    var Identity = __webpack_require__(144);
    var errs = __webpack_require__(115);
    
    Romain CREY's avatar
    Romain CREY committed
    
    module.exports = {
    	/* top-level classes */
    	Key: Key,
    	parseKey: Key.parse,
    	Fingerprint: Fingerprint,
    	parseFingerprint: Fingerprint.parse,
    	Signature: Signature,
    	parseSignature: Signature.parse,
    	PrivateKey: PrivateKey,
    	parsePrivateKey: PrivateKey.parse,
    	generatePrivateKey: PrivateKey.generate,
    	Certificate: Certificate,
    	parseCertificate: Certificate.parse,
    	createSelfSignedCertificate: Certificate.createSelfSigned,
    	createCertificate: Certificate.create,
    	Identity: Identity,
    	identityFromDN: Identity.parseDN,
    	identityForHost: Identity.forHost,
    	identityForUser: Identity.forUser,
    	identityForEmail: Identity.forEmail,
    	identityFromArray: Identity.fromArray,
    
    	/* errors */
    	FingerprintFormatError: errs.FingerprintFormatError,
    	InvalidAlgorithmError: errs.InvalidAlgorithmError,
    	KeyParseError: errs.KeyParseError,
    	SignatureParseError: errs.SignatureParseError,
    	KeyEncryptedError: errs.KeyEncryptedError,
    	CertificateParseError: errs.CertificateParseError
    };
    
    
    /***/ }),
    
    Romain CREY's avatar
    Romain CREY committed
    /***/ (function(module, exports, __webpack_require__) {
    
    // Copyright 2018 Joyent, Inc.
    
    module.exports = Key;
    
    
    var assert = __webpack_require__(107);
    var algs = __webpack_require__(112);
    var crypto = __webpack_require__(93);
    var Fingerprint = __webpack_require__(114);
    var Signature = __webpack_require__(117);
    var DiffieHellman = __webpack_require__(129).DiffieHellman;
    var errs = __webpack_require__(115);
    var utils = __webpack_require__(118);
    var PrivateKey = __webpack_require__(116);
    
    Romain CREY's avatar
    Romain CREY committed
    var edCompat;
    
    try {
    
    	edCompat = __webpack_require__(132);
    
    Romain CREY's avatar
    Romain CREY committed
    } catch (e) {
    	/* Just continue through, and bail out if we try to use it. */
    }
    
    var InvalidAlgorithmError = errs.InvalidAlgorithmError;
    var KeyParseError = errs.KeyParseError;
    
    var formats = {};
    
    formats['auto'] = __webpack_require__(133);
    formats['pem'] = __webpack_require__(134);
    formats['pkcs1'] = __webpack_require__(135);
    formats['pkcs8'] = __webpack_require__(136);
    formats['rfc4253'] = __webpack_require__(138);
    formats['ssh'] = __webpack_require__(140);
    formats['ssh-private'] = __webpack_require__(137);
    
    Romain CREY's avatar
    Romain CREY committed
    formats['openssh'] = formats['ssh-private'];
    
    formats['dnssec'] = __webpack_require__(141);
    formats['putty'] = __webpack_require__(142);
    
    Romain CREY's avatar
    Romain CREY committed
    15277 15278 15279 15280 15281 15282 15283 15284 15285 15286 15287 15288 15289 15290 15291 15292 15293 15294 15295 15296 15297 15298 15299 15300 15301 15302 15303 15304 15305 15306 15307 15308 15309 15310 15311 15312 15313 15314 15315 15316 15317 15318 15319 15320 15321 15322 15323 15324 15325 15326 15327 15328 15329 15330 15331 15332 15333 15334 15335 15336 15337 15338 15339 15340 15341 15342 15343 15344 15345 15346 15347 15348 15349 15350 15351 15352 15353 15354 15355 15356 15357 15358 15359 15360 15361 15362 15363 15364 15365 15366 15367 15368 15369 15370 15371 15372 15373 15374 15375 15376 15377 15378 15379 15380 15381 15382 15383 15384 15385 15386 15387 15388 15389 15390 15391 15392 15393 15394 15395 15396 15397 15398 15399 15400 15401 15402 15403 15404 15405 15406 15407 15408 15409 15410 15411 15412 15413 15414 15415 15416 15417 15418 15419 15420 15421 15422 15423 15424 15425 15426 15427 15428 15429 15430 15431 15432 15433 15434 15435 15436 15437 15438 15439 15440 15441 15442 15443 15444 15445 15446 15447 15448 15449 15450 15451 15452 15453 15454 15455 15456 15457 15458 15459 15460 15461 15462 15463 15464 15465 15466 15467 15468 15469 15470 15471 15472 15473 15474 15475 15476 15477 15478 15479 15480 15481 15482 15483 15484 15485 15486 15487 15488 15489 15490 15491 15492 15493 15494 15495 15496 15497 15498 15499 15500 15501 15502 15503 15504 15505 15506 15507 15508 15509 15510 15511 15512 15513 15514 15515 15516 15517 15518 15519 15520 15521 15522 15523 15524 15525 15526 15527 15528 15529 15530 15531 15532 15533 15534 15535 15536 15537 15538
    formats['ppk'] = formats['putty'];
    
    function Key(opts) {
    	assert.object(opts, 'options');
    	assert.arrayOfObject(opts.parts, 'options.parts');
    	assert.string(opts.type, 'options.type');
    	assert.optionalString(opts.comment, 'options.comment');
    
    	var algInfo = algs.info[opts.type];
    	if (typeof (algInfo) !== 'object')
    		throw (new InvalidAlgorithmError(opts.type));
    
    	var partLookup = {};
    	for (var i = 0; i < opts.parts.length; ++i) {
    		var part = opts.parts[i];
    		partLookup[part.name] = part;
    	}
    
    	this.type = opts.type;
    	this.parts = opts.parts;
    	this.part = partLookup;
    	this.comment = undefined;
    	this.source = opts.source;
    
    	/* for speeding up hashing/fingerprint operations */
    	this._rfc4253Cache = opts._rfc4253Cache;
    	this._hashCache = {};
    
    	var sz;
    	this.curve = undefined;
    	if (this.type === 'ecdsa') {
    		var curve = this.part.curve.data.toString();
    		this.curve = curve;
    		sz = algs.curves[curve].size;
    	} else if (this.type === 'ed25519' || this.type === 'curve25519') {
    		sz = 256;
    		this.curve = 'curve25519';
    	} else {
    		var szPart = this.part[algInfo.sizePart];
    		sz = szPart.data.length;
    		sz = sz * 8 - utils.countZeros(szPart.data);
    	}
    	this.size = sz;
    }
    
    Key.formats = formats;
    
    Key.prototype.toBuffer = function (format, options) {
    	if (format === undefined)
    		format = 'ssh';
    	assert.string(format, 'format');
    	assert.object(formats[format], 'formats[format]');
    	assert.optionalObject(options, 'options');
    
    	if (format === 'rfc4253') {
    		if (this._rfc4253Cache === undefined)
    			this._rfc4253Cache = formats['rfc4253'].write(this);
    		return (this._rfc4253Cache);
    	}
    
    	return (formats[format].write(this, options));
    };
    
    Key.prototype.toString = function (format, options) {
    	return (this.toBuffer(format, options).toString());
    };
    
    Key.prototype.hash = function (algo, type) {
    	assert.string(algo, 'algorithm');
    	assert.optionalString(type, 'type');
    	if (type === undefined)
    		type = 'ssh';
    	algo = algo.toLowerCase();
    	if (algs.hashAlgs[algo] === undefined)
    		throw (new InvalidAlgorithmError(algo));
    
    	var cacheKey = algo + '||' + type;
    	if (this._hashCache[cacheKey])
    		return (this._hashCache[cacheKey]);
    
    	var buf;
    	if (type === 'ssh') {
    		buf = this.toBuffer('rfc4253');
    	} else if (type === 'spki') {
    		buf = formats.pkcs8.pkcs8ToBuffer(this);
    	} else {
    		throw (new Error('Hash type ' + type + ' not supported'));
    	}
    	var hash = crypto.createHash(algo).update(buf).digest();
    	this._hashCache[cacheKey] = hash;
    	return (hash);
    };
    
    Key.prototype.fingerprint = function (algo, type) {
    	if (algo === undefined)
    		algo = 'sha256';
    	if (type === undefined)
    		type = 'ssh';
    	assert.string(algo, 'algorithm');
    	assert.string(type, 'type');
    	var opts = {
    		type: 'key',
    		hash: this.hash(algo, type),
    		algorithm: algo,
    		hashType: type
    	};
    	return (new Fingerprint(opts));
    };
    
    Key.prototype.defaultHashAlgorithm = function () {
    	var hashAlgo = 'sha1';
    	if (this.type === 'rsa')
    		hashAlgo = 'sha256';
    	if (this.type === 'dsa' && this.size > 1024)
    		hashAlgo = 'sha256';
    	if (this.type === 'ed25519')
    		hashAlgo = 'sha512';
    	if (this.type === 'ecdsa') {
    		if (this.size <= 256)
    			hashAlgo = 'sha256';
    		else if (this.size <= 384)
    			hashAlgo = 'sha384';
    		else
    			hashAlgo = 'sha512';
    	}
    	return (hashAlgo);
    };
    
    Key.prototype.createVerify = function (hashAlgo) {
    	if (hashAlgo === undefined)
    		hashAlgo = this.defaultHashAlgorithm();
    	assert.string(hashAlgo, 'hash algorithm');
    
    	/* ED25519 is not supported by OpenSSL, use a javascript impl. */
    	if (this.type === 'ed25519' && edCompat !== undefined)
    		return (new edCompat.Verifier(this, hashAlgo));
    	if (this.type === 'curve25519')
    		throw (new Error('Curve25519 keys are not suitable for ' +
    		    'signing or verification'));
    
    	var v, nm, err;
    	try {
    		nm = hashAlgo.toUpperCase();
    		v = crypto.createVerify(nm);
    	} catch (e) {
    		err = e;
    	}
    	if (v === undefined || (err instanceof Error &&
    	    err.message.match(/Unknown message digest/))) {
    		nm = 'RSA-';
    		nm += hashAlgo.toUpperCase();
    		v = crypto.createVerify(nm);
    	}
    	assert.ok(v, 'failed to create verifier');
    	var oldVerify = v.verify.bind(v);
    	var key = this.toBuffer('pkcs8');
    	var curve = this.curve;
    	var self = this;
    	v.verify = function (signature, fmt) {
    		if (Signature.isSignature(signature, [2, 0])) {
    			if (signature.type !== self.type)
    				return (false);
    			if (signature.hashAlgorithm &&
    			    signature.hashAlgorithm !== hashAlgo)
    				return (false);
    			if (signature.curve && self.type === 'ecdsa' &&
    			    signature.curve !== curve)
    				return (false);
    			return (oldVerify(key, signature.toBuffer('asn1')));
    
    		} else if (typeof (signature) === 'string' ||
    		    Buffer.isBuffer(signature)) {
    			return (oldVerify(key, signature, fmt));
    
    		/*
    		 * Avoid doing this on valid arguments, walking the prototype
    		 * chain can be quite slow.
    		 */
    		} else if (Signature.isSignature(signature, [1, 0])) {
    			throw (new Error('signature was created by too old ' +
    			    'a version of sshpk and cannot be verified'));
    
    		} else {
    			throw (new TypeError('signature must be a string, ' +
    			    'Buffer, or Signature object'));
    		}
    	};
    	return (v);
    };
    
    Key.prototype.createDiffieHellman = function () {
    	if (this.type === 'rsa')
    		throw (new Error('RSA keys do not support Diffie-Hellman'));
    
    	return (new DiffieHellman(this));
    };
    Key.prototype.createDH = Key.prototype.createDiffieHellman;
    
    Key.parse = function (data, format, options) {
    	if (typeof (data) !== 'string')
    		assert.buffer(data, 'data');
    	if (format === undefined)
    		format = 'auto';
    	assert.string(format, 'format');
    	if (typeof (options) === 'string')
    		options = { filename: options };
    	assert.optionalObject(options, 'options');
    	if (options === undefined)
    		options = {};
    	assert.optionalString(options.filename, 'options.filename');
    	if (options.filename === undefined)
    		options.filename = '(unnamed)';
    
    	assert.object(formats[format], 'formats[format]');
    
    	try {
    		var k = formats[format].read(data, options);
    		if (k instanceof PrivateKey)
    			k = k.toPublic();
    		if (!k.comment)
    			k.comment = options.filename;
    		return (k);
    	} catch (e) {
    		if (e.name === 'KeyEncryptedError')
    			throw (e);
    		throw (new KeyParseError(options.filename, format, e));
    	}
    };
    
    Key.isKey = function (obj, ver) {
    	return (utils.isCompatible(obj, Key, ver));
    };
    
    /*
     * API versions for Key:
     * [1,0] -- initial ver, may take Signature for createVerify or may not
     * [1,1] -- added pkcs1, pkcs8 formats
     * [1,2] -- added auto, ssh-private, openssh formats
     * [1,3] -- added defaultHashAlgorithm
     * [1,4] -- added ed support, createDH
     * [1,5] -- first explicitly tagged version
     * [1,6] -- changed ed25519 part names
     * [1,7] -- spki hash types
     */
    Key.prototype._sshpkApiVersion = [1, 7];
    
    Key._oldVersionDetect = function (obj) {
    	assert.func(obj.toBuffer);
    	assert.func(obj.fingerprint);
    	if (obj.createDH)
    		return ([1, 4]);
    	if (obj.defaultHashAlgorithm)
    		return ([1, 3]);
    	if (obj.formats['auto'])
    		return ([1, 2]);
    	if (obj.formats['pkcs1'])
    		return ([1, 1]);
    	return ([1, 0]);
    };
    
    
    /***/ }),
    
    Romain CREY's avatar
    Romain CREY committed
    /***/ (function(module, exports, __webpack_require__) {
    
    // Copyright 2015 Joyent, Inc.
    
    
    var Buffer = __webpack_require__(113).Buffer;
    
    Romain CREY's avatar
    Romain CREY committed
    
    var algInfo = {
    	'dsa': {
    		parts: ['p', 'q', 'g', 'y'],
    		sizePart: 'p'
    	},
    	'rsa': {
    		parts: ['e', 'n'],
    		sizePart: 'n'
    	},
    	'ecdsa': {
    		parts: ['curve', 'Q'],
    		sizePart: 'Q'
    	},
    	'ed25519': {
    		parts: ['A'],
    		sizePart: 'A'
    	}
    };
    algInfo['curve25519'] = algInfo['ed25519'];
    
    var algPrivInfo = {
    	'dsa': {
    		parts: ['p', 'q', 'g', 'y', 'x']
    	},
    	'rsa': {
    		parts: ['n', 'e', 'd', 'iqmp', 'p', 'q']
    	},
    	'ecdsa': {
    		parts: ['curve', 'Q', 'd']
    	},
    	'ed25519': {
    		parts: ['A', 'k']
    	}
    };
    algPrivInfo['curve25519'] = algPrivInfo['ed25519'];
    
    var hashAlgs = {
    	'md5': true,
    	'sha1': true,
    	'sha256': true,
    	'sha384': true,
    	'sha512': true
    };
    
    /*
     * Taken from
     * http://csrc.nist.gov/groups/ST/toolkit/documents/dss/NISTReCur.pdf
     */
    var curves = {
    	'nistp256': {
    		size: 256,
    		pkcs8oid: '1.2.840.10045.3.1.7',
    		p: Buffer.from(('00' +
    		    'ffffffff 00000001 00000000 00000000' +
    		    '00000000 ffffffff ffffffff ffffffff').
    		    replace(/ /g, ''), 'hex'),
    		a: Buffer.from(('00' +
    		    'FFFFFFFF 00000001 00000000 00000000' +
    		    '00000000 FFFFFFFF FFFFFFFF FFFFFFFC').
    		    replace(/ /g, ''), 'hex'),
    		b: Buffer.from((
    		    '5ac635d8 aa3a93e7 b3ebbd55 769886bc' +
    		    '651d06b0 cc53b0f6 3bce3c3e 27d2604b').
    		    replace(/ /g, ''), 'hex'),
    		s: Buffer.from(('00' +
    		    'c49d3608 86e70493 6a6678e1 139d26b7' +
    		    '819f7e90').
    		    replace(/ /g, ''), 'hex'),
    		n: Buffer.from(('00' +
    		    'ffffffff 00000000 ffffffff ffffffff' +
    		    'bce6faad a7179e84 f3b9cac2 fc632551').
    		    replace(/ /g, ''), 'hex'),
    		G: Buffer.from(('04' +
    		    '6b17d1f2 e12c4247 f8bce6e5 63a440f2' +
    		    '77037d81 2deb33a0 f4a13945 d898c296' +
    		    '4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16' +
    		    '2bce3357 6b315ece cbb64068 37bf51f5').
    		    replace(/ /g, ''), 'hex')
    	},
    	'nistp384': {
    		size: 384,
    		pkcs8oid: '1.3.132.0.34',
    		p: Buffer.from(('00' +
    		    'ffffffff ffffffff ffffffff ffffffff' +
    		    'ffffffff ffffffff ffffffff fffffffe' +
    		    'ffffffff 00000000 00000000 ffffffff').
    		    replace(/ /g, ''), 'hex'),
    		a: Buffer.from(('00' +
    		    'FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF' +
    		    'FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE' +
    		    'FFFFFFFF 00000000 00000000 FFFFFFFC').
    		    replace(/ /g, ''), 'hex'),
    		b: Buffer.from((
    		    'b3312fa7 e23ee7e4 988e056b e3f82d19' +
    		    '181d9c6e fe814112 0314088f 5013875a' +
    		    'c656398d 8a2ed19d 2a85c8ed d3ec2aef').
    		    replace(/ /g, ''), 'hex'),
    		s: Buffer.from(('00' +
    		    'a335926a a319a27a 1d00896a 6773a482' +
    		    '7acdac73').
    		    replace(/ /g, ''), 'hex'),
    		n: Buffer.from(('00' +
    		    'ffffffff ffffffff ffffffff ffffffff' +
    		    'ffffffff ffffffff c7634d81 f4372ddf' +
    		    '581a0db2 48b0a77a ecec196a ccc52973').
    		    replace(/ /g, ''), 'hex'),
    		G: Buffer.from(('04' +
    		    'aa87ca22 be8b0537 8eb1c71e f320ad74' +
    		    '6e1d3b62 8ba79b98 59f741e0 82542a38' +
    		    '5502f25d bf55296c 3a545e38 72760ab7' +
    		    '3617de4a 96262c6f 5d9e98bf 9292dc29' +
    		    'f8f41dbd 289a147c e9da3113 b5f0b8c0' +
    		    '0a60b1ce 1d7e819d 7a431d7c 90ea0e5f').
    		    replace(/ /g, ''), 'hex')
    	},
    	'nistp521': {
    		size: 521,
    		pkcs8oid: '1.3.132.0.35',
    		p: Buffer.from((
    		    '01ffffff ffffffff ffffffff ffffffff' +
    		    'ffffffff ffffffff ffffffff ffffffff' +
    		    'ffffffff ffffffff ffffffff ffffffff' +
    		    'ffffffff ffffffff ffffffff ffffffff' +
    		    'ffff').replace(/ /g, ''), 'hex'),
    		a: Buffer.from(('01FF' +
    		    'FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF' +
    		    'FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF' +
    		    'FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF' +
    		    'FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFC').
    		    replace(/ /g, ''), 'hex'),
    		b: Buffer.from(('51' +
    		    '953eb961 8e1c9a1f 929a21a0 b68540ee' +
    		    'a2da725b 99b315f3 b8b48991 8ef109e1' +
    		    '56193951 ec7e937b 1652c0bd 3bb1bf07' +
    		    '3573df88 3d2c34f1 ef451fd4 6b503f00').
    		    replace(/ /g, ''), 'hex'),
    		s: Buffer.from(('00' +
    		    'd09e8800 291cb853 96cc6717 393284aa' +
    		    'a0da64ba').replace(/ /g, ''), 'hex'),
    		n: Buffer.from(('01ff' +
    		    'ffffffff ffffffff ffffffff ffffffff' +
    		    'ffffffff ffffffff ffffffff fffffffa' +
    		    '51868783 bf2f966b 7fcc0148 f709a5d0' +
    		    '3bb5c9b8 899c47ae bb6fb71e 91386409').
    		    replace(/ /g, ''), 'hex'),
    		G: Buffer.from(('04' +
    		    '00c6 858e06b7 0404e9cd 9e3ecb66 2395b442' +
    		         '9c648139 053fb521 f828af60 6b4d3dba' +
    		         'a14b5e77 efe75928 fe1dc127 a2ffa8de' +
    		         '3348b3c1 856a429b f97e7e31 c2e5bd66' +
    		    '0118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9' +
    		         '98f54449 579b4468 17afbd17 273e662c' +
    		         '97ee7299 5ef42640 c550b901 3fad0761' +
    		         '353c7086 a272c240 88be9476 9fd16650').
    		    replace(/ /g, ''), 'hex')
    	}
    };
    
    module.exports = {
    	info: algInfo,
    	privInfo: algPrivInfo,
    	hashAlgs: hashAlgs,
    	curves: curves
    };
    
    
    /***/ }),
    
    Romain CREY's avatar
    Romain CREY committed
    /***/ (function(module, exports, __webpack_require__) {
    
    "use strict";
    /* eslint-disable node/no-deprecated-api */
    
    
    
    
    var buffer = __webpack_require__(95)
    
    Romain CREY's avatar
    Romain CREY committed
    var Buffer = buffer.Buffer
    
    var safer = {}
    
    var key
    
    for (key in buffer) {
      if (!buffer.hasOwnProperty(key)) continue
      if (key === 'SlowBuffer' || key === 'Buffer') continue
      safer[key] = buffer[key]
    }
    
    var Safer = safer.Buffer = {}
    for (key in Buffer) {
      if (!Buffer.hasOwnProperty(key)) continue
      if (key === 'allocUnsafe' || key === 'allocUnsafeSlow') continue
      Safer[key] = Buffer[key]
    }
    
    safer.Buffer.prototype = Buffer.prototype
    
    if (!Safer.from || Safer.from === Uint8Array.from) {
      Safer.from = function (value, encodingOrOffset, length) {
        if (typeof value === 'number') {
          throw new TypeError('The "value" argument must not be of type number. Received type ' + typeof value)
        }
        if (value && typeof value.length === 'undefined') {
          throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type ' + typeof value)
        }
        return Buffer(value, encodingOrOffset, length)
      }
    }
    
    if (!Safer.alloc) {
      Safer.alloc = function (size, fill, encoding) {
        if (typeof size !== 'number') {
          throw new TypeError('The "size" argument must be of type number. Received type ' + typeof size)
        }
        if (size < 0 || size >= 2 * (1 << 30)) {
          throw new RangeError('The value "' + size + '" is invalid for option "size"')
        }
        var buf = Buffer(size)
        if (!fill || fill.length === 0) {
          buf.fill(0)
        } else if (typeof encoding === 'string') {
          buf.fill(fill, encoding)
        } else {
          buf.fill(fill)
        }
        return buf
      }
    }
    
    if (!safer.kStringMaxLength) {
      try {
        safer.kStringMaxLength = process.binding('buffer').kStringMaxLength
      } catch (e) {
        // we can't determine kStringMaxLength in environments where process.binding
        // is unsupported, so let's not set it
      }
    }
    
    if (!safer.constants) {
      safer.constants = {
        MAX_LENGTH: safer.kMaxLength
      }
      if (safer.kStringMaxLength) {
        safer.constants.MAX_STRING_LENGTH = safer.kStringMaxLength
      }
    }
    
    module.exports = safer
    
    
    /***/ }),
    
    Romain CREY's avatar
    Romain CREY committed
    /***/ (function(module, exports, __webpack_require__) {
    
    // Copyright 2018 Joyent, Inc.
    
    module.exports = Fingerprint;
    
    
    var assert = __webpack_require__(107);
    var Buffer = __webpack_require__(113).Buffer;
    var algs = __webpack_require__(112);
    var crypto = __webpack_require__(93);
    var errs = __webpack_require__(115);
    var Key = __webpack_require__(111);
    var PrivateKey = __webpack_require__(116);
    var Certificate = __webpack_require__(143);
    var utils = __webpack_require__(118);
    
    Romain CREY's avatar
    Romain CREY committed
    
    var FingerprintFormatError = errs.FingerprintFormatError;
    var InvalidAlgorithmError = errs.InvalidAlgorithmError;
    
    function Fingerprint(opts) {
    	assert.object(opts, 'options');
    	assert.string(opts.type, 'options.type');
    	assert.buffer(opts.hash, 'options.hash');
    	assert.string(opts.algorithm, 'options.algorithm');
    
    	this.algorithm = opts.algorithm.toLowerCase();
    	if (algs.hashAlgs[this.algorithm] !== true)
    		throw (new InvalidAlgorithmError(this.algorithm));
    
    	this.hash = opts.hash;
    	this.type = opts.type;
    	this.hashType = opts.hashType;
    }
    
    Fingerprint.prototype.toString = function (format) {
    	if (format === undefined) {
    		if (this.algorithm === 'md5' || this.hashType === 'spki')
    			format = 'hex';
    		else
    			format = 'base64';
    	}
    	assert.string(format);
    
    	switch (format) {
    	case 'hex':
    		if (this.hashType === 'spki')
    			return (this.hash.toString('hex'));
    		return (addColons(this.hash.toString('hex')));
    	case 'base64':
    		if (this.hashType === 'spki')
    			return (this.hash.toString('base64'));
    		return (sshBase64Format(this.algorithm,
    		    this.hash.toString('base64')));
    	default:
    		throw (new FingerprintFormatError(undefined, format));
    	}
    };
    
    Fingerprint.prototype.matches = function (other) {
    	assert.object(other, 'key or certificate');
    	if (this.type === 'key' && this.hashType !== 'ssh') {
    		utils.assertCompatible(other, Key, [1, 7], 'key with spki');
    		if (PrivateKey.isPrivateKey(other)) {
    			utils.assertCompatible(other, PrivateKey, [1, 6],
    			    'privatekey with spki support');
    		}
    	} else if (this.type === 'key') {
    		utils.assertCompatible(other, Key, [1, 0], 'key');
    	} else {
    		utils.assertCompatible(other, Certificate, [1, 0],
    		    'certificate');
    	}
    
    	var theirHash = other.hash(this.algorithm, this.hashType);
    	var theirHash2 = crypto.createHash(this.algorithm).
    	    update(theirHash).digest('base64');
    
    	if (this.hash2 === undefined)
    		this.hash2 = crypto.createHash(this.algorithm).
    		    update(this.hash).digest('base64');
    
    	return (this.hash2 === theirHash2);
    };
    
    /*JSSTYLED*/
    var base64RE = /^[A-Za-z0-9+\/=]+$/;
    /*JSSTYLED*/
    var hexRE = /^[a-fA-F0-9]+$/;
    
    Fingerprint.parse = function (fp, options) {
    	assert.string(fp, 'fingerprint');
    
    	var alg, hash, enAlgs;
    	if (Array.isArray(options)) {
    		enAlgs = options;
    		options = {};
    	}
    	assert.optionalObject(options, 'options');
    	if (options === undefined)
    		options = {};
    	if (options.enAlgs !== undefined)
    		enAlgs = options.enAlgs;
    	if (options.algorithms !== undefined)
    		enAlgs = options.algorithms;
    	assert.optionalArrayOfString(enAlgs, 'algorithms');
    
    	var hashType = 'ssh';
    	if (options.hashType !== undefined)
    		hashType = options.hashType;
    	assert.string(hashType, 'options.hashType');
    
    	var parts = fp.split(':');
    	if (parts.length == 2) {
    		alg = parts[0].toLowerCase();
    		if (!base64RE.test(parts[1]))
    			throw (new FingerprintFormatError(fp));
    		try {
    			hash = Buffer.from(parts[1], 'base64');
    		} catch (e) {
    			throw (new FingerprintFormatError(fp));
    		}
    	} else if (parts.length > 2) {
    		alg = 'md5';
    		if (parts[0].toLowerCase() === 'md5')
    			parts = parts.slice(1);
    		parts = parts.map(function (p) {
    			while (p.length < 2)
    				p = '0' + p;
    			if (p.length > 2)
    				throw (new FingerprintFormatError(fp));
    			return (p);
    		});
    		parts = parts.join('');
    		if (!hexRE.test(parts) || parts.length % 2 !== 0)
    			throw (new FingerprintFormatError(fp));
    		try {
    			hash = Buffer.from(parts, 'hex');
    		} catch (e) {
    			throw (new FingerprintFormatError(fp));
    		}
    	} else {
    		if (hexRE.test(fp)) {
    			hash = Buffer.from(fp, 'hex');
    		} else if (base64RE.test(fp)) {
    			hash = Buffer.from(fp, 'base64');
    		} else {
    			throw (new FingerprintFormatError(fp));
    		}
    
    		switch (hash.length) {
    		case 32:
    			alg = 'sha256';
    			break;
    		case 16:
    			alg = 'md5';
    			break;
    		case 20:
    			alg = 'sha1';
    			break;
    		case 64:
    			alg = 'sha512';
    			break;
    		default:
    			throw (new FingerprintFormatError(fp));
    		}
    
    		/* Plain hex/base64: guess it's probably SPKI unless told. */
    		if (options.hashType === undefined)
    			hashType = 'spki';
    	}
    
    	if (alg === undefined)
    		throw (new FingerprintFormatError(fp));
    
    	if (algs.hashAlgs[alg] === undefined)
    		throw (new InvalidAlgorithmError(alg));
    
    	if (enAlgs !== undefined) {
    		enAlgs = enAlgs.map(function (a) { return a.toLowerCase(); });
    		if (enAlgs.indexOf(alg) === -1)
    			throw (new InvalidAlgorithmError(alg));
    	}
    
    	return (new Fingerprint({
    		algorithm: alg,
    		hash: hash,
    		type: options.type || 'key',
    		hashType: hashType
    	}));
    };
    
    function addColons(s) {
    	/*JSSTYLED*/
    	return (s.replace(/(.{2})(?=.)/g, '$1:'));
    }
    
    function base64Strip(s) {
    	/*JSSTYLED*/
    	return (s.replace(/=*$/, ''));
    }
    
    function sshBase64Format(alg, h) {
    	return (alg.toUpperCase() + ':' + base64Strip(h));