http-signature
Advanced tools
Comparing version 0.9.3 to 0.9.4
@@ -21,2 +21,3 @@ // Copyright 2011 Joyent, Inc. All rights reserved. | ||
sshKeyToPEM: util.sshKeyToPEM, | ||
sshKeyFingerprint: util.fingerprint, | ||
@@ -23,0 +24,0 @@ verify: verify.verifySignature, |
// Copyright 2011 Joyent, Inc. All rights reserved. | ||
var crypto = require('crypto'); | ||
var asn1 = require('asn1'); | ||
@@ -126,2 +128,36 @@ var ctype = require('ctype'); | ||
return '-----BEGIN PUBLIC KEY-----' + newKey + '-----END PUBLIC KEY-----\n'; | ||
}, | ||
/** | ||
* Generates an OpenSSH fingerprint from an ssh public key. | ||
* | ||
* @param {String} key an OpenSSH public key. | ||
* @return {String} key fingerprint. | ||
* @throws {TypeError} on bad input. | ||
* @throws {Error} if what you passed doesn't look like an ssh public key. | ||
*/ | ||
fingerprint: function(key) { | ||
if (!key || typeof(key) !== 'string') | ||
throw new TypeError('ssh_key (string) required'); | ||
var pieces = key.split(' '); | ||
if (!pieces || !pieces.length || pieces.length < 2) | ||
throw new Error('invalid ssh key'); | ||
var data = new Buffer(pieces[1], 'base64'); | ||
var hash = crypto.createHash('md5'); | ||
hash.update(data); | ||
var digest = hash.digest('hex'); | ||
var fp = ''; | ||
for (var i = 0; i < digest.length; i++) { | ||
if (i && i % 2 === 0) | ||
fp += ':'; | ||
fp += digest[i]; | ||
} | ||
return fp; | ||
} | ||
@@ -128,0 +164,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "Reference implementation of Joyent's HTTP Signature Scheme", | ||
"version": "0.9.3", | ||
"version": "0.9.4", | ||
"homepage": "http://www.joyent.com", | ||
@@ -22,3 +22,3 @@ "repository": { | ||
"asn1": "0.1.5", | ||
"ctype": "0.0.3", | ||
"ctype": "0.1.0", | ||
"sprintf": "0.1.1" | ||
@@ -25,0 +25,0 @@ }, |
@@ -5,2 +5,3 @@ // Copyright 2011 Joyent, Inc. All rights reserved. | ||
var sshKeyFingerprint = require('../lib/index').sshKeyFingerprint; | ||
var sshKeyToPEM = require('../lib/index').sshKeyToPEM; | ||
@@ -84,1 +85,8 @@ | ||
}); | ||
test('fingerprint', function(t) { | ||
var fp = sshKeyFingerprint(SSH_1024); | ||
t.equal(fp, '59:a4:61:0e:38:18:9f:0f:28:58:2a:27:f7:65:c5:87'); | ||
t.end(); | ||
}); |
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
52648
1237
+ Addedctype@0.1.0(transitive)
- Removedctype@0.0.3(transitive)
Updatedctype@0.1.0