Recently added SecureSocket feature brought dependency on Python 2.7 namely bit_length() method. Since we need to keep compatibility with Python 2.6 that's on RHEL6 I added a fallback if bit_length is not available. I compared the DH_GROUP and SRP_GROUP dicts both on Python2.6 and 2.7 and they had the same content (bit length), so this patch should be safe.
Fixes issue 166.
Signed-off-by: Jan Tluka jtluka@redhat.com --- lnst/Common/SecureSocket.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/lnst/Common/SecureSocket.py b/lnst/Common/SecureSocket.py index b4ee8af..734d448 100644 --- a/lnst/Common/SecureSocket.py +++ b/lnst/Common/SecureSocket.py @@ -34,12 +34,23 @@ DH_GROUP = {"p": int("0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"\ "15728E5A8AACAA68FFFFFFFFFFFFFFFF", 16), "g": 2}
+# to support both Python2.6 and 2.7, use following workaround to count +# the bit length of a number; note that the workaround does not work for +# value 0 but we don't use it for such value +def bit_length(i): + try: + int(1).bit_length() + except AttributeError: + return len(bin(i)) - 2 + + return i.bit_length() + DH_GROUP["q"] = (DH_GROUP["p"]-1)/2 -DH_GROUP["q_size"] = DH_GROUP["q"].bit_length()/8 -if DH_GROUP["q"].bit_length()%8: +DH_GROUP["q_size"] = bit_length(DH_GROUP["q"])/8 +if bit_length(DH_GROUP["q"])%8: DH_GROUP["q_size"] += 1 -DH_GROUP["p_size"] = DH_GROUP["p"].bit_length()/8 -if DH_GROUP["p"].bit_length()%8: +DH_GROUP["p_size"] = bit_length(DH_GROUP["p"])/8 +if bit_length(DH_GROUP["p"])%8: DH_GROUP["p_size"] += 1
SRP_GROUP = {"p": int("0xAC6BDB41324A9A9BF166DE5E1389582FAF72B6651987EE07FC" @@ -55,11 +66,11 @@ SRP_GROUP = {"p": int("0xAC6BDB41324A9A9BF166DE5E1389582FAF72B6651987EE07FC" "g": 2}
SRP_GROUP["q"] = (SRP_GROUP["p"]-1)/2 -SRP_GROUP["q_size"] = SRP_GROUP["q"].bit_length()/8 -if SRP_GROUP["q"].bit_length()%8: +SRP_GROUP["q_size"] = bit_length(SRP_GROUP["q"])/8 +if bit_length(SRP_GROUP["q"])%8: SRP_GROUP["q_size"] += 1 -SRP_GROUP["p_size"] = SRP_GROUP["p"].bit_length()/8 -if SRP_GROUP["p"].bit_length()%8: +SRP_GROUP["p_size"] = bit_length(SRP_GROUP["p"])/8 +if bit_length(SRP_GROUP["p"])%8: SRP_GROUP["p_size"] += 1
class SecSocketException(Exception):
On Wed, Mar 16, 2016 at 03:16:43PM +0100, Jan Tluka wrote:
Recently added SecureSocket feature brought dependency on Python 2.7 namely bit_length() method. Since we need to keep compatibility with Python 2.6 that's on RHEL6 I added a fallback if bit_length is not available. I compared the DH_GROUP and SRP_GROUP dicts both on Python2.6 and 2.7 and they had the same content (bit length), so this patch should be safe.
Fixes issue 166.
Signed-off-by: Jan Tluka jtluka@redhat.com
lnst/Common/SecureSocket.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/lnst/Common/SecureSocket.py b/lnst/Common/SecureSocket.py index b4ee8af..734d448 100644 --- a/lnst/Common/SecureSocket.py +++ b/lnst/Common/SecureSocket.py @@ -34,12 +34,23 @@ DH_GROUP = {"p": int("0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"\ "15728E5A8AACAA68FFFFFFFFFFFFFFFF", 16), "g": 2}
+# to support both Python2.6 and 2.7, use following workaround to count +# the bit length of a number; note that the workaround does not work for +# value 0 but we don't use it for such value
What do you mean it doesn't work for 0? when I try it i get bit length 1 which seems fine to me.
+def bit_length(i):
- try:
int(1).bit_length()
- except AttributeError:
return len(bin(i)) - 2
- return i.bit_length()
Why not: try: return i.bit_length() except: return len(bin(i)) - 2
DH_GROUP["q"] = (DH_GROUP["p"]-1)/2 -DH_GROUP["q_size"] = DH_GROUP["q"].bit_length()/8 -if DH_GROUP["q"].bit_length()%8: +DH_GROUP["q_size"] = bit_length(DH_GROUP["q"])/8 +if bit_length(DH_GROUP["q"])%8: DH_GROUP["q_size"] += 1 -DH_GROUP["p_size"] = DH_GROUP["p"].bit_length()/8 -if DH_GROUP["p"].bit_length()%8: +DH_GROUP["p_size"] = bit_length(DH_GROUP["p"])/8 +if bit_length(DH_GROUP["p"])%8: DH_GROUP["p_size"] += 1
SRP_GROUP = {"p": int("0xAC6BDB41324A9A9BF166DE5E1389582FAF72B6651987EE07FC" @@ -55,11 +66,11 @@ SRP_GROUP = {"p": int("0xAC6BDB41324A9A9BF166DE5E1389582FAF72B6651987EE07FC" "g": 2}
SRP_GROUP["q"] = (SRP_GROUP["p"]-1)/2 -SRP_GROUP["q_size"] = SRP_GROUP["q"].bit_length()/8 -if SRP_GROUP["q"].bit_length()%8: +SRP_GROUP["q_size"] = bit_length(SRP_GROUP["q"])/8 +if bit_length(SRP_GROUP["q"])%8: SRP_GROUP["q_size"] += 1 -SRP_GROUP["p_size"] = SRP_GROUP["p"].bit_length()/8 -if SRP_GROUP["p"].bit_length()%8: +SRP_GROUP["p_size"] = bit_length(SRP_GROUP["p"])/8 +if bit_length(SRP_GROUP["p"])%8: SRP_GROUP["p_size"] += 1
class SecSocketException(Exception):
2.4.3 _______________________________________________ LNST-developers mailing list lnst-developers@lists.fedorahosted.org https://lists.fedorahosted.org/admin/lists/lnst-developers@lists.fedorahoste...
On Mon, Mar 21, 2016 at 11:11:51AM +0100, Ondrej Lichtner wrote:
On Wed, Mar 16, 2016 at 03:16:43PM +0100, Jan Tluka wrote:
Recently added SecureSocket feature brought dependency on Python 2.7 namely bit_length() method. Since we need to keep compatibility with Python 2.6 that's on RHEL6 I added a fallback if bit_length is not available. I compared the DH_GROUP and SRP_GROUP dicts both on Python2.6 and 2.7 and they had the same content (bit length), so this patch should be safe.
Fixes issue 166.
Signed-off-by: Jan Tluka jtluka@redhat.com
lnst/Common/SecureSocket.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/lnst/Common/SecureSocket.py b/lnst/Common/SecureSocket.py index b4ee8af..734d448 100644 --- a/lnst/Common/SecureSocket.py +++ b/lnst/Common/SecureSocket.py @@ -34,12 +34,23 @@ DH_GROUP = {"p": int("0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"\ "15728E5A8AACAA68FFFFFFFFFFFFFFFF", 16), "g": 2}
+# to support both Python2.6 and 2.7, use following workaround to count +# the bit length of a number; note that the workaround does not work for +# value 0 but we don't use it for such value
What do you mean it doesn't work for 0? when I try it i get bit length 1 which seems fine to me.
Ah, never mind, the bit_length() method returns 0 for 0... so the branches return different lengths for 0... Ok, keep the comment, you're right... we won't be using this for 0
+def bit_length(i):
- try:
int(1).bit_length()
- except AttributeError:
return len(bin(i)) - 2
- return i.bit_length()
Why not: try: return i.bit_length() except: return len(bin(i)) - 2
DH_GROUP["q"] = (DH_GROUP["p"]-1)/2 -DH_GROUP["q_size"] = DH_GROUP["q"].bit_length()/8 -if DH_GROUP["q"].bit_length()%8: +DH_GROUP["q_size"] = bit_length(DH_GROUP["q"])/8 +if bit_length(DH_GROUP["q"])%8: DH_GROUP["q_size"] += 1 -DH_GROUP["p_size"] = DH_GROUP["p"].bit_length()/8 -if DH_GROUP["p"].bit_length()%8: +DH_GROUP["p_size"] = bit_length(DH_GROUP["p"])/8 +if bit_length(DH_GROUP["p"])%8: DH_GROUP["p_size"] += 1
SRP_GROUP = {"p": int("0xAC6BDB41324A9A9BF166DE5E1389582FAF72B6651987EE07FC" @@ -55,11 +66,11 @@ SRP_GROUP = {"p": int("0xAC6BDB41324A9A9BF166DE5E1389582FAF72B6651987EE07FC" "g": 2}
SRP_GROUP["q"] = (SRP_GROUP["p"]-1)/2 -SRP_GROUP["q_size"] = SRP_GROUP["q"].bit_length()/8 -if SRP_GROUP["q"].bit_length()%8: +SRP_GROUP["q_size"] = bit_length(SRP_GROUP["q"])/8 +if bit_length(SRP_GROUP["q"])%8: SRP_GROUP["q_size"] += 1 -SRP_GROUP["p_size"] = SRP_GROUP["p"].bit_length()/8 -if SRP_GROUP["p"].bit_length()%8: +SRP_GROUP["p_size"] = bit_length(SRP_GROUP["p"])/8 +if bit_length(SRP_GROUP["p"])%8: SRP_GROUP["p_size"] += 1
class SecSocketException(Exception):
2.4.3 _______________________________________________ LNST-developers mailing list lnst-developers@lists.fedorahosted.org https://lists.fedorahosted.org/admin/lists/lnst-developers@lists.fedorahoste...
LNST-developers mailing list lnst-developers@lists.fedorahosted.org https://lists.fedorahosted.org/admin/lists/lnst-developers@lists.fedorahoste...
Mon, Mar 21, 2016 at 11:11:51AM CET, olichtne@redhat.com wrote:
On Wed, Mar 16, 2016 at 03:16:43PM +0100, Jan Tluka wrote:
Recently added SecureSocket feature brought dependency on Python 2.7 namely bit_length() method. Since we need to keep compatibility with Python 2.6 that's on RHEL6 I added a fallback if bit_length is not available. I compared the DH_GROUP and SRP_GROUP dicts both on Python2.6 and 2.7 and they had the same content (bit length), so this patch should be safe.
Fixes issue 166.
Signed-off-by: Jan Tluka jtluka@redhat.com
+def bit_length(i):
- try:
int(1).bit_length()
- except AttributeError:
return len(bin(i)) - 2
- return i.bit_length()
Why not: try: return i.bit_length() except: return len(bin(i)) - 2
Ok, will resend with this fix.
-Jan
lnst-developers@lists.fedorahosted.org