{"id":13636260,"url":"https://github.com/jamesmarlowe/lua-resty-hmac","last_synced_at":"2025-04-09T11:31:33.296Z","repository":{"id":15152100,"uuid":"17879615","full_name":"jamesmarlowe/lua-resty-hmac","owner":"jamesmarlowe","description":"Lua driver for making and receiving hmac signed requests","archived":false,"fork":false,"pushed_at":"2022-05-09T07:06:21.000Z","size":19,"stargazers_count":41,"open_issues_count":5,"forks_count":14,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-02-14T13:30:52.161Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jamesmarlowe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-18T19:46:19.000Z","updated_at":"2023-04-12T07:21:02.000Z","dependencies_parsed_at":"2022-08-29T01:30:32.618Z","dependency_job_id":null,"html_url":"https://github.com/jamesmarlowe/lua-resty-hmac","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesmarlowe%2Flua-resty-hmac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesmarlowe%2Flua-resty-hmac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesmarlowe%2Flua-resty-hmac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesmarlowe%2Flua-resty-hmac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamesmarlowe","download_url":"https://codeload.github.com/jamesmarlowe/lua-resty-hmac/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248031444,"owners_count":21036396,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T00:00:59.173Z","updated_at":"2025-04-09T11:31:32.252Z","avatar_url":"https://github.com/jamesmarlowe.png","language":"Lua","funding_links":[],"categories":["Libraries","Lua"],"sub_categories":[],"readme":"Name\n====\n\nlua-resty-hmac - Lua library for making and receiving hmac signed requests\n\nTable of Contents\n=================\n\n* [Name](#name)\n* [Status](#status)\n* [Description](#description)\n* [Synopsis](#synopsis)\n* [Methods](#methods)\n    * [new](#new)\n    * [generate_signature](#generate_signature)\n    * [check_signature](#check_signature)\n    * [generate_headers](#generate_headers)\n    * [check_headers](#check_headers)\n* [Limitations](#limitations)\n* [Installation](#installation)\n* [TODO](#todo)\n* [Community](#community)\n    * [English Mailing List](#english-mailing-list)\n    * [Chinese Mailing List](#chinese-mailing-list)\n* [Testing](#testing)\n* [Bugs and Patches](#bugs-and-patches)\n* [Author](#author)\n* [Copyright and License](#copyright-and-license)\n* [See Also](#see-also)\n\nStatus\n======\n\nThis library is still under early development and considered experimental.\n\nDescription\n===========\n\nThis Lua library is a hmac utility for the ngx_lua nginx module:\n\nSynopsis\n========\n\n```lua\n    lua_package_path \"/path/to/lua-resty-hmac/lib/?.lua;;\";\n\n    server {\n        location /test {\n            content_by_lua '\n                local hmac = require \"resty.hmac\"\n                local hm, err = hmac:new(\"SigningKey\")\n                \n                local date = os.date(\"!%a, %d %b %Y %H:%M:%S +0000\")\n                local destination = \"/path/to/new/file.txt\"\n                local StringToSign = \"PUT\"..string.char(10)..string.char(10)..string.char(10)..date..string.char(10)..destination\n                \n                local headers, err = hm:generate_headers(\"AWS\", \"AccessKeyId\", \"sha1\", StringToSign)\n                \n                if headers then\n                    ngx.say(\"headers generated\")\n                else\n                    ngx.say(err)\n                end\n                \n                res = ngx.location.capture(\n                    \"/upload/to/s3/\",\n                    { method = ngx.HTTP_PUT, body = \"Test Upload Content\",\n                      args = {date = headers.date, auth = headers.auth, file = destination}}\n                )\n                \n                if res.status == 200 then\n                    ngx.say(\"uploaded successfully\")\n                else\n                    ngx.say(\"upload failed\")\n                end\n            ';\n        }\n        \n        location /upload/to/s3/ {\n            internal;\n            resolver 8.8.8.8;\n            set_unescape_uri $date $arg_date;\n            set_unescape_uri $auth $arg_auth;\n            set_unescape_uri $file $arg_file;\n\n            proxy_pass_request_headers off;\n            more_clear_headers 'Host';\n            more_clear_headers 'Connection';\n            more_clear_headers 'Content-Length';\n            more_clear_headers 'User-Agent';\n            more_clear_headers 'Accept';\n\n            proxy_set_header Date $date;\n            proxy_set_header Authorization $auth;\n            proxy_set_header content-type '';\n            proxy_set_header Content-MD5 '';\n\n            proxy_pass http://s3.amazonaws.com$file;\n        }\n    }\n```\n\n[Back to TOC](#table-of-contents)\n\nMethods\n=======\n\nAll of the commands return either something that evaluates to true on success, or `nil` and an error message on failure.\n\nnew\n---\n`syntax: hm, err = hmac:new(\"SigningKey\")`\n\nCreates a signing object. In case of failures, returns `nil` and a string describing the error.\n\n[Back to TOC](#table-of-contents)\n\ngenerate_signature\n------------------\n`syntax: sig, err = hm:generate_signature(dtype, message, delimiter)`\n\n`syntax: sig, err = hm:generate_signature(\"sha1\", \"StringToSign\")`\n\nAttempts to sign a message using the algorithm set by dtype and the key set with new(). It can also be called using a table as the message with a delimiter used when concatenating the arguments which defaults to a newline (char 10).\n\n```\nlocal args = {\"PUT\",\"/path/to/file/\",\"Wed, 19 Mar 2014 21:45:06 +0000\"}\nlocal sig, err = hm:generate_signature(\"sha1\", args)\n```\n\nIn case of success, returns the signature. In case of errors, returns `nil` with a string describing the error.\n\n[Back to TOC](#table-of-contents)\n\ncheck_signature\n------------------\n`syntax: ok, err = hm:check_signature(dtype, message, delimiter, signature)`\n\n`syntax: ok, err = hm:check_signature(\"sha1\", \"StringToSign\", nil, \"bo1h3498v3\")`\n\nAttempts to sign a message and compare it with a precomputed signature.\n\n```\nlocal args = {\"PUT\",\"/path/to/file/\",\"Wed, 19 Mar 2014 21:45:06 +0000\"}\nlocal ok, err = hm:check_signature(\"sha1\", args, nil, \"bo1h3498v3\")\n```\n\nIn case of success, returns `true`. In case of errors, returns `false` with a string describing the error.\n\n[Back to TOC](#table-of-contents)\n\ngenerate_headers\n------------------\n`syntax: headers, err = hm:generate_headers(service, id, dtype, message, delimiter)`\n\n`syntax: headers, err = hm:generate_headers(\"AWS\", \"AccessKeyId\", \"sha1\", \"StringToSign\")`\n\nAttempts to generate the date and an authentication string for use in an auth header.\n\nIn case of success, returns a table `{date = date, auth = auth}`. In case of errors, returns `nil` with a string describing the error.\n\n[Back to TOC](#table-of-contents)\n\ncheck_headers\n------------------\n`syntax: ok, err = hm:check_headers(service, id, dtype, message, delimiter, max_time_diff)`\n\n`syntax: ok, err = hm:check_headers(\"AWS\", \"AccessKeyId\", \"sha1\", \"StringToSign\")`\n\nAttempts to sign a message and compare request headers to computed headers.\n\nIn case of success, returns `true`. In case of errors, returns `nil` with a string describing the error.\n\n[Back to TOC](#table-of-contents)\n\nLimitations\n===========\n\n* Doesn't support setting which headers to compare against\n\n[Back to TOC](#table-of-contents)\n\nInstallation\n============\nYou can install it with luarocks `luarocks install lua-resty-hmac`\n\nOtherwise you need to configure the lua_package_path directive to add the path of your lua-resty-hmac source tree to ngx_lua's LUA_PATH search path, as in\n\n```nginx\n    # nginx.conf\n    http {\n        lua_package_path \"/path/to/lua-resty-hmac/lib/?.lua;;\";\n        ...\n    }\n```\n\nThis package also requires the luacrypto package to be installed http://luarocks.org/repositories/rocks/#luacrypto\n\nEnsure that the system account running your Nginx ''worker'' proceses have\nenough permission to read the `.lua` file.\n\nDocker\n------\nI've also made a docker image to make setup of the nginx environment easier. View details here: https://registry.hub.docker.com/u/jamesmarlowe/lua-resty-hmac/\n```\n# install docker according to http://docs.docker.com/installation/\n\n# pull image\nsudo docker pull jamesmarlowe/lua-resty-hmac\n\n# make sure it is there\nsudo docker images\n\n# run the image\nsudo docker run -t -i jamesmarlowe/lua-resty-hmac\n```\n\n[Back to TOC](#table-of-contents)\n\nTODO\n====\n\n[Back to TOC](#table-of-contents)\n\nCommunity\n=========\n\n[Back to TOC](#table-of-contents)\n\nEnglish Mailing List\n--------------------\n\nThe [openresty-en](https://groups.google.com/group/openresty-en) mailing list is for English speakers.\n\n[Back to TOC](#table-of-contents)\n\nChinese Mailing List\n--------------------\n\nThe [openresty](https://groups.google.com/group/openresty) mailing list is for Chinese speakers.\n\n[Back to TOC](#table-of-contents)\n\nTesting\n=======\n\nRunning the tests in t/ is simple once you know whats happening. They use perl's prove and agentzh's test-nginx.\n\n```\nsudo apt-get install perl build-essential curl\nsudo cpan Test::Nginx\nmkdir -p ~/work \ncd ~/work \ngit clone https://github.com/agentzh/test-nginx.git \ncd /path/to/lua-resty-hmac/\nmake test #assumes openresty installed to /usr/bin/openresty/\n```\n\n[Back to TOC](#table-of-contents)\n\nBugs and Patches\n================\n\nPlease report bugs or submit patches by\n\n1. creating a ticket on the [GitHub Issue Tracker](http://github.com/jamesmarlowe/lua-resty-hmac/issues),\n\n[Back to TOC](#table-of-contents)\n\nAuthor\n======\n\nJames Marlowe \"jamesmarlowe\" \u003cjameskmarlowe@gmail.com\u003e, Lumate LLC.\n\n[Back to TOC](#table-of-contents)\n\nCopyright and License\n=====================\n\nThis module is licensed under the BSD license.\n\nCopyright (C) 2012-2014, by James Marlowe (jamesmarlowe) \u003cjameskmarlowe@gmail.com\u003e, Lumate LLC.\n\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n\n* Redistributions of source code must retain the above copyright notice, this\n  list of conditions and the following disclaimer.\n\n* Redistributions in binary form must reproduce the above copyright notice,\n  this list of conditions and the following disclaimer in the documentation\n  and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\nAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\nFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\nDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\nSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\nCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\nOR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n[Back to TOC](#table-of-contents)\n\nSee Also\n========\n* the ngx_lua module: http://wiki.nginx.org/HttpLuaModule\n\n[Back to TOC](#table-of-contents)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesmarlowe%2Flua-resty-hmac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamesmarlowe%2Flua-resty-hmac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesmarlowe%2Flua-resty-hmac/lists"}