Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uD6eI-006XmM-UU for pgsql-hackers@arkaria.postgresql.org; Thu, 08 May 2025 19:11:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uD6eH-005qDt-SU for pgsql-hackers@arkaria.postgresql.org; Thu, 08 May 2025 19:11:13 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uD6eH-005q5Y-FA for pgsql-hackers@lists.postgresql.org; Thu, 08 May 2025 19:11:13 +0000 Received: from meesny.iki.fi ([195.140.195.201]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uD6eE-000ohp-0c for pgsql-hackers@postgresql.org; Thu, 08 May 2025 19:11:12 +0000 Received: from [192.168.1.112] (iptv-hkibng21-58c090-167.dhcp.inet.fi [88.192.144.167]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by meesny.iki.fi (Postfix) with ESMTPSA id 4ZthYm0PmFzyQB; Thu, 8 May 2025 22:11:07 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1746731468; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Yvqp/8c55SerzNuUZ8rxuE1thx/s3vLTxVGKnU++ayQ=; b=PeI3zPAgdgnj3Hyyj6MoxK7EIQ/d8MSMUQV/2zH2XS4XriSxgFyvZdyC5UIyWhS14s2oTr OAJNWg1clKTQB6PNkvtf77MZC4mQmtCnjPa9YnfZIz84trgBAX7e3f2ei9qqvUShfqJ0NE eeXEY+TTCUezfVGFRwhRSFxiU7BvCQ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1746731468; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Yvqp/8c55SerzNuUZ8rxuE1thx/s3vLTxVGKnU++ayQ=; b=e8y8Uoer3Korzrbl9XMPUV0RNW9Jd6JJnSQZ4+DPiJD7c52wzMjouQnmJhMCHwrlqrEhv0 S4qJJJ3soFshonyQ4Jh0aKz9w6ns1E3UWWQV45u+DQYqMrn4PulMjwGhzI85DToycaXWee aq5kKfdwiSbS1AzpZZX7vyjCQ2sarok= ARC-Seal: i=1; s=meesny; d=iki.fi; t=1746731468; a=rsa-sha256; cv=none; b=D4/AeF4wVgJPt5iNiX127U2IYhBzraFbpSIoNqH+ISbDjzP2RM/W6c0wbMOv3R91RYd6Ok xThZMA7+sbTARZ4uNpuc7f3NthTABvWbD/2WQNNio4hP7FxhBNCglJtN8mwTLDzBjy286d VwvYpIzoEZLuugTWcfWn0kCxdiKZ7SE= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi Message-ID: <52d648b1-9aca-43d1-a9e4-a6a556410f41@iki.fi> Date: Thu, 8 May 2025 22:11:07 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: pgsql: Make cancel request keys longer From: Heikki Linnakangas To: Peter Eisentraut , "pgsql-hackers@postgresql.org" References: <61be9e31-7b7d-49d5-bc11-721800d89d64@eisentraut.org> <09323e6a-4743-4be2-9d7f-74b86e4dac64@iki.fi> <34d5d731-06cc-43af-88cd-b3a4c5c8d9df@iki.fi> <2afbd9c6-51b7-450f-9ae1-61e552368963@eisentraut.org> <4bd8421a-50ad-4169-a096-99247c2f563c@iki.fi> <9399dc5d-5575-483e-8e23-af6be79385c8@iki.fi> Content-Language: en-US In-Reply-To: <9399dc5d-5575-483e-8e23-af6be79385c8@iki.fi> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 09/04/2025 13:46, Heikki Linnakangas wrote: > On 09/04/2025 13:28, Heikki Linnakangas wrote: >> On 09/04/2025 12:39, Peter Eisentraut wrote: >>> On 09.04.25 10:53, Heikki Linnakangas wrote: >>>> On 08/04/2025 22:41, Heikki Linnakangas wrote: >>>>> On 08/04/2025 20:06, Peter Eisentraut wrote: >>>>>> While I was looking at this, I suggest to make the first argument >>>>>> void *.  This is consistent for passing binary data. >>>>> >>>>> Ok, sure. >>>> >>>> On second thoughts, -1 on that. 'void *' is appropriate for >>>> functions like libc's read() or pq_sendbytes(), where the buffer can >>>> point to anything. In other words, the caller is expected to have a >>>> pointer like 'foobar *', and it gets cast to 'void *' when you call >>>> the function. That's not the case with the cancellation key. The >>>> cancellation key is just an array of bytes, the caller is expected >>>> to pass an array of bytes, not a struct. >>>> >>>> The right precedent for that are e.g. SCRAM functions in scram- >>>> common.h, for example. They use "const uint8 *" for the hashes. >>>> >>>> I'll switch to "const uint *" everywhere that deals with cancel >>>> keys. There are a few more variables elsewhere in the backend and in >>>> libpq. >>> >>> I was having the same second thoughts overnight.  I agree with your >>> conclusion. >> >> Here's a patch to change cancellation keys to "uint8 *". I did the >> same for a few other places, namely the new scram_client_key_binary >> and scram_server_key_binary fields in pg_conn, and a few libpq >> functions that started to give compiler warnings after that. There >> probably would be more code that could be changed to follow this >> convention, but I didn't look hard. What do you think? >> >> I'm on the edge with the pg_b64_encode/decode functions, whether they >> should work on "uint8 *" or "void *". On one hand, you do base64 >> encoding on a byte array, which would support "uint8 *". But on the >> other hand, you might use it for encoding things with more structure, >> which would support "void *". I went with "void *", mostly out of >> convenience as many of the SCRAM functions that currently use >> pg_b64_encode/decode, use "char *" to represent byte arrays. But >> arguably those should be changed to use "uint8 *" too. > > I went around looking a bit more anyway. Here's a patch to change more > places to use 'uint8' for byte arrays, in SCRAM and MD5 salts and > digests and such. It's a bit of code churn, but I think it improves > readability. Especially the SCRAM code sometimes deals with base64- > encoded string representations of digests and sometimes with decoded > byte arrays, and it's helpful to use different datatypes for them. Polished this up a tiny bit, and committed. -- Heikki Linnakangas Neon (https://neon.tech)