sshpk
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -15,2 +15,6 @@ // Copyright 2015 Joyent, Inc. | ||
sizePart: 'Q' | ||
}, | ||
'ed25519': { | ||
parts: ['Q'], | ||
sizePart: 'Q' | ||
} | ||
@@ -28,2 +32,5 @@ }; | ||
parts: ['curve', 'Q', 'd'] | ||
}, | ||
'ed25519': { | ||
parts: ['Q', 'd'] | ||
} | ||
@@ -30,0 +37,0 @@ }; |
@@ -17,2 +17,3 @@ // Copyright 2015 Joyent, Inc. | ||
var pkcs8 = require('./pkcs8'); | ||
var sshpriv = require('./ssh-private'); | ||
@@ -73,2 +74,6 @@ /* | ||
/* The new OpenSSH internal format abuses PEM headers */ | ||
if (alg && alg.toLowerCase() === 'openssh') | ||
return (sshpriv.readSSHPrivate(type, buf)); | ||
var der = new asn1.BerReader(buf); | ||
@@ -75,0 +80,0 @@ der.originalInput = input; |
@@ -5,2 +5,3 @@ // Copyright 2015 Joyent, Inc. | ||
read: read.bind(undefined, false, undefined), | ||
readType: read.bind(undefined, false), | ||
write: write, | ||
@@ -19,2 +20,3 @@ /* semi-private api, used by sshpk-agent */ | ||
var PrivateKey = require('../private-key'); | ||
var SSHBuffer = require('../ssh-buffer'); | ||
@@ -27,2 +29,4 @@ function algToKeyType(alg) { | ||
return ('rsa'); | ||
else if (alg === 'ssh-ed25519') | ||
return ('ed25519'); | ||
else if (alg.match(/^ecdsa-sha2-/)) | ||
@@ -40,2 +44,4 @@ return ('ecdsa'); | ||
return ('ssh-rsa'); | ||
else if (key.type === 'ed25519') | ||
return ('ssh-ed25519'); | ||
else if (key.type === 'ecdsa') | ||
@@ -47,10 +53,2 @@ return ('ecdsa-sha2-' + key.part.curve.data.toString()); | ||
function readLV(buf, offset, parts) { | ||
var len = buf.readUInt32BE(offset); | ||
offset += 4; | ||
parts.push({data: buf.slice(offset, offset + len)}); | ||
offset += len; | ||
return (offset); | ||
} | ||
function read(partial, type, buf) { | ||
@@ -64,16 +62,9 @@ if (typeof (buf) === 'string') | ||
var parts = key.parts = []; | ||
var offset = 0; | ||
offset = readLV(buf, offset, parts); | ||
var sshbuf = new SSHBuffer({buffer: buf}); | ||
assert.ok(parts.length >= 1, | ||
'key must have at least one part'); | ||
assert.ok(parts[0].data.length > 0, | ||
'first key part must not be empty'); | ||
var alg = sshbuf.readString(); | ||
assert.ok(!sshbuf.atEnd(), 'key must have at least one part'); | ||
var alg = parts[0].data.toString(); | ||
key.type = algToKeyType(alg); | ||
/* Now chop off the algorithm identifier */ | ||
parts = key.parts = parts.slice(1); | ||
var partCount = algs.info[key.type].parts.length; | ||
@@ -83,6 +74,6 @@ if (type && type === 'private') | ||
while (offset < buf.length && parts.length < partCount) | ||
offset = readLV(buf, offset, parts); | ||
while (!partial && offset < buf.length) | ||
offset = readLV(buf, offset, parts); | ||
while (!sshbuf.atEnd() && parts.length < partCount) | ||
parts.push(sshbuf.readPart()); | ||
while (!partial && !sshbuf.atEnd()) | ||
parts.push(sshbuf.readPart()); | ||
@@ -92,3 +83,3 @@ assert.ok(parts.length >= 1, | ||
key._rfc4253Cache = buf.slice(0, offset); | ||
key._rfc4253Cache = sshbuf.toBuffer(); | ||
@@ -126,31 +117,17 @@ var Constructor = Key; | ||
var size = 0; | ||
for (i = 0; i < parts.length; ++i) | ||
/* +1 in case it's a bignum that needs a leading 0 */ | ||
size += 4 + 1 + key.part[parts[i]].data.length; | ||
size += alg.length + 4; | ||
var buf = new SSHBuffer({}); | ||
var buf = new Buffer(size); | ||
var o = 0; | ||
buf.writeString(alg); | ||
buf.writeUInt32BE(alg.length, o); | ||
o += 4; | ||
o += buf.write(alg, o); | ||
for (i = 0; i < parts.length; ++i) { | ||
var data = key.part[parts[i]].data; | ||
if (parts[i] !== 'curve' && (data[0] & 0x80) == 0x80) { | ||
buf.writeUInt32BE(data.length + 1, o); | ||
o += 4; | ||
buf[o++] = 0; | ||
o += data.copy(buf, o); | ||
} else { | ||
buf.writeUInt32BE(data.length, o); | ||
o += 4; | ||
o += data.copy(buf, o); | ||
var pre = new Buffer(1); | ||
pre[0] = 0; | ||
data = Buffer.concat([pre, data]); | ||
} | ||
buf.writeBuffer(data); | ||
} | ||
buf = buf.slice(0, o); | ||
return (buf); | ||
return (buf.toBuffer()); | ||
} |
// Copyright 2015 Joyent, Inc. | ||
module.exports = { | ||
read: read, | ||
write: write | ||
}; | ||
var assert = require('assert-plus'); | ||
var rfc4253 = require('./rfc4253'); | ||
var utils = require('../utils'); | ||
var Key = require('../key'); | ||
var PrivateKey = require('../private-key'); | ||
var sshpriv = require('./ssh-private'); | ||
function read(buf) { | ||
@@ -13,2 +22,9 @@ if (typeof (buf) !== 'string') { | ||
var lines = buf.split('\n'); | ||
if (lines.length > 2) | ||
return (sshpriv.read(buf)); | ||
if (lines[0].match(/*JSSTYLED*/ | ||
/BEGIN ([A-Z]+ )?(PUBLIC|PRIVATE) KEY/)) | ||
return (sshpriv.read(buf)); | ||
var parts = buf.split(' '); | ||
@@ -32,2 +48,4 @@ assert.ok(parts.length >= 2); | ||
assert.object(key); | ||
if (key instanceof PrivateKey) | ||
return (sshpriv.write(key)); | ||
@@ -46,6 +64,1 @@ var parts = []; | ||
} | ||
module.exports = { | ||
read: read, | ||
write: write | ||
}; |
@@ -17,2 +17,3 @@ // Copyright 2015 Joyent, Inc. | ||
var formats = {}; | ||
formats['auto'] = require('./formats/auto'); | ||
formats['pem'] = require('./formats/pem'); | ||
@@ -23,2 +24,4 @@ formats['pkcs1'] = require('./formats/pkcs1'); | ||
formats['ssh'] = require('./formats/ssh'); | ||
formats['ssh-private'] = require('./formats/ssh-private'); | ||
formats['openssh'] = formats['ssh-private']; | ||
@@ -177,3 +180,3 @@ function Key(opts) { | ||
if (format === undefined) | ||
format = 'ssh'; | ||
format = 'auto'; | ||
assert.string(format, 'format'); | ||
@@ -180,0 +183,0 @@ if (name === undefined) |
@@ -19,2 +19,3 @@ // Copyright 2015 Joyent, Inc. | ||
var formats = {}; | ||
formats['auto'] = require('./formats/auto'); | ||
formats['pem'] = require('./formats/pem'); | ||
@@ -24,2 +25,5 @@ formats['pkcs1'] = require('./formats/pkcs1'); | ||
formats['rfc4253'] = require('./formats/rfc4253'); | ||
formats['ssh-private'] = require('./formats/ssh-private'); | ||
formats['openssh'] = formats['ssh-private']; | ||
formats['ssh'] = formats['ssh-private']; | ||
@@ -123,3 +127,3 @@ function PrivateKey(opts) { | ||
if (format === undefined) | ||
format = 'pem'; | ||
format = 'auto'; | ||
assert.string(format, 'format'); | ||
@@ -126,0 +130,0 @@ if (name === undefined) |
{ | ||
"name": "sshpk", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "A library for finding and using SSH public keys", | ||
@@ -35,6 +35,11 @@ "main": "lib/index.js", | ||
}, | ||
"directories": { | ||
"bin": "./bin", | ||
"lib": "./lib" | ||
}, | ||
"homepage": "https://github.com/arekinath/node-sshpk#readme", | ||
"dependencies": { | ||
"asn1": ">=0.2.3 <0.3.0", | ||
"assert-plus": ">=0.1.5 <0.2.0" | ||
"assert-plus": ">=0.1.5 <0.2.0", | ||
"dashdash": ">=1.10.1 <2.0.0" | ||
}, | ||
@@ -41,0 +46,0 @@ "optionalDependencies": { |
@@ -7,4 +7,4 @@ sshpk | ||
Supports RSA, DSA and ECDSA (nistp-\*) key types, in PEM (PKCS#1, PKCS#8) and | ||
OpenSSH formats. | ||
Supports RSA, DSA, ECDSA (nistp-\*) and ED25519 key types, in PEM (PKCS#1, | ||
PKCS#8) and OpenSSH formats. | ||
@@ -115,3 +115,3 @@ This library has been extracted from | ||
### `parseKey(data[, format = 'ssh'[, name]])` | ||
### `parseKey(data[, format = 'auto'[, name]])` | ||
@@ -123,6 +123,10 @@ Parses a key from a given data format and returns a new `Key` object. | ||
- `data` -- Either a Buffer or String, containing the key | ||
- `format` -- String name of format to use, valid options are `pem` (supports | ||
both PKCS#1 and PKCS#8), `rfc4253` (raw OpenSSH wire format, as | ||
returned by `ssh-agent`, for example), `ssh` (OpenSSH format), | ||
`pkcs1`, `pkcs8` | ||
- `format` -- String name of format to use, valid options are: | ||
- `auto`: choose automatically from all below | ||
- `pem`: supports both PKCS#1 and PKCS#8 | ||
- `ssh`: standard OpenSSH format, | ||
- `pkcs1`, `pkcs8`: variants of `pem` | ||
- `rfc4253`: raw OpenSSH wire format | ||
- `openssh`: new post-OpenSSH 6.5 internal format, produced by | ||
`ssh-keygen -o` | ||
- `name` -- Optional name for the key being parsed (eg. the filename that | ||
@@ -157,4 +161,3 @@ was opened). Used to generate Error messages | ||
- `format` -- String name of format to use, valid options are `pem`, `rfc4253`, | ||
`ssh` | ||
- `format` -- String name of format to use, for valid options see `parseKey()` | ||
@@ -195,3 +198,3 @@ ### `Key#toString([format = 'ssh])` | ||
### `parsePrivateKey(data[, format = 'pem'[, name]])` | ||
### `parsePrivateKey(data[, format = 'auto'[, name]])` | ||
@@ -204,5 +207,9 @@ Parses a private key from a given data format and returns a new | ||
- `data` -- Either a Buffer or String, containing the key | ||
- `format` -- String name of format to use, valid options are `pem` (supports | ||
both PKCS#1 and PKCS#8), `rfc4253` (raw OpenSSH wire format, as | ||
returned by `ssh-agent`, for example), `pkcs1`, `pkcs8` | ||
- `format` -- String name of format to use, valid options are: | ||
- `auto`: choose automatically from all below | ||
- `pem`: supports both PKCS#1 and PKCS#8 | ||
- `ssh`, `openssh`: new post-OpenSSH 6.5 internal format, produced by | ||
`ssh-keygen -o` | ||
- `pkcs1`, `pkcs8`: variants of `pem` | ||
- `rfc4253`: raw OpenSSH wire format | ||
- `name` -- Optional name for the key being parsed (eg. the filename that | ||
@@ -233,4 +240,5 @@ was opened). Used to generate Error messages | ||
- `format` -- String name of format to use, valid options are `pkcs8`, `pkcs1`, | ||
`rfc4253`, `pem` (same as `pkcs1`) | ||
- `format` -- String name of format to use, valid options are listed under | ||
`parsePrivateKey`. Note that ED25519 keys default to `openssh` | ||
format instead (as they have no `pkcs1` representation). | ||
@@ -237,0 +245,0 @@ ### `PrivateKey#toString([format = 'pkcs1'])` |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
2133
378
0
0
78247
5
22
+ Addeddashdash@>=1.10.1 <2.0.0
+ Addedassert-plus@1.0.0(transitive)
+ Addeddashdash@1.14.1(transitive)