Sat, 25 Jul 2015 13:10:09 +0200
Corrected some code style issues.
4317
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

1  # * coding: utf8 * 
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

2  
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

3  # Copyright (c) 2015 Detlev Offenbach <detlev@dieoffenbachs.de> 
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

4  # 
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

5  
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

6  """ 
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

7  Module implementing SSL utility functions. 
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

8  """ 
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

9  
4318
c2f374ca452b
Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4317
diff
changeset

10  from __future__ import unicode_literals 
c2f374ca452b
Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4317
diff
changeset

11  
4317
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

12  from PyQt5.QtCore import qVersion 
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

13  
4332
64034d85c709
Corrected some code style issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4318
diff
changeset

14  
4317
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

15  def initSSL(): 
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

16  """ 
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

17  Function to initialize some global SSL stuff. 
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

18  """ 
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

19  if qVersion() < "5.3.0": 
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

20  # Qt 5.3.0 and newer don't use weak ciphers anymore 
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

21  try: 
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

22  from PyQt5.QtNetwork import QSslSocket 
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

23  except ImportError: 
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

24  # no SSL available, so there is nothing to initialize 
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

25  return 
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

26  
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

27  strongCiphers = [c for c in QSslSocket.supportedCiphers() 
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

28  if c.usedBits() >= 128] 
0de465a93200
Added code to limit SSL sockets to ciphers with at least 128 bits for Qt < 5.3.0.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

29  QSslSocket.setDefaultCiphers(strongCiphers) 