-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds sha1 support for basic auth configuration (issue Kong#33)
- Loading branch information
Yahel Bahat
committed
Sep 2, 2015
1 parent
a23185c
commit 920b45a
Showing
4 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
return { | ||
no_consumer = true, | ||
fields = { | ||
hide_credentials = { type = "boolean", default = false } | ||
hide_credentials = { type = "boolean", default = false }, | ||
encryption_method = { type = "string", default = 'plain' }, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
local resty_string = require "resty.string" | ||
local resty_sha1 = require "resty.sha1" | ||
|
||
local string_format = string.format | ||
|
||
_M = {} | ||
|
||
-- sha1 — Calculate the sha1 hash of a string | ||
-- @param `string` input string. | ||
-- @return `string` the sha1 of the given string. | ||
function _M.sha1(string) | ||
local sha1 = resty_sha1:new() | ||
if not sha1 then | ||
return nil, "failed to create the sha1 object" | ||
end | ||
|
||
local ok = sha1:update(string) | ||
if not ok then | ||
return nil, "failed to add data" | ||
end | ||
|
||
local digest = sha1:final() -- binary digest | ||
return resty_string.to_hex(digest) | ||
end | ||
|
||
function _M.salt_credentials(credential) | ||
return string_format("%s:%s", credential.password, credential.consumer_id) | ||
end | ||
|
||
-- transformation table for all supported encryption mathods. | ||
_M.encryption_methods = { | ||
plain = function(credential) return credential.password end, | ||
sha1 = function(credential) | ||
local password_salted = _M.salt_credentials(credential) | ||
ngx.log(ngx.ERR, "Dalted: ", password_salted) | ||
return _M.sha1(password_salted) | ||
end, | ||
} | ||
|
||
return _M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters