Comparing version 1.4.0 to 1.4.1
@@ -18,6 +18,15 @@ // Copyright 2015 Joyent, Inc. | ||
function read(buf) { | ||
if (buf.slice(0, 4).toString('ascii') === '----') | ||
return (pem.read(buf)); | ||
if (buf.slice(0, 4).toString('ascii') === 'ssh-') | ||
return (ssh.read(buf)); | ||
if (typeof (buf) === 'string') { | ||
if (buf.trim().match(/^[-]+[ ]*BEGIN/)) | ||
return (pem.read(buf)); | ||
if (buf.match(/^ssh-[a-z]/)) | ||
return (ssh.read(buf)); | ||
buf = new Buffer(buf, 'binary'); | ||
} else { | ||
assert.buffer(buf); | ||
if (findPEMHeader(buf)) | ||
return (pem.read(buf)); | ||
if (buf.slice(0, 4).toString('ascii') === 'ssh-') | ||
return (ssh.read(buf)); | ||
} | ||
if (buf.readUInt32BE(0) < buf.length) | ||
@@ -28,4 +37,23 @@ return (rfc4253.read(buf)); | ||
function findPEMHeader(buf) { | ||
var offset = 0; | ||
while (offset < buf.length && | ||
(buf[offset] === 32 || buf[offset] === 10)) | ||
++offset; | ||
if (buf[offset] !== 45) | ||
return (false); | ||
while (offset < buf.length && | ||
(buf[offset] === 45)) | ||
++offset; | ||
while (offset < buf.length && | ||
(buf[offset] === 32)) | ||
++offset; | ||
if (offset + 5 > buf.length || | ||
buf.slice(offset, offset + 5).toString('ascii') !== 'BEGIN') | ||
return (false); | ||
return (true); | ||
} | ||
function write(key) { | ||
throw (new Error('"auto" format cannot be used for writing')); | ||
} |
@@ -18,2 +18,3 @@ // Copyright 2015 Joyent, Inc. | ||
var sshpriv = require('./ssh-private'); | ||
var rfc4253 = require('./rfc4253'); | ||
@@ -34,7 +35,7 @@ /* | ||
var m = lines[0].match(/*JSSTYLED*/ | ||
/BEGIN ([A-Z]+ )?(PUBLIC|PRIVATE) KEY/); | ||
/[-]+[ ]*BEGIN ([A-Z0-9]+ )?(PUBLIC|PRIVATE) KEY[ ]*[-]+/); | ||
assert.ok(m, 'invalid PEM header'); | ||
var m2 = lines[lines.length - 2].match(/*JSSTYLED*/ | ||
/END ([A-Z]+ )?(PUBLIC|PRIVATE) KEY/); | ||
/[-]+[ ]*END ([A-Z0-9]+ )?(PUBLIC|PRIVATE) KEY[ ]*[-]+/); | ||
assert.ok(m2, 'invalid PEM footer'); | ||
@@ -78,2 +79,4 @@ | ||
return (sshpriv.readSSHPrivate(type, buf)); | ||
if (alg && alg.toLowerCase() === 'ssh2') | ||
return (rfc4253.readType(type, buf)); | ||
@@ -80,0 +83,0 @@ var der = new asn1.BerReader(buf); |
@@ -74,3 +74,2 @@ // Copyright 2015 Joyent, Inc. | ||
var comment = buf.readString(); | ||
key.comment = comment; | ||
@@ -96,2 +95,6 @@ | ||
privBuf.writeString(key.comment || ''); | ||
var n = 1; | ||
while (privBuf._offset % 8 !== 0) | ||
privBuf.writeChar(n++); | ||
} | ||
@@ -121,3 +124,3 @@ | ||
var tmp = buf.toString('base64'); | ||
var len = tmp.length + (tmp.length / 64) + | ||
var len = tmp.length + (tmp.length / 70) + | ||
18 + 16 + header.length*2 + 10; | ||
@@ -128,3 +131,3 @@ buf = new Buffer(len); | ||
for (var i = 0; i < tmp.length; ) { | ||
var limit = i + 64; | ||
var limit = i + 70; | ||
if (limit > tmp.length) | ||
@@ -131,0 +134,0 @@ limit = tmp.length; |
@@ -22,12 +22,6 @@ // Copyright 2015 Joyent, Inc. | ||
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.trim().replace(/\s+/g, ' ').split(' '); | ||
assert.ok(parts.length === 2 || parts.length === 3, | ||
'invalid extra whitespace within key'); | ||
var parts = buf.split(' '); | ||
assert.ok(parts.length >= 2); | ||
var type = rfc4253.algToKeyType(parts[0]); | ||
@@ -49,3 +43,3 @@ | ||
if (key instanceof PrivateKey) | ||
return (sshpriv.write(key)); | ||
throw (new Error('Private keys are not supported')); | ||
@@ -52,0 +46,0 @@ var parts = []; |
@@ -68,2 +68,4 @@ // Copyright 2015 Joyent, Inc. | ||
}); | ||
if (this.comment) | ||
this._pubCache.comment = this.comment; | ||
return (this._pubCache); | ||
@@ -70,0 +72,0 @@ }; |
{ | ||
"name": "sshpk", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"description": "A library for finding and using SSH public keys", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
79688
2163