Re: [Help] Re: Bug#939181: cycle: Python2 removal in sid/bullseye
Hi Andreas, On 16.09.19 11:38, Andreas Tille wrote: > Hi Peter, > > On Sun, Sep 15, 2019 at 02:47:50PM +0100, peter green wrote: tmp = rt.encrypt('Cycle{}'.format(pickle.dumps(objSave))) >>> >>> Thanks to this hint >> This hint was *wrong*, it will introduce garbage into the string and the >> "rotor" code is clearly designed to work with byte strings, not unicode >> strings. >> >> Change it to >> >> "tmp=rt.encrypt( b'Cycle'+pickle.dumps(objSave) )" Oops, got that backwards. Thanks for spotting this. > Thanks a lot for your patience. Unfortunately this is not > yet the final solution: > > ... > Traceback (most recent call last): > File "/usr/bin/cycle", line 83, in OnCloseWindow > Save_Cycle(cycle.name, cycle.passwd, cycle.file) > File "/usr/share/cycle/save_load.py", line 46, in Save_Cycle > tmp=rt.encrypt( b'Cycle'+pickle.dumps(objSave) ) > File "/usr/share/cycle/p_rotor.py", line 63, in encrypt > return self.cryptmore(buf, 0) > File "/usr/share/cycle/p_rotor.py", line 88, in cryptmore > c = rotors[i][c ^ pos[i]] > TypeError: unsupported operand type(s) for ^: 'int' and 'float' That code could be patched by using int() around potentially float numbers. But honestly, it should better be ripped out and use real encryption. The docstring tells so: The rotor module has been removed from the Python 2.4 distribution because the rotor module uses an insecure algorithm and is deprecated. == Best wishes Michael signature.asc Description: OpenPGP digital signature
Re: [Help] Re: Bug#939181: cycle: Python2 removal in sid/bullseye
Hi Peter, On Sun, Sep 15, 2019 at 02:47:50PM +0100, peter green wrote: > > > tmp = rt.encrypt('Cycle{}'.format(pickle.dumps(objSave))) > > > > Thanks to this hint > This hint was *wrong*, it will introduce garbage into the string and the > "rotor" code is clearly designed to work with byte strings, not unicode > strings. > > Change it to > > "tmp=rt.encrypt( b'Cycle'+pickle.dumps(objSave) )" Thanks a lot for your patience. Unfortunately this is not yet the final solution: ... Traceback (most recent call last): File "/usr/bin/cycle", line 83, in OnCloseWindow Save_Cycle(cycle.name, cycle.passwd, cycle.file) File "/usr/share/cycle/save_load.py", line 46, in Save_Cycle tmp=rt.encrypt( b'Cycle'+pickle.dumps(objSave) ) File "/usr/share/cycle/p_rotor.py", line 63, in encrypt return self.cryptmore(buf, 0) File "/usr/share/cycle/p_rotor.py", line 88, in cryptmore c = rotors[i][c ^ pos[i]] TypeError: unsupported operand type(s) for ^: 'int' and 'float' Kind regards Andreas. -- http://fam-tille.de
Re: [Help] Re: Bug#939181: cycle: Python2 removal in sid/bullseye
> tmp = rt.encrypt('Cycle{}'.format(pickle.dumps(objSave))) Thanks to this hint This hint was *wrong*, it will introduce garbage into the string and the "rotor" code is clearly designed to work with byte strings, not unicode strings. Change it to "tmp=rt.encrypt( b'Cycle'+pickle.dumps(objSave) )"
Re: [Help] Re: Bug#939181: cycle: Python2 removal in sid/bullseye
Hi, On Thu, Sep 12, 2019 at 09:08:04PM +0200, Michael Kesper wrote: > > Since I do not have much experience with hashlib I'd be happy if > > someone might be able to proof-read `def Save_Cycle` in > > save_load.py. > > This does not have anything to do with hashlib per se. > It's just the usual mess of mixing bytestrings with strings. > You often don't notice in Python2, it just introduces subtle bugs. > Python3 is more strict here and doesn't allow it. > > Try this: > > tmp = rt.encrypt('Cycle{}'.format(pickle.dumps(objSave))) Thanks to this hint and the other hints by Peter Green, I'm now a bit further. > As an explanation: > > Python 3.7.3 (default, Apr 3 2019, 05:39:12) > ... Thanks as well. > P.S.: The code is in a bad state regarding whitespace / indentation. > This is critical to get right in Python (e.g. after a for there _has to_ > be an indentation added, Python normally uses four spaces, no tabs). I'm aware that the code is not good - there are other issues than spaces and tabs for instance I removed an instance of os.tempnam where upstream simply had overridden the automatic warning. Its unmaintained upstream as well. I've seen other code in Debian which is not good as well. Its rather a philosophical question whether it is better to drop it from Debian (and leave its users alone may be fiddling around with the upstream code themselves) or whether we try our best to make the code at least acceptable. I usually subscribe to the latter and think there is no right or wrong here. I'm not really sure whether we might manage in this case. After implementing all hints I'm now stumbling upon: Traceback (most recent call last): File "/usr/bin/cycle", line 83, in OnCloseWindow Save_Cycle(cycle.name, cycle.passwd, cycle.file) File "/usr/share/cycle/save_load.py", line 46, in Save_Cycle tmp = rt.encrypt('Cycle{}'.format(pickle.dumps(objSave))) File "/usr/share/cycle/p_rotor.py", line 63, in encrypt return self.cryptmore(buf, 0) File "/usr/share/cycle/p_rotor.py", line 88, in cryptmore c = rotors[i][c ^ pos[i]] TypeError: unsupported operand type(s) for ^: 'str' and 'int' I think an "int(c) ^ pos[i]" could do here - but I'd like to get some confirmation first. Kind regards Andreas. -- http://fam-tille.de
Re: [Help] Re: Bug#939181: cycle: Python2 removal in sid/bullseye
but this leads later to Traceback (most recent call last): File "cycle.py", line 83, in OnCloseWindow Save_Cycle(cycle.name, cycle.passwd, cycle.file) File "/home/andreas/debian-maintain/salsa/med-team/cycle/save_load.py", line 46, in Save_Cycle tmp=rt.encrypt( 'Cycle'+pickle.dumps(objSave) ) TypeError: can only concatenate str (not "bytes") to str String handling changed significantly between python2 and python3. Python 2 is "byte strings by default", type "str" was used for byte strings and type "unicode" was used for unicode strings. Implicit conversions between the two were allowed. Python 3 is "unicode by default", type "bytes" is used for byte strings and type "str" is used for unicode strings. There is no implict conversion between unicode strings and byte strings. "pickle.dumps" returned a bytes object, and you tried to concatenate it to a str object. You need to change 'Cycle' to b'Cycle'. Also python 3 bytes objects behave a bit differently from python 2 str objects. To accommodate this I believe you need the following changes in p_rotor.py "|for c in map(ord, buf):|" -> "|for c in buf:|" "|return ''.join(map(chr, outbuf))|" -> "|return bytes(outbuf)|" "|for c in map(ord, key):|" -> "for c in key:"
Re: [Help] Re: Bug#939181: cycle: Python2 removal in sid/bullseye
Hi, On 12.09.19 16:09, Andreas Tille wrote: > May be some final helping hint could be how to fix leaving the > program that leads to: > > > Traceback (most recent call last): File "/usr/bin/cycle", line 83, > in OnCloseWindow Save_Cycle(cycle.name, cycle.passwd, cycle.file) > File "/usr/share/cycle/save_load.py", line 27, in Save_Cycle > m.update(passwd) TypeError: Unicode-objects must be encoded before > hashing > > > I tried > > m.update(passwd.encode()) > > but this leads later to > > Traceback (most recent call last): File "cycle.py", line 83, in > OnCloseWindow Save_Cycle(cycle.name, cycle.passwd, cycle.file) File > "/home/andreas/debian-maintain/salsa/med-team/cycle/save_load.py", > line 46, in Save_Cycle tmp=rt.encrypt( 'Cycle'+pickle.dumps(objSave) > ) TypeError: can only concatenate str (not "bytes") to str > > > Since I do not have much experience with hashlib I'd be happy if > someone might be able to proof-read `def Save_Cycle` in > save_load.py. This does not have anything to do with hashlib per se. It's just the usual mess of mixing bytestrings with strings. You often don't notice in Python2, it just introduces subtle bugs. Python3 is more strict here and doesn't allow it. Try this: tmp = rt.encrypt('Cycle{}'.format(pickle.dumps(objSave))) As an explanation: Python 3.7.3 (default, Apr 3 2019, 05:39:12) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import pickle >>> s = 'abc123üöß' >>> objSave = pickle.dumps(s) >>> objSave b'\x80\x03X\x0c\x00\x00\x00abc123\xc3\xbc\xc3\xb6\xc3\x9fq\x00.' >>> type(objSave) >>> print('Cycle'+pickle.dumps(objSave)) Traceback (most recent call last): File "", line 1, in TypeError: can only concatenate str (not "bytes") to str >>> print('Cycle{}'.format(pickle.dumps(objSave))) Cycleb'\x80\x03C\x16\x80\x03X\x0c\x00\x00\x00abc123\xc3\xbc\xc3\xb6\xc3\x9fq\x00.q\x00.' Best wishes Michael P.S.: The code is in a bad state regarding whitespace / indentation. This is critical to get right in Python (e.g. after a for there _has to_ be an indentation added, Python normally uses four spaces, no tabs). signature.asc Description: OpenPGP digital signature
Re: [Help] Re: Bug#939181: cycle: Python2 removal in sid/bullseye
On Thu, Sep 12, 2019 at 01:57:32PM +0500, Andrey Rahmatullin wrote: > > > There are circular imports in the code so you most likely broke that by > > > reordering imports in various files. > > > > s/you most likely broke/2to3 most likely broke/ > 2to3 doesn't do that. You mentioned autopep8, it could do that. Ahhh, well, that might be another way to mess up the sequence. Put a mental note to warn me about autodep8. > > So may be I misinterpreted your hint but even reverting the reordering > > of 2to3 in my latest commit does not help. > I also said that other changes may be problematic too. I didn't check > them. OK, I redid the patching in git[1] now. Some more wxPython 4 porting was needed as well but I somehow got the user interface working. May be some final helping hint could be how to fix leaving the program that leads to: Traceback (most recent call last): File "/usr/bin/cycle", line 83, in OnCloseWindow Save_Cycle(cycle.name, cycle.passwd, cycle.file) File "/usr/share/cycle/save_load.py", line 27, in Save_Cycle m.update(passwd) TypeError: Unicode-objects must be encoded before hashing I tried m.update(passwd.encode()) but this leads later to Traceback (most recent call last): File "cycle.py", line 83, in OnCloseWindow Save_Cycle(cycle.name, cycle.passwd, cycle.file) File "/home/andreas/debian-maintain/salsa/med-team/cycle/save_load.py", line 46, in Save_Cycle tmp=rt.encrypt( 'Cycle'+pickle.dumps(objSave) ) TypeError: can only concatenate str (not "bytes") to str Since I do not have much experience with hashlib I'd be happy if someone might be able to proof-read `def Save_Cycle` in save_load.py. Kind regards Andreas. [1] https://salsa.debian.org/med-team/cycle -- http://fam-tille.de
Re: [Help] Re: Bug#939181: cycle: Python2 removal in sid/bullseye
On Thu, Sep 12, 2019 at 09:17:08AM +0200, Andreas Tille wrote: > > > $ cycle > > > Traceback (most recent call last): > > > File "/usr/bin/cycle", line 12, in > > > from dialogs import * > > > File "/usr/share/cycle/dialogs.py", line 8, in > > > from cal_year import cycle, Val > > > File "/usr/share/cycle/cal_year.py", line 9, in > > > from dialogs import Note_Dlg > > > ImportError: cannot import name 'Note_Dlg' from 'dialogs' > > > (/usr/share/cycle/dialogs.py) > > There are circular imports in the code so you most likely broke that by > > reordering imports in various files. > > s/you most likely broke/2to3 most likely broke/ 2to3 doesn't do that. You mentioned autopep8, it could do that. > > "from cal_year import *; from dialogs import *" works, the reverse > > doesn't, so the /usr/bin/cycle code is definitely problematic, not sure > > about other changes. > > I can not confirm that > >from cal_year import * > > works at all. It works in the unpatched Python2 version. I was just saying that (in the unpatched Python2 version) "from cal_year import *; from dialogs import *" works, the reverse doesn't, and the patched version contains the reverse. >git clone https://salsa.debian.org/med-team/cycle >cd cycle >echo "from cal_year import *" | python >quilt push -a >echo "from cal_year import *" | python3 > Traceback (most recent call last): > File "", line 1, in > File "/home/andreas/debian-maintain/salsa/med-team/cycle/cal_year.py", line > 9, in > from dialogs import Note_Dlg > File "/home/andreas/debian-maintain/salsa/med-team/cycle/dialogs.py", line > 12, in > from cal_year import cycle, Val > ImportError: cannot import name 'cycle' from 'cal_year' > (/home/andreas/debian-maintain/salsa/med-team/cycle/cal_year.py) > > > So may be I misinterpreted your hint but even reverting the reordering > of 2to3 in my latest commit does not help. I also said that other changes may be problematic too. I didn't check them. -- WBR, wRAR signature.asc Description: PGP signature
Re: [Help] Re: Bug#939181: cycle: Python2 removal in sid/bullseye
Hi Andrey, On Wed, Sep 11, 2019 at 07:32:33PM +0500, Andrey Rahmatullin wrote: > > $ cycle > > Traceback (most recent call last): > > File "/usr/bin/cycle", line 12, in > > from dialogs import * > > File "/usr/share/cycle/dialogs.py", line 8, in > > from cal_year import cycle, Val > > File "/usr/share/cycle/cal_year.py", line 9, in > > from dialogs import Note_Dlg > > ImportError: cannot import name 'Note_Dlg' from 'dialogs' > > (/usr/share/cycle/dialogs.py) > There are circular imports in the code so you most likely broke that by > reordering imports in various files. s/you most likely broke/2to3 most likely broke/ I admit I did not really checked what 2to3 created but I can assure you I did not simply fired up an editor and had fun reverting some import sequences. > "from cal_year import *; from dialogs import *" works, the reverse > doesn't, so the /usr/bin/cycle code is definitely problematic, not sure > about other changes. I can not confirm that from cal_year import * works at all. It works in the unpatched Python2 version. git clone https://salsa.debian.org/med-team/cycle cd cycle echo "from cal_year import *" | python quilt push -a echo "from cal_year import *" | python3 Traceback (most recent call last): File "", line 1, in File "/home/andreas/debian-maintain/salsa/med-team/cycle/cal_year.py", line 9, in from dialogs import Note_Dlg File "/home/andreas/debian-maintain/salsa/med-team/cycle/dialogs.py", line 12, in from cal_year import cycle, Val ImportError: cannot import name 'cycle' from 'cal_year' (/home/andreas/debian-maintain/salsa/med-team/cycle/cal_year.py) So may be I misinterpreted your hint but even reverting the reordering of 2to3 in my latest commit does not help. Kind regards Andreas. -- http://fam-tille.de
Re: [Help] Re: Bug#939181: cycle: Python2 removal in sid/bullseye
On Wed, Sep 11, 2019 at 04:12:34PM +0200, Andreas Tille wrote: > Control: tags -1 help > > On Wed, Sep 11, 2019 at 09:33:54AM -0300, Antonio Terceiro wrote: > > E: Sub-process /usr/bin/dpkg returned an error code (1) > > ~[100]$ cycle > > File "/usr/bin/cycle", line 29 > > if lang_find: > > ^ > > TabError: inconsistent use of tabs and spaces in indentation > > Argh. That's fixed via autopep8 in Git[1] now. However, when calling > cycle I get > > $ cycle > Traceback (most recent call last): > File "/usr/bin/cycle", line 12, in > from dialogs import * > File "/usr/share/cycle/dialogs.py", line 8, in > from cal_year import cycle, Val > File "/usr/share/cycle/cal_year.py", line 9, in > from dialogs import Note_Dlg > ImportError: cannot import name 'Note_Dlg' from 'dialogs' > (/usr/share/cycle/dialogs.py) There are circular imports in the code so you most likely broke that by reordering imports in various files. "from cal_year import *; from dialogs import *" works, the reverse doesn't, so the /usr/bin/cycle code is definitely problematic, not sure about other changes. -- WBR, wRAR signature.asc Description: PGP signature
[Help] Re: Bug#939181: cycle: Python2 removal in sid/bullseye
Control: tags -1 help On Wed, Sep 11, 2019 at 09:33:54AM -0300, Antonio Terceiro wrote: > E: Sub-process /usr/bin/dpkg returned an error code (1) > ~[100]$ cycle > File "/usr/bin/cycle", line 29 > if lang_find: > ^ > TabError: inconsistent use of tabs and spaces in indentation Argh. That's fixed via autopep8 in Git[1] now. However, when calling cycle I get $ cycle Traceback (most recent call last): File "/usr/bin/cycle", line 12, in from dialogs import * File "/usr/share/cycle/dialogs.py", line 8, in from cal_year import cycle, Val File "/usr/share/cycle/cal_year.py", line 9, in from dialogs import Note_Dlg ImportError: cannot import name 'Note_Dlg' from 'dialogs' (/usr/share/cycle/dialogs.py) Any idea how to fix this? Kind regards Andreas. [1] https://salsa.debian.org/med-team/cycle -- http://fam-tille.de