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

Ported to ColdFusion/CFML #311

Closed
JamoCA opened this issue Oct 25, 2021 · 9 comments
Closed

Ported to ColdFusion/CFML #311

JamoCA opened this issue Oct 25, 2021 · 9 comments

Comments

@JamoCA
Copy link
Contributor

JamoCA commented Oct 25, 2021

I've ported nanoid to ColdFusion/CFML.
https://github.com/JamoCA/cfml-nanoid

NOTE: The built-in RandRange() function leverages Java's SecureRandom SHA1PRNG algorithm.

@ai
Copy link
Owner

ai commented Oct 26, 2021

Does it use hardware random generator?

@JamoCA
Copy link
Contributor Author

JamoCA commented Oct 26, 2021

I'm not sure... I'm still researching.

I found this:

2013 - Google confirmed that the IBM Java SecureRandom class in Java Cryptography Architecture (JCA) generated repetitive (and therefore predictable) sequences, which compromised application security made for Android to support the electronic currency Bitcoin – the equivalent of USD large amount in Bitcoins10,11 was stolen. (NOTE: The Java version is not mentioned.)
https://www.nature.com/articles/s41598-021-95388-7

and this:

SHA1PRNG is a pure Java implementation, that may or may not use /dev/[u]random, depending on the java.security.egd System property or securerandom.source Security property.... SHA1PRNG is an old method, unless there is an obvious reason or unless you definitely know what you are doing, it should not be used in production.
https://metebalci.com/blog/everything-about-javas-securerandom/

Which makes me think that it may not be possible to use Java's SecureRandom SHA1PRNG implementation (like the listed jnanoid library does) to generate a nanoid. (Does jnanoid use hardware random generator? source)

ColdFusion server environments may vary link as well as the version of Java used. I may need to rewrite the function to support different security classes, but I'm attempting to use regular CFML so that nothing additional has to be installed and/or configured.

@ai
Copy link
Owner

ai commented Oct 26, 2021

The modern secure random generators works in two steps:

  1. CPU collects electromagnetic noises (with another random data from OS) to generate random seed. It could take a while.
  2. Then we use a deterministic algorithm to generate a long pseudo-random bytes sequence from this seed.

These two steps allows us to generate random numbers faster. We need to collect noise only once (the implementation is a little more complicated, but let’s simplify).

SHA1PRNG is only the second step. With the same seed, it will generate the same byte sequence.

So, main question is who and how you set seed.

@ai
Copy link
Owner

ai commented Oct 26, 2021

Does jnanoid use hardware random generator?

It doesn’t pass anything to SecureRandom constructor. Why do we limit algorithm to SHA1PRNG?

@JamoCA
Copy link
Contributor Author

JamoCA commented Oct 26, 2021

I've just updated the component and added support for all available CFML algorithms for RandRange(): SHA1PRNG, IBMSecureRandom, NativePRNG, NativePRNGBlocking and NativePRNGNonBlocking.

@ai
Copy link
Owner

ai commented Oct 26, 2021

Still not sure how it works, but seems very likely that it should work properly.

Please send PR to docs with a link to your project to save your name in the project history.

@JamoCA
Copy link
Contributor Author

JamoCA commented Oct 26, 2021

BTW, Thanks for responding so quickly! (It often takes me days, weeks, etc to get responses from some project maintainers.)

@ai ai closed this as completed Oct 26, 2021
@JamoCA
Copy link
Contributor Author

JamoCA commented Oct 26, 2021

BTW, I just noticed that the quantity of "ports other programming languages" was referenced in the project's readme intro. (The number should now reflect 20 instead of 19.) Is this an issue? Should I re-edit?

@ai
Copy link
Owner

ai commented Oct 26, 2021

BTW, I just noticed that the quantity of "ports other programming languages" was referenced in the project's readme intro. (The number should now reflect 20 instead of 19.) Is this an issue? Should I re-edit?

Yeap! And try to find the same number in Chinese and Russian docs.

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