Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

digest is nil on Mac OSX #2

Closed
rohitjoshi opened this issue Nov 10, 2015 · 2 comments
Closed

digest is nil on Mac OSX #2

rohitjoshi opened this issue Nov 10, 2015 · 2 comments

Comments

@rohitjoshi
Copy link

Hello,
I am using lua-resty-hmac as part of lua-resty-jwt but signature is always empty. It seems hmac is returning nil digest. but if I use resty.string sha1 algorithm, it works fine.

Below is my nginx/openresty version

/opt/openresty/bin/resty -V
resty 0.03
nginx version:nginx/1.9.3.1
built by clang 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
built with OpenSSL 0.9.8zd 8 Jan 2015
TLS SNI support enabled
configure arguments: --prefix=/opt/openresty/nginx --with-cc-opt='-O2 -I/usr/local/include' --add-    module=../ngx_devel_kit-0.2.19 --add-module=../echo-nginx-module-0.58 --add-module=../xss-nginx-    module-0.05 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.29 --add-    module=../form-input-nginx-module-0.11 --add-module=../encrypted-session-nginx-module-0.04 --add-module=../srcache-nginx-module-0.30 --add-module=../ngx_lua-0.9.16 --add-module=../ngx_lua_upstream-0.03 --add-module=../headers-more-nginx-module-0.26 --add-module=../array-var-nginx-module-0.04 --add-module=../memc-nginx-module-0.16 --add-module=../redis2-nginx-module-0.12 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.14 --add-module=../rds-csv-nginx-module-0.06 --with-ld-opt='-Wl,-rpath,/opt/openresty/luajit/lib -L/usr/local/lib' --with-http_ssl_module

resty.hmac

 local hmac = require "resty.hmac"
  local str = require "resty.string"

 local hmac_sha1 = hmac:new("secret_key", hmac.ALGOS.SHA1)
 if not hmac_sha1 then
   ngx.say("failed to create the hmac_sha1 object")
   return
end
local ok = hmac_sha1:update("hello ")
if not ok then
   ngx.say("Failed to update str")
   return
end
local digest = hmac_sha1:final("world",true)
ngx.say("hmac_sha1: ", digest)

resty.string sha1

local resty_sha1 = require "resty.sha1"
 local str = require "resty.string"
 local sha1 = resty_sha1:new()
 if not sha1 then
     ngx.say("failed to get sha1 object")
    return
  end

local ok = sha1:update("hello word")
if not ok then
   ngx.say("Failed to update str")
   return
end
local digest = sha1:final()  -- binary digest
ngx.say("sha1: ", str.to_hex(digest)) 
@jkeys089
Copy link
Owner

OpenSSL 1.x+ is a prerequisite for lua-resty-hmac. This is a common issue I've seen when developing on OSX (see the comments on this PR for help using a more recent version of OpenSSL on OSX).

@rohitjoshi
Copy link
Author

thanks for details. will try with updated version of openssl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants