Re: [5/7] relayd: use imsg_get_ibuf() for variable-length CA key operations

Claudio Jeker <[email protected]>
Newsgroups gmane.os.openbsd.tech
Message-ID <[email protected]>
On Wed, Jun 10, 2026 at 10:04:34AM +0200, Rafael Sadowski wrote:
> On Mon Jun 08, 2026 at 03:41:54PM +0200, Claudio Jeker wrote:
> > >  
> > > -		from = (u_char *)imsg->data + sizeof(cko);
> > > +		from = ibuf_data(&ibuf);
> > 
> > I think this needs again a second refactor that kills from and just uses
> > the ibuf in the right place. Ok this calls into libssl functions but this
> > all looks not very safe to me.
> 
>  It took me a while to figure out exactly what you wanted. I checked
>  smtpd, and it's also points in the imsg. However, I think this is OK here.
>  I changed like this (Full diff below).
> 
>  		case IMSG_CA_PRIVENC:
>  			cko.cko_tlen = RSA_private_encrypt(cko.cko_flen,
> -			    from, to, rsa, cko.cko_padding);
> +			    ibuf_data(&ibuf), to, rsa, cko.cko_padding);
>  			break;
>  		case IMSG_CA_PRIVDEC:
>  			cko.cko_tlen = RSA_private_decrypt(cko.cko_flen,
> -			    from, to, rsa, cko.cko_padding);
> +			    ibuf_data(&ibuf), to, rsa, cko.cko_padding);
>  			break;

I would prefer if instead of cko.cko_flen in those functions we used
ibuf_size(&ibuf).

It is the same because before we have this check:
		if (ibuf_size(&ibuf) != (size_t)cko.cko_flen)
  			fatalx("%s: invalid key operation", __func__);
but I find
  			cko.cko_tlen = RSA_private_encrypt(ibuf_size(&ibuf),
			    ibuf_data(&ibuf), to, rsa, cko.cko_padding);
clearer to know that both size and data of the ibuf are respected.

Now since both are equivalent you can also go on with your version. 

-- 
:wq Claudio
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.