pygop icon indicating copy to clipboard operation
pygop copied to clipboard

DH_KEY_TOO_SMALL error fix, e.g. Ubuntu 18 -> 20 increase in SECLEVEL

Open christianchristensen opened this issue 3 years ago • 0 comments

Error observed

$ python2.7 pygop/gopcli.py -r 4 -s 0
Failed to reach the lighting server. Check to make sure you're connected to the same network as the gateway and it's online.
Reason:  [SSL: DH_KEY_TOO_SMALL] dh key too small (_ssl.c:727)
Failed to setRoomLevelByRid

Fix (...at least that worked):

diff --git a/pygop.py b/pygop.py
index 50833f2..ce74d3a 100644
--- a/pygop.py
+++ b/pygop.py
@@ -231,7 +231,10 @@ class pygop(object):

         # handle any connection errors
         try:
-            response = urllib2.urlopen(req)
+            # https://askubuntu.com/questions/1231844/ssl-sslerror-ssl-dh-key-too-small-dh-key-too-small-ssl-c1108 & https://docs
.python.org/2/library/urllib2.html
+            context=ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
+            context.set_ciphers('DEFAULT@SECLEVEL=1')
+            response = urllib2.urlopen(req,context=context)
         except urllib2.URLError as e:
             if hasattr(e, 'reason'):
                 print 'Failed to reach the lighting server. Check to make ' \

After fix:

python2.7 pygop/gopcli.py -r 4 -s 0
Turning 4 off

This fix is to be local to pygop rather than overriding global (e.g. https://askubuntu.com/questions/1233186/ubuntu-20-04-how-to-set-lower-ssl-security-level )

christianchristensen avatar Jan 01 '22 04:01 christianchristensen