diff options
author | isaacs <i@izs.me> | 2020-07-23 20:58:04 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2020-07-29 21:53:42 +0300 |
commit | ad5e07d8bd86d1dbe2b03dc142f8c8d6f4828ffe (patch) | |
tree | 97b66f97d77f35774f10a5e3e9957b1897d150bb /node_modules/sshpk/lib/key.js | |
parent | a16994cfdd2f255016f3d8ee60d03473d80eabd8 (diff) |
Full dependency reboot
Reinstall everything from a clean node_modules and package-lock.json
state.
Re-generate list of bundleDependencies and node_modules/.gitignore with
a script that does the right thing based on actual dependency state.
Diffstat (limited to 'node_modules/sshpk/lib/key.js')
-rw-r--r-- | node_modules/sshpk/lib/key.js | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/node_modules/sshpk/lib/key.js b/node_modules/sshpk/lib/key.js index f8ef22dc7..706f83400 100644 --- a/node_modules/sshpk/lib/key.js +++ b/node_modules/sshpk/lib/key.js @@ -1,4 +1,4 @@ -// Copyright 2017 Joyent, Inc. +// Copyright 2018 Joyent, Inc. module.exports = Key; @@ -32,6 +32,8 @@ formats['ssh'] = require('./formats/ssh'); formats['ssh-private'] = require('./formats/ssh-private'); formats['openssh'] = formats['ssh-private']; formats['dnssec'] = require('./formats/dnssec'); +formats['putty'] = require('./formats/putty'); +formats['ppk'] = formats['putty']; function Key(opts) { assert.object(opts, 'options'); @@ -98,28 +100,44 @@ Key.prototype.toString = function (format, options) { return (this.toBuffer(format, options).toString()); }; -Key.prototype.hash = function (algo) { +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)); - if (this._hashCache[algo]) - return (this._hashCache[algo]); - var hash = crypto.createHash(algo). - update(this.toBuffer('rfc4253')).digest(); - this._hashCache[algo] = hash; + 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) { +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), - algorithm: algo + hash: this.hash(algo, type), + algorithm: algo, + hashType: type }; return (new Fingerprint(opts)); }; @@ -257,8 +275,9 @@ Key.isKey = function (obj, ver) { * [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, 6]; +Key.prototype._sshpkApiVersion = [1, 7]; Key._oldVersionDetect = function (obj) { assert.func(obj.toBuffer); |