Sat, 18 Jul 2015 16:50:24 +0200
Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
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  
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

14  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

15  """ 
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  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

17  """ 
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  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

19  # 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

20  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

21  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

22  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

23  # 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

24  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

25  
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  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

27  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

28  QSslSocket.setDefaultCiphers(strongCiphers) 