Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openssl rand doesn't use provider or propquery and does not allow to fetch a specific rand type by name #20850

Open
simo5 opened this issue Apr 27, 2023 · 10 comments
Labels
branch: master Merge to master branch branch: 3.0 Merge to openssl-3.0 branch branch: 3.1 Merge to openssl-3.1 triaged: bug The issue/pr is/fixes a bug

Comments

@simo5
Copy link
Contributor

simo5 commented Apr 27, 2023

rand_main parses provider options via opt_provider(), however it never fetches a random provider, it just unconditionally uses the default.

@simo5 simo5 added the issue: bug report The issue was opened to report a bug label Apr 27, 2023
@mattcaswell mattcaswell added triaged: bug The issue/pr is/fixes a bug and removed issue: bug report The issue was opened to report a bug labels Apr 28, 2023
@t8m
Copy link
Member

t8m commented Apr 28, 2023

I assume this is because the EVP_RAND is initialized before the potential rand provider is loaded.

@t8m t8m added branch: master Merge to master branch branch: 3.0 Merge to openssl-3.0 branch branch: 3.1 Merge to openssl-3.1 labels Apr 28, 2023
@t8m
Copy link
Member

t8m commented Apr 28, 2023

@simo5 What does the random provider actually provide? Which algorithm? How do you call the rand command?

@simo5
Copy link
Contributor Author

simo5 commented Apr 28, 2023

I called the algorithm PKCS11-RAND because for pkcs11 you have no idea what algorithm there is, it's like the rdrand engine.

But that is not the point, the openssl command simply ignore all provider related options.

I think we should look closely at the whole abstraction built around the rand provider in any case.

Other things I found: the provider loader API considers locking functions optional, yet if you do not provide them you do not go far, as early on the code requires them for seeding the "primary" drbg, which is not a thing in a hardware RNG (which, btw does not allow (re)seeding with the token I have).

I think you should try to convert the rdrand engine in a provider and then you'll figure out all the things that are not really right ...

OTOH, you may consider that I should only use HW sources for seeding and not for final numbers, but that doesn't work if your provider is a FIPS provider and you want random numbers to come out only from a certified source and not from some additional PRNG that is not certified.

Anyway I tried to call openssl rand -provider pkcs11 -propquery provider=pkcs11 1
And saw that the provider's rng code was untouched.

To force the use of the provider code for testing I now change the openssl.conf file to add a random section wth random = PKCS11-RAND and that does request bytes from the provider.

@paulidale
Copy link
Contributor

The code is still going to fetch CTR-DRBG regardless of the provider command line options (which are working BTW). Using config and setting random = PKCS11-RAND changes what is being fetched and thus works.

To address the real problem, what the rand command needs is another option to specify the RNG to be used along with any parameters it might need (a -randopt like -pkeyopt for genpkey). Given these it should then call RAND_set_seed_source_type() and/or RAND_set_DRBG_type() to specify the RNG to use. Alternatively, it could call RAND_set0_public() to override the public DRBG with the specified source.

@paulidale paulidale changed the title openssl rand accepts provider options but never uses them openssl rand doesn't allow the random fetched to be specified May 1, 2023
@paulidale
Copy link
Contributor

I edited the title to be more accurate.

@simo5
Copy link
Contributor Author

simo5 commented May 2, 2023

I will test if the other options work, at a first read of the code I did not see them used at all.

@simo5
Copy link
Contributor Author

simo5 commented May 2, 2023

Changing the name to CTR-DRBG did indeed pull the random generator from the provider, the problem is that it does it unconditionally.
Setting -propquery provider!=pkcs11 or -provider default -propquery provider=default makes no difference.
So I think I maintain my initial report that these options are ignored in openssl rand

@t8m
Copy link
Member

t8m commented May 2, 2023

Yeah, I assume the propquery is not applied to the CTR-DRBG fetch.

@simo5 simo5 changed the title openssl rand doesn't allow the random fetched to be specified openssl rand doesn't use provider or propquery and does not allow to fetch a specific rand type by name May 2, 2023
@paulidale
Copy link
Contributor

Thanks for the extra investigation.

@paulidale
Copy link
Contributor

The -file command line option isn't ideal either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
branch: master Merge to master branch branch: 3.0 Merge to openssl-3.0 branch branch: 3.1 Merge to openssl-3.1 triaged: bug The issue/pr is/fixes a bug
Projects
Status: Backlog
Development

No branches or pull requests

4 participants