Skip to content

Commit 2ab4f2a

Browse files
author
Alex Wilson
committed
#56 md5 fingerprints not quite right
Reviewed by: Cody Peter Mello <[email protected]>
1 parent 026ef47 commit 2ab4f2a

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

lib/fingerprint.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,17 @@ Fingerprint.parse = function (fp, options) {
9999
alg = 'md5';
100100
if (parts[0].toLowerCase() === 'md5')
101101
parts = parts.slice(1);
102+
parts = parts.map(function (p) {
103+
while (p.length < 2)
104+
p = '0' + p;
105+
if (p.length > 2)
106+
throw (new FingerprintFormatError(fp));
107+
return (p);
108+
});
102109
parts = parts.join('');
103110
/*JSSTYLED*/
104111
var md5RE = /^[a-fA-F0-9]+$/;
105-
if (!md5RE.test(parts) || md5RE.length % 2 !== 0)
112+
if (!md5RE.test(parts) || parts.length % 2 !== 0)
106113
throw (new FingerprintFormatError(fp));
107114
try {
108115
hash = Buffer.from(parts, 'hex');

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sshpk",
3-
"version": "1.15.0",
3+
"version": "1.15.1",
44
"description": "A library for finding and using SSH public keys",
55
"main": "lib/index.js",
66
"scripts": {

test/fingerprint.js

+16
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ test('fingerprint matches', function(t) {
8484
'SHA256:PYC9kPVC6J873CSIbfp0LwYeczP/W4ffObNCuDJ1u5w');
8585
t.ok(f.matches(k2));
8686
t.ok(!f.matches(k1));
87+
var f2 = sshpk.parseFingerprint(
88+
'59:a4:61:0e:38:18:9f:0f:28:58:2a:27:f7:65:c5:87');
89+
t.ok(f2.matches(k1));
90+
t.ok(!f2.matches(k2));
91+
var f3 = sshpk.parseFingerprint(
92+
'MD5:59:a4:61:e:38:18:9f:f:28:58:2a:27:f7:65:c5:87');
93+
t.ok(f3.matches(k1));
94+
t.ok(!f3.matches(k2));
95+
var f4 = sshpk.parseFingerprint(
96+
'SHA1:3JP2y/wCv8KnvAunLz7EjcEhKeE');
97+
t.ok(f4.matches(k1));
98+
t.ok(!f4.matches(k2));
8799
t.end();
88100
});
89101

@@ -118,5 +130,9 @@ test('invalid fingerprints', function(t) {
118130
var fp = sshpk.parseFingerprint(
119131
'59:a4:61:0e:38:18:9f:0f:28:58:2a:27:f7:65:c5:878');
120132
}, sshpk.FingerprintFormatError);
133+
t.throws(function () {
134+
var fp = sshpk.parseFingerprint(
135+
'59:a46:1:0e:38:18:9f:0f:28:58:2a:27:f7:65:c5:87');
136+
}, sshpk.FingerprintFormatError);
121137
t.end();
122138
});

0 commit comments

Comments
 (0)