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

SystemRandom is not imported correctly #486

Closed
shelman opened this issue Feb 9, 2018 · 1 comment · Fixed by #487
Closed

SystemRandom is not imported correctly #486

shelman opened this issue Feb 9, 2018 · 1 comment · Fixed by #487

Comments

@shelman
Copy link

shelman commented Feb 9, 2018

In src/oic/__init__.py, random.SystemRandom is imported via the following code:

try:
    import random.SystemRandom as rnd
except ImportError:
    import random as rnd

In both python2 and python3 this yields an import error and falls back to the random package.

I believe the fix is to change the import to from random import SystemRandom as rnd. The import works locally for me but I am having some trouble with the unit tests and wanted to check in before opening a pull request.

@schlenk
Copy link
Collaborator

schlenk commented Feb 9, 2018

Thats bad. Yes, PR welcome. That shouldn't break any tests.

tpazderka pushed a commit that referenced this issue Feb 12, 2018
* Fix randomness for rndstr() and unreserved()

The import for SystemRandom was broken, so rndstr() got its randomness from the non-CSPRNG random.Random().

We now use secrets.choice() when available, otherwise fallback to SystemRandom and warn if only the Mersenne-Twister based random.Random() is available.

It is probably a good idea to migrate to secrets.token_* APIs for rndstr() and unreserved() in the future.

Close #486
andrewkrug pushed a commit to mozilla-iam/pyoidc that referenced this issue Jun 6, 2019
* Fix randomness for rndstr() and unreserved()

The import for SystemRandom was broken, so rndstr() got its randomness from the non-CSPRNG random.Random().

We now use secrets.choice() when available, otherwise fallback to SystemRandom and warn if only the Mersenne-Twister based random.Random() is available.

It is probably a good idea to migrate to secrets.token_* APIs for rndstr() and unreserved() in the future.

Close CZ-NIC#486
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants