<div dir="ltr"><div dir="auto">Thank you for the suggestion.<div dir="auto">I am using providers though, not engine, and I can't see the higher level checking this RSA flags before it has detected a valid key is passed back from the store manager to ossl_store_handle_load_result() ( the callback passed to the store mgmt load() method).</div><div>If I don't call the callback ossl_store_handle_load_result the higher level after the store mgmt load() complains no private key can be read. </div><div>If I pass back an RSA key generated on the fly in the store mgmt load() then the ossl_store_handle_load_result() is fine using the RSA key mgmt load finds error in checking RSA flags , I think these flags are not set but I don't know how to set them in the fictitious private key I generated on the fly in the store mgmt load() with </div><div>    EVP_PKEY *pkey = NULL;<br>    pkey = EVP_RSA_gen(2048);<br></div><div>This produces a valid pkey without errors but I think the rsa fields are not filled in.How can I add them to pkey ?</div><div>I think I should register a different keymgmt on my provider but I am not sure what it should do in my case.</div><div>So , for now, the RSA keymgmt is called and in its load() function ( rsa_load() ) at some point it wants to check RSA_check_flags() and there it stops as the rsa struct fileds referenced are not filled in.</div><div><br></div><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 8 Oct 2021, 22:04 Piotr Lobacz, <<a href="mailto:piotr.lobacz@softgent.com" target="_blank">piotr.lobacz@softgent.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">




<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Hi Antonio,</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
I was discussing about this problem about half a year ago in here. The problem was itself in .net library but it <span lang="en"><span><span>concerned
 RSA_FLAG_EXT_PKEY in RSA_METHOD which is wrong. Yo can read it in here <a href="https://github.com/dotnet/runtime/issues/53345" id="gmail-m_-7274699874073980074m_-7837997346193041486LPlnk" rel="noreferrer" target="_blank">https://github.com/dotnet/runtime/issues/53345</a>. The clue of my problem was that this flag was being set by the dotnet
 and engine was setting it in RSA_set_flags - which is the proper way. You need to verify how the engine sets this flag and read my issue maybe it will help you in solving yours.</span></span></span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span lang="en"><span><span><br>
</span></span></span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span lang="en"><span><span>BR</span></span></span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span lang="en"><span><span>Piotr</span></span></span></div>
<div id="gmail-m_-7274699874073980074m_-7837997346193041486appendonsend"></div>
<hr style="display:inline-block;width:98%">
<div id="gmail-m_-7274699874073980074m_-7837997346193041486divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>Od:</b> openssl-users <<a href="mailto:openssl-users-bounces@openssl.org" rel="noreferrer" target="_blank">openssl-users-bounces@openssl.org</a>> w imieniu użytkownika Antonio Santagiuliana <<a href="mailto:santantonioswap@gmail.com" rel="noreferrer" target="_blank">santantonioswap@gmail.com</a>><br>
<b>Wysłane:</b> piątek, 8 października 2021 10:34<br>
<b>Do:</b> Tomas Mraz <<a href="mailto:tomas@openssl.org" rel="noreferrer" target="_blank">tomas@openssl.org</a>><br>
<b>DW:</b> <a href="mailto:openssl-users@openssl.org" rel="noreferrer" target="_blank">openssl-users@openssl.org</a> <<a href="mailto:openssl-users@openssl.org" rel="noreferrer" target="_blank">openssl-users@openssl.org</a>><br>
<b>Temat:</b> Re: Store Mgmt and keys loading ( keyform ENG )</font>
<div> </div>
</div>
<div>
<div dir="auto">Could I ask you what is the best way to let the Openssl carry on in the case I can't pass the private key from my store manager load() function as key is offloaded in secure hw? 
<div dir="auto">I have set RSA_FLAG_EXT_PKEY in RSA_METHOD but if I don't call the callback function from my Store Mgmt's load() where I get the uri ( the callback func is ossl_store_handle_load_result() ) I get error "could not read the private key".</div>
<div dir="auto">If instead I call the callback func , I don't know how to fill in its params , as I don't have the private key. What should I put in the params to let the rest of call chain ( I am on the dgst command ) not caring about private key but carry
 on with operation?or can I avoid calling the callback?</div>
