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

x509 random setSerial with BN_rand #212

Open
dcrawford1 opened this issue Mar 16, 2023 · 3 comments
Open

x509 random setSerial with BN_rand #212

dcrawford1 opened this issue Mar 16, 2023 · 3 comments

Comments

@dcrawford1
Copy link

Is there any way to set a random x509 serial number when creating a x509 self signed certificate? The openssl command line tool calls BN_rand(btmp, SERIAL_RAND_BITS, BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY)). Is there any way to do the equivalent with luaossl?

@daurnimator
Copy link
Collaborator

Just generate a random number and call :setSerial()?

@dcrawford1
Copy link
Author

I think I figured it out:

local bytes = openssl_rand.bytes(20)
crt:setSerial(openssl_bignum.fromBinary(bytes))

@daurnimator
Copy link
Collaborator

Sure that works if you want a byte-sized max for your range.

We should probably add bindings for e.g. openssl_rand.uniform where if you pass a bignum we use BN_rand or similar to generate a random number in the whole range?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants