Skip to content

Commit

Permalink
fix digest mapping for scram auth
Browse files Browse the repository at this point in the history
  • Loading branch information
fffonion committed Jun 29, 2023
1 parent 7b7ef2a commit 0766862
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions pgmoon/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,13 @@ do
pem, signature = server_cert:pem(), server_cert:getsignaturename()
end
signature = signature:lower()
local _, with_sig
_, _, with_sig = signature:find("%-with%-(.*)")
if with_sig then
signature = with_sig
end
if signature:match("^md5") or signature:match("^sha1") or signature:match("sha1$") then
signature = "sha256"
else
local objects = require("resty.openssl.objects")
local sigid = assert(objects.txt2nid(signature))
local digest_nid = assert(objects.find_sigid_algs(sigid))
signature = assert(objects.nid2table(digest_nid).sn)
end
cbind_data = assert(x509_digest(pem, signature))
end
Expand Down
10 changes: 5 additions & 5 deletions pgmoon/init.moon
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,14 @@ class Postgres

signature = signature\lower!

-- Handle the case when the signature is e.g. ECDSA-with-SHA384
_, _, with_sig = signature\find("%-with%-(.*)")
if with_sig
signature = with_sig

-- upgrade the signature if necessary (also handle the case of s/RSA-SHA1/sha256)
if signature\match("^md5") or signature\match("^sha1") or signature\match("sha1$")
signature = "sha256"
else
objects = require "resty.openssl.objects"
sigid = assert objects.txt2nid(signature)
digest_nid = assert objects.find_sigid_algs(sigid)
signature = assert objects.nid2table(digest_nid).sn

assert x509_digest(pem, signature)

Expand Down

0 comments on commit 0766862

Please sign in to comment.