<div dir="auto">Thank you</div>
</div>
<br>
<div>
<div dir="ltr">On Thu, 7 Oct 2021, 09:47 Antonio Santagiuliana, <<a href="mailto:santantonioswap@gmail.com" rel="noreferrer" target="_blank">santantonioswap@gmail.com</a>> wrote:<br>
</div>
<blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="auto">It is because of prototypes of methods..</div>
<br>
<div>
<div dir="ltr">On Thu, 7 Oct 2021, 08:49 Antonio Santagiuliana, <<a href="mailto:santantonioswap@gmail.com" rel="noreferrer noreferrer" target="_blank">santantonioswap@gmail.com</a>> wrote:<br>
</div>
<blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Hello,<br>
just continuing on this..<br>
I defined my store mgmt as :<br>
static const OSSL_ALGORITHM test_store[] = {<br>
{ "handle", "provider=test", mystore_functions},<br>
{NULL, NULL, NULL}<br>
};<br>
<br>
echo "test" | LD_LIBRARY_PATH=.    apps/openssl  dgst<br>
--provider-path=./providers --provider=test  --sign handle:1 -out<br>
messa.encrypted.bin<br>
<br>
Could not open file or uri for loading private key from handle:1<br>
<br>
C0628C24787F0000:error:16000069:STORE<br>
routines:ossl_store_get0_loader_int:unregistered<br>
scheme:crypto/store/store_register.c:237:scheme=file<br>
<br>
C0628C24787F0000:error:1608010C:STORE<br>
routines:inner_loader_fetch:unsupported:crypto/store/store_meth.c:356:No<br>
store loader found. For standard store loaders you need at least one<br>
of the default or base providers available. Did you forget to load<br>
them? Info: Global default library context, Scheme (file : 0),<br>
Properties (<null>)<br>
<br>
C0628C24787F0000:error:16000069:STORE<br>
routines:ossl_store_get0_loader_int:unregistered<br>
scheme:crypto/store/store_register.c:237:scheme=handle<br>
<br>
1) It firstly looks for a provider for scheme file: and it doesn't<br>
find as I haven't set up any store mgmt for file: .<br>
<br>
2) It looks like on second attempt it tries to look for handle: but it<br>
finds it not registered. What does this error mean ? Does it look for<br>
registered uri schemes online ? if that is the case how can this works<br>
instead : <a href="https://github.com/tpm2-software/tpm2-openssl" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">
https://github.com/tpm2-software/tpm2-openssl</a> ? They use<br>
handle: scheme as well.<br>
<br>
Does this mean it's a problem of the methods I registered for the<br>
store or is something related to the uri scheme I am using ?<br>
Sorry but I couldn't find more info on this in the sources/docs .<br>
<br>
<br>
thank you<br>
<br>
<br>
<br>
On Mon, Oct 4, 2021 at 4:52 PM Antonio Santagiuliana<br>
<<a href="mailto:santantonioswap@gmail.com" rel="noreferrer noreferrer noreferrer" target="_blank">santantonioswap@gmail.com</a>> wrote:<br>
><br>
> OK, thank you very much for your comments, that's clear.<br>
><br>
> On Mon, 4 Oct 2021, 15:45 Tomas Mraz, <<a href="mailto:tomas@openssl.org" rel="noreferrer noreferrer noreferrer" target="_blank">tomas@openssl.org</a>> wrote:<br>
>><br>
>> No, that's wrong. The dgst and other apps in OpenSSL-3.0 were already<br>
>> modified to use OSSL_STORE API to load keys. So you do not need to<br>
>> specify keyform=ENGINE if your key is provided by a provider that<br>
>> supports the STORE functionality for some special URL scheme. You just<br>
>> specify the right URL with that scheme to reference the key in the<br>
>> provider.<br>
>><br>
>> Of course third party applications need to be modified to call<br>
>> OSSL_STORE API in a similar way how the openssl application does it.<br>
>><br>
>> Tomas<br>
>><br>
>> On Mon, 2021-10-04 at 15:39 +0100, Antonio Santagiuliana wrote:<br>
>> > Thank you for your comment.<br>
>> > Am I wrong then in saying that dgst and possibly other apps are not<br>
>> > ready to be used with providers  rather than engines in the case you<br>
>> > need keyform=ENGINE ?<br>
>> ><br>
>> ><br>
>> > On Mon, 4 Oct 2021, 14:13 Tomas Mraz, <<a href="mailto:tomas@openssl.org" rel="noreferrer noreferrer noreferrer" target="_blank">tomas@openssl.org</a>> wrote:<br>
>> > > You would have to implement a STORE provider that handles your<br>
>> > > special<br>
>> > > url scheme and then the keys would be referenced by the<br>
>> > > yourscheme://any-identifier-you-have. Of course the application<br>
>> > > (i.e.,<br>
>> > > the openssl application which already does this) would have to use<br>
>> > > the<br>
>> > > OSSL_STORE API to load the keys and not directly the OSSL_DECODER<br>
>> > > API<br>
>> > > or the d2i/PEM_read APIs.<br>
>> > ><br>
>> > > Tomas<br>
>> > ><br>
>> > > On Mon, 2021-10-04 at 13:56 +0100, Antonio Santagiuliana wrote:<br>
>> > > > I checked the sources, I found that keyform cannot be set to<br>
>> > > > ENGINE<br>
>> > > > if engine is not specified in the command options, this is in the<br>
>> > > > function make_engine_url() called from load_key() when<br>
>> > > > format==FORMAT_ENGINE.<br>
>> > > > I am not specifying engine in the dgst command options as I am<br>
>> > > using<br>
>> > > > a  provider.<br>
>> > > > I would like to achieve the same as FORMAT_ENGINE does, but with<br>
>> > > > provider.<br>
>> > > ><br>
>> > > ><br>
>> > > > On Mon, 4 Oct 2021, 12:12 Antonio Santagiuliana,<br>
>> > > > <<a href="mailto:santantonioswap@gmail.com" rel="noreferrer noreferrer noreferrer" target="_blank">santantonioswap@gmail.com</a>> wrote:<br>
>> > > > > Hello,<br>
>> > > > > I am doing my own provider starting from the default provider's<br>
>> > > > > code.<br>
>> > > > > I have now a question, I am seeing the STOREMGMT operation is<br>
>> > > > > required to interpret the URI of input private key,  I would<br>
>> > > > > like<br>
>> > > > > that the string passed by the user for input key is not<br>
>> > > > > interpret<br>
>> > > > > as file to open but just my provider should save the string<br>
>> > > > > value<br>
>> > > > > to be used later .This is  when invoking command options such<br>
>> > > > > as<br>
>> > > > > dgst sign -in "text" -keyform ENG.<br>
>> > > > > With engines' architecture this is possible by passing option -<br>
>> > > > > keyform ENG to dgst command. The string in that case is not<br>
>> > > > > interpreted as a file path and just passed through.<br>
>> > > > > There was engine_set_load_privkey_function that was getting<br>
>> > > > > this<br>
>> > > > > string.<br>
>> > > > > How can I achieve this now with the provider architecture ? If<br>
>> > > > > I<br>
>> > > > > pass -keyform ENG to dgst command together with --provider , it<br>
>> > > > > says "no engine specified to load private key" Should I use<br>
>> > > > > OSSL_FUNC_store_load_fn and OSSL_FUNC_store_open_fn ? .<br>
>> > > > > Also, at low level I am using RSA_FLAG_EXT_PKEY flag set as I<br>
>> > > don't<br>
>> > > > > have a real private key info to load and use from a Filesystem.<br>
>> > > > > Is there anything to set in the KEYMGMT too ? I can see there<br>
>> > > > > is<br>
>> > > a<br>
>> > > > > flag OSSL_KEYMGMT_SELECT_PRIVATE_KEY indicating the private key<br>
>> > > > > data in a key object should be considered. Not really sure if<br>
>> > > this<br>
>> > > > > is something I should set or not and how this keymgmt operation<br>
>> > > > > relates with storemgmt operation.<br>
>> > > > ><br>
>> > > > > thank you if you can send some comment on this.<br>
>> > > > ><br>
>> > ><br>
>><br>
>> --<br>
>> Tomáš Mráz<br>
>> No matter how far down the wrong road you've gone, turn back.<br>
>>                                               Turkish proverb<br>
>> [You'll know whether the road is wrong if you carefully listen to your<br>
>> conscience.]<br>
>><br>
>><br>
</blockquote>
</div>
</blockquote>
</div>
<a href="https://www.softgent.com" rel="noreferrer" target="_blank"><img width="150" height="50" src="https://softgent.com/wp-content/uploads/2020/01/Zasob-14.png"></a>
<p style="font-family:"Open Sans",sans-serif,Arial,Tahoma;color:gray;display:block;font-size:9px;text-transform:uppercase;margin:10px 0px 0px">
<b>Softgent Sp. z o.o.</b>, Budowlanych 31d, 80-298 Gdansk, POLAND</p>
<p style="font-family:"Open Sans",sans-serif,Arial,Tahoma;color:gray;display:block;font-size:9px;text-transform:uppercase;margin:0px">
KRS: 0000674406, NIP: 9581679801, REGON: 367090912</p>
<a href="https://www.softgent.com" style="font-family:"Open Sans",sans-serif,Arial,Tahoma;text-decoration:none;color:blue;display:block;font-size:9px;text-transform:uppercase;margin:0px" rel="noreferrer" target="_blank">www.softgent.com</a>
<p style="font-family:"Open Sans",sans-serif,Arial,Tahoma;color:gray;display:block;font-size:9px;text-transform:uppercase;margin:10px 0px 0px">
Sąd Rejonowy Gdańsk-Północ w Gdańsku, VII Wydział Gospodarczy Krajowego Rejestru Sądowego</p>
<p style="font-family:"Open Sans",sans-serif,Arial,Tahoma;color:gray;display:block;font-size:9px;text-transform:uppercase;margin:0px">
KRS 0000674406, Kapitał zakładowy: 25 000,00 zł wpłacony w całości.</p>
<p style="margin-bottom:12pt"><span style="font-size:9pt;font-family:Tahoma,sans-serif;color:rgb(127,127,127)">Jesteśmy uczestnikiem Programu
<br>
</span><b><span style="font-size:16pt;font-family:Tahoma,sans-serif;color:red">RZETELNA</span></b>
<b><span style="font-size:16pt;font-family:Tahoma,sans-serif;color:gray"></span></b><b><span style="font-size:16pt;font-family:Tahoma,sans-serif">Firma
</span></b><span style="font-size:9pt;font-family:Tahoma,sans-serif;color:rgb(127,127,127)"><br>
Sprawdź naszą rzetelność na<br>
</span><a href="https://www.rzetelnafirma.pl/F5IA32UW" style="font-family:Tahoma,sans-serif;font-size:9pt" rel="noreferrer" target="_blank">https://www.rzetelnafirma.pl/F5IA32UW</a></p>
</div>
</div>

</blockquote></div>