This is an archive of the discontinued LLVM Phabricator instance.

[LNT] Python 3 support: adapt secret computation
ClosedPublic

Authored by thopre on Sep 26 2019, 2:33 PM.

Details

Summary

Computation of the secret when it is not supplied on the command line
involves passing a string constructed with str to the sha1 function.
However that function expects binary data which is a different type in
Python3. This commit uses the bytes constructor as an additional step to
convert from text to binary data.

Event Timeline

thopre created this revision.Sep 26 2019, 2:33 PM
lnt/lnttool/create.py
141–146

Being no security expert, I am not sure about the patch. I do see that getrandbits is documented as not being for security purposes, but I think we can do the Python 3 support without changing the status quo of the "security".

With the future package:

from builtins import bytes
hashlib.sha1(bytes(str(random.getrandbits(256)), encoding='ascii')).hexdigest()
thopre updated this revision to Diff 223468.Oct 7 2019, 3:09 AM

Use approach suggested by Hubert to adapt the existing code rather than use a new way of generating random bits to not change the security strength of the code.

thopre edited the summary of this revision. (Show Details)Oct 7 2019, 3:10 AM
This revision is now accepted and ready to land.Oct 9 2019, 6:20 PM
thopre updated this revision to Diff 224297.Oct 10 2019, 3:15 AM

Fix mypy warning

thopre closed this revision.Oct 10 2019, 3:54 AM