Skip to content

Commit 0766862

Browse files
committed
fix digest mapping for scram auth
1 parent 7b7ef2a commit 0766862

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

pgmoon/init.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,13 @@ do
402402
pem, signature = server_cert:pem(), server_cert:getsignaturename()
403403
end
404404
signature = signature:lower()
405-
local _, with_sig
406-
_, _, with_sig = signature:find("%-with%-(.*)")
407-
if with_sig then
408-
signature = with_sig
409-
end
410405
if signature:match("^md5") or signature:match("^sha1") or signature:match("sha1$") then
411406
signature = "sha256"
407+
else
408+
local objects = require("resty.openssl.objects")
409+
local sigid = assert(objects.txt2nid(signature))
410+
local digest_nid = assert(objects.find_sigid_algs(sigid))
411+
signature = assert(objects.nid2table(digest_nid).sn)
412412
end
413413
cbind_data = assert(x509_digest(pem, signature))
414414
end

pgmoon/init.moon

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,14 +406,14 @@ class Postgres
406406

407407
signature = signature\lower!
408408

409-
-- Handle the case when the signature is e.g. ECDSA-with-SHA384
410-
_, _, with_sig = signature\find("%-with%-(.*)")
411-
if with_sig
412-
signature = with_sig
413-
414409
-- upgrade the signature if necessary (also handle the case of s/RSA-SHA1/sha256)
415410
if signature\match("^md5") or signature\match("^sha1") or signature\match("sha1$")
416411
signature = "sha256"
412+
else
413+
objects = require "resty.openssl.objects"
414+
sigid = assert objects.txt2nid(signature)
415+
digest_nid = assert objects.find_sigid_algs(sigid)
416+
signature = assert objects.nid2table(digest_nid).sn
417417

418418
assert x509_digest(pem, signature)
419419

0 commit comments

Comments
 (0)