Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hIhdX-0000U7-VT for pgsql-bugs@arkaria.postgresql.org; Mon, 22 Apr 2019 22:42:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hIhdW-00063A-OO for pgsql-bugs@arkaria.postgresql.org; Mon, 22 Apr 2019 22:42:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hIhdW-00062g-9b for pgsql-bugs@lists.postgresql.org; Mon, 22 Apr 2019 22:42:06 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hIhdT-0003DP-Jl for pgsql-bugs@lists.postgresql.org; Mon, 22 Apr 2019 22:42:04 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x3MMg1sE030285; Mon, 22 Apr 2019 18:42:01 -0400 From: Tom Lane To: "Jonathan S. Katz" cc: Michael Paquier , pgsql-bugs@lists.postgresql.org, Stephen Frost Subject: Re: Possible to store invalid SCRAM-SHA-256 Passwords In-reply-to: <5a93333c-dde6-ee52-f870-4dccfc50eb6f@postgresql.org> References: <016deb6b-1f0a-8e9f-1833-a8675b170aa9@postgresql.org> <4240a41f-a957-fd7d-7c24-31683f259b9d@postgresql.org> <20190422015051.GA3433@paquier.xyz> <3033.1555940554@sss.pgh.pa.us> <5a93333c-dde6-ee52-f870-4dccfc50eb6f@postgresql.org> Comments: In-reply-to "Jonathan S. Katz" message dated "Mon, 22 Apr 2019 18:32:45 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <30283.1555972921.1@sss.pgh.pa.us> Date: Mon, 22 Apr 2019 18:42:01 -0400 Message-ID: <30284.1555972921@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "Jonathan S. Katz" writes: > OK, so I have something that sort of works, i.e: > if (strncmp(shadow_pass, "md5", 3) == 0 && > strlen(shadow_pass) == MD5_PASSWD_LEN && > strspn(shadow_pass, MD5_PASSWD_CHARSET) == MD5_PASSWD_LEN > ) > where MD5_PASSWD_CHARSET = "mabcdef0123456789" > ...but you may notice something: the CHARSET contains an "m" as we store > that "md5" prefix on the md5 hashed passwords. Yeah, that's silly; why not strspn(shadow_pass + 3, MD5_PASSWD_CHARSET) == MD5_PASSWD_LEN - 3 It's not like this code isn't very well aware of the first 3 characters being not like the others. regards, tom lane