OLD | NEW |
1 # Authors: | 1 # Authors: |
2 # Trevor Perrin | 2 # Trevor Perrin |
3 # Dave Baggett (Arcode Corporation) - cleanup handling of constants | 3 # Dave Baggett (Arcode Corporation) - cleanup handling of constants |
| 4 # Yngve Pettersen (ported by Paul Sokolovsky) - TLS 1.2 |
4 # | 5 # |
5 # See the LICENSE file for legal information regarding use of this file. | 6 # See the LICENSE file for legal information regarding use of this file. |
6 | 7 |
7 """Class for setting handshake parameters.""" | 8 """Class for setting handshake parameters.""" |
8 | 9 |
9 from .constants import CertificateType | 10 from .constants import CertificateType |
10 from .utils import cryptomath | 11 from .utils import cryptomath |
11 from .utils import cipherfactory | 12 from .utils import cipherfactory |
12 | 13 |
13 # RC4 is preferred as faster in Python, works in SSL3, and immune to CBC | 14 # RC4 is preferred as faster in Python, works in SSL3, and immune to CBC |
14 # issues such as timing attacks | 15 # issues such as timing attacks |
15 CIPHER_NAMES = ["rc4", "aes256", "aes128", "3des"] | 16 CIPHER_NAMES = ["rc4", "aes256", "aes128", "3des"] |
16 MAC_NAMES = ["sha"] # Don't allow "md5" by default. | 17 MAC_NAMES = ["sha", "sha256"] # Don't allow "md5" by default. |
17 ALL_MAC_NAMES = ["sha", "md5"] | 18 ALL_MAC_NAMES = ["sha", "sha256", "md5"] |
18 KEY_EXCHANGE_NAMES = ["rsa", "dhe_rsa", "srp_sha", "srp_sha_rsa", "dh_anon"] | 19 KEY_EXCHANGE_NAMES = ["rsa", "dhe_rsa", "srp_sha", "srp_sha_rsa", "dh_anon"] |
19 CIPHER_IMPLEMENTATIONS = ["openssl", "pycrypto", "python"] | 20 CIPHER_IMPLEMENTATIONS = ["openssl", "pycrypto", "python"] |
20 CERTIFICATE_TYPES = ["x509"] | 21 CERTIFICATE_TYPES = ["x509"] |
21 TLS_INTOLERANCE_TYPES = ["alert", "close", "reset"] | 22 TLS_INTOLERANCE_TYPES = ["alert", "close", "reset"] |
22 | 23 |
23 class HandshakeSettings(object): | 24 class HandshakeSettings(object): |
24 """This class encapsulates various parameters that can be used with | 25 """This class encapsulates various parameters that can be used with |
25 a TLS handshake. | 26 a TLS handshake. |
26 @sort: minKeySize, maxKeySize, cipherNames, macNames, certificateTypes, | 27 @sort: minKeySize, maxKeySize, cipherNames, macNames, certificateTypes, |
27 minVersion, maxVersion | 28 minVersion, maxVersion |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 73 |
73 The only allowed certificate type is 'x509'. This list is only used with a | 74 The only allowed certificate type is 'x509'. This list is only used with a |
74 client handshake. The client will advertise to the server which certificate | 75 client handshake. The client will advertise to the server which certificate |
75 types are supported, and will check that the server uses one of the | 76 types are supported, and will check that the server uses one of the |
76 appropriate types. | 77 appropriate types. |
77 | 78 |
78 | 79 |
79 @type minVersion: tuple | 80 @type minVersion: tuple |
80 @ivar minVersion: The minimum allowed SSL/TLS version. | 81 @ivar minVersion: The minimum allowed SSL/TLS version. |
81 | 82 |
82 This variable can be set to (3,0) for SSL 3.0, (3,1) for | 83 This variable can be set to (3,0) for SSL 3.0, (3,1) for TLS 1.0, (3,2) for |
83 TLS 1.0, or (3,2) for TLS 1.1. If the other party wishes to | 84 TLS 1.1, or (3,3) for TLS 1.2. If the other party wishes to use a lower |
84 use a lower version, a protocol_version alert will be signalled. | 85 version, a protocol_version alert will be signalled. The default is (3,1). |
85 The default is (3,0). | |
86 | 86 |
87 @type maxVersion: tuple | 87 @type maxVersion: tuple |
88 @ivar maxVersion: The maximum allowed SSL/TLS version. | 88 @ivar maxVersion: The maximum allowed SSL/TLS version. |
89 | 89 |
90 This variable can be set to (3,0) for SSL 3.0, (3,1) for | 90 This variable can be set to (3,0) for SSL 3.0, (3,1) for TLS 1.0, (3,2) for |
91 TLS 1.0, or (3,2) for TLS 1.1. If the other party wishes to | 91 TLS 1.1, or (3,3) for TLS 1.2. If the other party wishes to use a higher |
92 use a higher version, a protocol_version alert will be signalled. | 92 version, a protocol_version alert will be signalled. The default is (3,3). |
93 The default is (3,2). (WARNING: Some servers may (improperly) | 93 (WARNING: Some servers may (improperly) reject clients which offer support |
94 reject clients which offer support for TLS 1.1. In this case, | 94 for TLS 1.1. In this case, try lowering maxVersion to (3,1)). |
95 try lowering maxVersion to (3,1)). | |
96 | 95 |
97 @type tlsIntolerant: tuple | 96 @type tlsIntolerant: tuple |
98 @ivar tlsIntolerant: The TLS ClientHello version which the server | 97 @ivar tlsIntolerant: The TLS ClientHello version which the server |
99 simulates intolerance of. | 98 simulates intolerance of. |
100 | 99 |
101 If tlsIntolerant is not None, the server will simulate TLS version | 100 If tlsIntolerant is not None, the server will simulate TLS version |
102 intolerance by aborting the handshake in response to all TLS versions | 101 intolerance by aborting the handshake in response to all TLS versions |
103 tlsIntolerant or higher. | 102 tlsIntolerant or higher. |
104 | 103 |
105 @type tlsIntoleranceType: str | 104 @type tlsIntoleranceType: str |
(...skipping 10 matching lines...) Expand all Loading... |
116 TLS Extension number, so should NOT be used in production software. | 115 TLS Extension number, so should NOT be used in production software. |
117 """ | 116 """ |
118 def __init__(self): | 117 def __init__(self): |
119 self.minKeySize = 1023 | 118 self.minKeySize = 1023 |
120 self.maxKeySize = 8193 | 119 self.maxKeySize = 8193 |
121 self.cipherNames = CIPHER_NAMES | 120 self.cipherNames = CIPHER_NAMES |
122 self.macNames = MAC_NAMES | 121 self.macNames = MAC_NAMES |
123 self.keyExchangeNames = KEY_EXCHANGE_NAMES | 122 self.keyExchangeNames = KEY_EXCHANGE_NAMES |
124 self.cipherImplementations = CIPHER_IMPLEMENTATIONS | 123 self.cipherImplementations = CIPHER_IMPLEMENTATIONS |
125 self.certificateTypes = CERTIFICATE_TYPES | 124 self.certificateTypes = CERTIFICATE_TYPES |
126 self.minVersion = (3,0) | 125 self.minVersion = (3,1) |
127 self.maxVersion = (3,2) | 126 self.maxVersion = (3,3) |
128 self.tlsIntolerant = None | 127 self.tlsIntolerant = None |
129 self.tlsIntoleranceType = 'alert' | 128 self.tlsIntoleranceType = 'alert' |
130 self.useExperimentalTackExtension = False | 129 self.useExperimentalTackExtension = False |
131 | 130 |
132 # Validates the min/max fields, and certificateTypes | 131 # Validates the min/max fields, and certificateTypes |
133 # Filters out unsupported cipherNames and cipherImplementations | 132 # Filters out unsupported cipherNames and cipherImplementations |
134 def _filter(self): | 133 def _filter(self): |
135 other = HandshakeSettings() | 134 other = HandshakeSettings() |
136 other.minKeySize = self.minKeySize | 135 other.minKeySize = self.minKeySize |
137 other.maxKeySize = self.maxKeySize | 136 other.maxKeySize = self.maxKeySize |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 if s not in CERTIFICATE_TYPES: | 184 if s not in CERTIFICATE_TYPES: |
186 raise ValueError("Unknown certificate type: '%s'" % s) | 185 raise ValueError("Unknown certificate type: '%s'" % s) |
187 | 186 |
188 if other.tlsIntoleranceType not in TLS_INTOLERANCE_TYPES: | 187 if other.tlsIntoleranceType not in TLS_INTOLERANCE_TYPES: |
189 raise ValueError( | 188 raise ValueError( |
190 "Unknown TLS intolerance type: '%s'" % other.tlsIntoleranceType) | 189 "Unknown TLS intolerance type: '%s'" % other.tlsIntoleranceType) |
191 | 190 |
192 if other.minVersion > other.maxVersion: | 191 if other.minVersion > other.maxVersion: |
193 raise ValueError("Versions set incorrectly") | 192 raise ValueError("Versions set incorrectly") |
194 | 193 |
195 if not other.minVersion in ((3,0), (3,1), (3,2)): | 194 if not other.minVersion in ((3,0), (3,1), (3,2), (3,3)): |
196 raise ValueError("minVersion set incorrectly") | 195 raise ValueError("minVersion set incorrectly") |
197 | 196 |
198 if not other.maxVersion in ((3,0), (3,1), (3,2)): | 197 if not other.maxVersion in ((3,0), (3,1), (3,2), (3,3)): |
199 raise ValueError("maxVersion set incorrectly") | 198 raise ValueError("maxVersion set incorrectly") |
200 | 199 |
| 200 if other.maxVersion < (3,3): |
| 201 # No sha256 pre TLS 1.2 |
| 202 other.macNames = [e for e in self.macNames if e != "sha256"] |
| 203 |
201 return other | 204 return other |
202 | 205 |
203 def _getCertificateTypes(self): | 206 def _getCertificateTypes(self): |
204 l = [] | 207 l = [] |
205 for ct in self.certificateTypes: | 208 for ct in self.certificateTypes: |
206 if ct == "x509": | 209 if ct == "x509": |
207 l.append(CertificateType.x509) | 210 l.append(CertificateType.x509) |
208 else: | 211 else: |
209 raise AssertionError() | 212 raise AssertionError() |
210 return l | 213 return l |
OLD | NEW |