]> git.proxmox.com Git - mirror_acme.sh.git/commitdiff
minor: add _hmac function
authorneilpang <github@byneil.com>
Tue, 8 Nov 2016 13:27:39 +0000 (21:27 +0800)
committerneilpang <github@byneil.com>
Tue, 8 Nov 2016 13:27:39 +0000 (21:27 +0800)
acme.sh

diff --git a/acme.sh b/acme.sh
index e077d2e630d0dfc8b9bc16d662da171212c00d57..c52ce70cb4f762eea41f81ad412d459a17d4a5ba 100755 (executable)
--- a/acme.sh
+++ b/acme.sh
@@ -436,6 +436,31 @@ _digest() {
 
 }
 
+#Usage: hashalg  secret  [outputhex]
+#Output Base64-encoded hmac
+_hmac() {
+  alg="$1"
+  hmac_sec="$2"
+  outputhex="$3"
+  
+  if [ -z "$hmac_sec" ] ; then
+    _usage "Usage: _hmac hashalg secret [outputhex]" 
+    return 1
+  fi
+
+  if [ "$alg" = "sha256" ] || [ "$alg" = "sha1" ]; then
+    if [ "$outputhex" ] ; then
+      openssl dgst -$alg -hmac "$hmac_sec" | cut -d = -f 2 | tr -d ' '
+    else
+      openssl dgst -$alg -hmac "$hmac_sec" -binary | _base64
+    fi
+  else
+    _err "$alg is not supported yet"
+    return 1
+  fi
+
+}
+
 #Usage: keyfile hashalg
 #Output: Base64-encoded signature value
 _sign() {