From d8556de06e7e4ffda13eb5951f9042bc5e770890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20Fr=C3=B6hle?= Date: Tue, 24 Feb 2015 12:00:43 +0100 Subject: [PATCH] Add hash option to getFingerprint function `getFingerprint(certificate, [hash,] callback)` --- README.md | 5 +++-- lib/pem.js | 11 ++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4e253f88..aecdf41a 100644 --- a/README.md +++ b/README.md @@ -142,13 +142,14 @@ Where ### Get fingerprint -Use `getFingerprint` to get the SHA1 fingerprint for a certificate +Use `getFingerprint` to get the default SHA1 fingerprint for a certificate - pem.getFingerprint(certificate, callback) + pem.getFingerprint(certificate, [hash,] callback) Where * **certificate** is a PEM encoded certificate + * **hash** is a hash function to use (either `md5`, `sha1` or `sha256`, defaults to `sha1`) * **callback** is a callback function with an error object and `{fingerprint}` ### Get modulus diff --git a/lib/pem.js b/lib/pem.js index 528b344e..b4b95bbf 100644 --- a/lib/pem.js +++ b/lib/pem.js @@ -411,12 +411,21 @@ function config(options) { * @param {String} PEM encoded certificate * @param {Function} callback Callback function with an error object and {fingerprint} */ -function getFingerprint(certificate, callback) { +function getFingerprint(certificate, hash, callback) { + + if (!callback && typeof hash === 'function') { + callback = hash; + hash = undefined; + } + + hash = hash || 'sha1'; + var params = ['x509', '-in', '--TMPFILE--', '-fingerprint', '-noout' + '-'+hash ]; spawnWrapper(params, certificate, function(err, code, stdout) {