summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/request/node_modules/http-signature/node_modules/sshpk/lib/signature.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/request/node_modules/http-signature/node_modules/sshpk/lib/signature.js')
-rw-r--r--deps/npm/node_modules/request/node_modules/http-signature/node_modules/sshpk/lib/signature.js20
1 files changed, 14 insertions, 6 deletions
diff --git a/deps/npm/node_modules/request/node_modules/http-signature/node_modules/sshpk/lib/signature.js b/deps/npm/node_modules/request/node_modules/http-signature/node_modules/sshpk/lib/signature.js
index ddf4a8c988..964f55cb56 100644
--- a/deps/npm/node_modules/request/node_modules/http-signature/node_modules/sshpk/lib/signature.js
+++ b/deps/npm/node_modules/request/node_modules/http-signature/node_modules/sshpk/lib/signature.js
@@ -65,23 +65,31 @@ Signature.prototype.toBuffer = function (format) {
buf = new SSHBuffer({});
buf.writeString('ssh-dss');
r = this.part.r.data;
- if (r[0] === 0x00)
+ if (r.length > 20 && r[0] === 0x00)
r = r.slice(1);
s = this.part.s.data;
+ if (s.length > 20 && s[0] === 0x00)
+ s = s.slice(1);
+ if ((this.hashAlgorithm &&
+ this.hashAlgorithm !== 'sha1') ||
+ r.length + s.length !== 40) {
+ throw (new Error('OpenSSH only supports ' +
+ 'DSA signatures with SHA1 hash'));
+ }
buf.writeBuffer(Buffer.concat([r, s]));
return (buf.toBuffer());
} else if (format === 'ssh' && this.type === 'ecdsa') {
var inner = new SSHBuffer({});
- r = this.part.r;
- if (r[0] === 0x00)
- r = r.slice(1);
- inner.writePart(r);
+ r = this.part.r.data;
+ inner.writeBuffer(r);
inner.writePart(this.part.s);
buf = new SSHBuffer({});
/* XXX: find a more proper way to do this? */
var curve;
- var sz = this.part.r.data.length * 8;
+ if (r[0] === 0x00)
+ r = r.slice(1);
+ var sz = r.length * 8;
if (sz === 256)
curve = 'nistp256';
else if (sz === 384)