<div dir="ltr"><div dir="ltr">Dear Francesco,</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Oct 24, 2020 at 1:06 PM Francesco Pretto <<a href="mailto:ceztko@gmail.com">ceztko@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello,<br>
<br>
I'm trying to create a CMS context for subsequent export using<br>
CMS_sign(). I add a signer using CMS_add1_signer() that allows me to<br>
specify a X509 certificate and a hash function. I would like the CMS<br>
context to perform hash computation and ANS1 structure filling, but I<br>
want to delegate encryption to an external service, for example an<br>
hardware encryption token (I'm assuming this is a very common use<br>
case). At this point I'm in a stalemate since CMS_add1_signer() asks<br>
me for a private EVP_PKEY that is compatible with the public key<br>
present in the X509 certificate. No other function seems to exist to<br>
create a CMS_SignerInfo by providing an external mechanism for<br>
encryption.<br>
<br>
My hacky solution was to add a signer CMS_add1_signer() supplying the<br>
public key stored in the X509 certificate in the place of the private<br>
one. This passes internal checks of the function and allows me to<br>
subsequently handle (manually) all the ANS1 structure filling and hash<br>
computations. This is barely doable with public openssl API and still<br>
requires a big rip-off of private openssl code (attached as a<br>
standalone C++ class, if it can be useful for someone).<br>
<br>
My question is: is there an easier mechanism to plug a separate<br>
encryption method when creating the CMS_SignerInfo structure and have<br>
openssl do all the other dirty work for me? If so, is it possible to<br>
do with openssl 1.1.0/1.1.1?<br></blockquote><div><br></div><div>Engines allow operating by private keys in such a manner. </div><div>You have to reimplement all the callbacks dealing with private keys. Also, it's possible you have to write some wrappers for the functions dealing with public keys.</div><div><br></div><div>For 3.0, the providers should do the same trick, I think.<br><br></div></div>-- <br><div dir="ltr" class="gmail_signature">SY, Dmitry Belyavsky</div></div>