OLD | NEW |
1 """Classes representing TLS messages.""" | 1 """Classes representing TLS messages.""" |
2 | 2 |
3 from utils.compat import * | 3 from utils.compat import * |
4 from utils.cryptomath import * | 4 from utils.cryptomath import * |
5 from errors import * | 5 from errors import * |
6 from utils.codec import * | 6 from utils.codec import * |
7 from constants import * | 7 from constants import * |
8 from X509 import X509 | 8 from X509 import X509 |
9 from X509CertChain import X509CertChain | 9 from X509CertChain import X509CertChain |
10 | 10 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 self.contentType = ContentType.handshake | 124 self.contentType = ContentType.handshake |
125 self.ssl2 = ssl2 | 125 self.ssl2 = ssl2 |
126 self.client_version = (0,0) | 126 self.client_version = (0,0) |
127 self.random = createByteArrayZeros(32) | 127 self.random = createByteArrayZeros(32) |
128 self.session_id = createByteArraySequence([]) | 128 self.session_id = createByteArraySequence([]) |
129 self.cipher_suites = [] # a list of 16-bit values | 129 self.cipher_suites = [] # a list of 16-bit values |
130 self.certificate_types = [CertificateType.x509] | 130 self.certificate_types = [CertificateType.x509] |
131 self.compression_methods = [] # a list of 8-bit values | 131 self.compression_methods = [] # a list of 8-bit values |
132 self.srp_username = None # a string | 132 self.srp_username = None # a string |
133 self.channel_id = False | 133 self.channel_id = False |
| 134 self.support_signed_cert_timestamps = False |
134 | 135 |
135 def create(self, version, random, session_id, cipher_suites, | 136 def create(self, version, random, session_id, cipher_suites, |
136 certificate_types=None, srp_username=None): | 137 certificate_types=None, srp_username=None): |
137 self.client_version = version | 138 self.client_version = version |
138 self.random = random | 139 self.random = random |
139 self.session_id = session_id | 140 self.session_id = session_id |
140 self.cipher_suites = cipher_suites | 141 self.cipher_suites = cipher_suites |
141 self.certificate_types = certificate_types | 142 self.certificate_types = certificate_types |
142 self.compression_methods = [0] | 143 self.compression_methods = [0] |
143 self.srp_username = srp_username | 144 self.srp_username = srp_username |
(...skipping 26 matching lines...) Expand all Loading... |
170 soFar = 0 | 171 soFar = 0 |
171 while soFar != totalExtLength: | 172 while soFar != totalExtLength: |
172 extType = p.get(2) | 173 extType = p.get(2) |
173 extLength = p.get(2) | 174 extLength = p.get(2) |
174 if extType == 6: | 175 if extType == 6: |
175 self.srp_username = bytesToString(p.getVarBytes(1)) | 176 self.srp_username = bytesToString(p.getVarBytes(1)) |
176 elif extType == 7: | 177 elif extType == 7: |
177 self.certificate_types = p.getVarList(1, 1) | 178 self.certificate_types = p.getVarList(1, 1) |
178 elif extType == ExtensionType.channel_id: | 179 elif extType == ExtensionType.channel_id: |
179 self.channel_id = True | 180 self.channel_id = True |
| 181 elif extType == ExtensionType.signed_cert_timestamps: |
| 182 if extLength: |
| 183 raise SyntaxError() |
| 184 self.support_signed_cert_timestamps = True |
180 else: | 185 else: |
181 p.getFixBytes(extLength) | 186 p.getFixBytes(extLength) |
182 soFar += 4 + extLength | 187 soFar += 4 + extLength |
183 p.stopLengthCheck() | 188 p.stopLengthCheck() |
184 return self | 189 return self |
185 | 190 |
186 def write(self, trial=False): | 191 def write(self, trial=False): |
187 w = HandshakeMsg.preWrite(self, HandshakeType.client_hello, trial) | 192 w = HandshakeMsg.preWrite(self, HandshakeType.client_hello, trial) |
188 w.add(self.client_version[0], 1) | 193 w.add(self.client_version[0], 1) |
189 w.add(self.client_version[1], 1) | 194 w.add(self.client_version[1], 1) |
(...skipping 27 matching lines...) Expand all Loading... |
217 class ServerHello(HandshakeMsg): | 222 class ServerHello(HandshakeMsg): |
218 def __init__(self): | 223 def __init__(self): |
219 self.contentType = ContentType.handshake | 224 self.contentType = ContentType.handshake |
220 self.server_version = (0,0) | 225 self.server_version = (0,0) |
221 self.random = createByteArrayZeros(32) | 226 self.random = createByteArrayZeros(32) |
222 self.session_id = createByteArraySequence([]) | 227 self.session_id = createByteArraySequence([]) |
223 self.cipher_suite = 0 | 228 self.cipher_suite = 0 |
224 self.certificate_type = CertificateType.x509 | 229 self.certificate_type = CertificateType.x509 |
225 self.compression_method = 0 | 230 self.compression_method = 0 |
226 self.channel_id = False | 231 self.channel_id = False |
| 232 self.signed_cert_timestamps = None |
227 | 233 |
228 def create(self, version, random, session_id, cipher_suite, | 234 def create(self, version, random, session_id, cipher_suite, |
229 certificate_type): | 235 certificate_type): |
230 self.server_version = version | 236 self.server_version = version |
231 self.random = random | 237 self.random = random |
232 self.session_id = session_id | 238 self.session_id = session_id |
233 self.cipher_suite = cipher_suite | 239 self.cipher_suite = cipher_suite |
234 self.certificate_type = certificate_type | 240 self.certificate_type = certificate_type |
235 self.compression_method = 0 | 241 self.compression_method = 0 |
236 return self | 242 return self |
(...skipping 29 matching lines...) Expand all Loading... |
266 w.add(self.compression_method, 1) | 272 w.add(self.compression_method, 1) |
267 | 273 |
268 extLength = 0 | 274 extLength = 0 |
269 if self.certificate_type and self.certificate_type != \ | 275 if self.certificate_type and self.certificate_type != \ |
270 CertificateType.x509: | 276 CertificateType.x509: |
271 extLength += 5 | 277 extLength += 5 |
272 | 278 |
273 if self.channel_id: | 279 if self.channel_id: |
274 extLength += 4 | 280 extLength += 4 |
275 | 281 |
| 282 if self.signed_cert_timestamps: |
| 283 extLength += 4 + len(self.signed_cert_timestamps) |
| 284 |
276 if extLength != 0: | 285 if extLength != 0: |
277 w.add(extLength, 2) | 286 w.add(extLength, 2) |
278 | 287 |
279 if self.certificate_type and self.certificate_type != \ | 288 if self.certificate_type and self.certificate_type != \ |
280 CertificateType.x509: | 289 CertificateType.x509: |
281 w.add(7, 2) | 290 w.add(7, 2) |
282 w.add(1, 2) | 291 w.add(1, 2) |
283 w.add(self.certificate_type, 1) | 292 w.add(self.certificate_type, 1) |
284 | 293 |
285 if self.channel_id: | 294 if self.channel_id: |
286 w.add(ExtensionType.channel_id, 2) | 295 w.add(ExtensionType.channel_id, 2) |
287 w.add(0, 2) | 296 w.add(0, 2) |
288 | 297 |
| 298 if self.signed_cert_timestamps: |
| 299 w.add(ExtensionType.signed_cert_timestamps, 2) |
| 300 w.addVarSeq(stringToBytes(self.signed_cert_timestamps), 1, 2) |
| 301 |
289 return HandshakeMsg.postWrite(self, w, trial) | 302 return HandshakeMsg.postWrite(self, w, trial) |
290 | 303 |
291 class Certificate(HandshakeMsg): | 304 class Certificate(HandshakeMsg): |
292 def __init__(self, certificateType): | 305 def __init__(self, certificateType): |
293 self.certificateType = certificateType | 306 self.certificateType = certificateType |
294 self.contentType = ContentType.handshake | 307 self.contentType = ContentType.handshake |
295 self.certChain = None | 308 self.certChain = None |
296 | 309 |
297 def create(self, certChain): | 310 def create(self, certChain): |
298 self.certChain = certChain | 311 self.certChain = certChain |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 def create(self, bytes): | 621 def create(self, bytes): |
609 self.bytes = bytes | 622 self.bytes = bytes |
610 return self | 623 return self |
611 | 624 |
612 def parse(self, p): | 625 def parse(self, p): |
613 self.bytes = p.bytes | 626 self.bytes = p.bytes |
614 return self | 627 return self |
615 | 628 |
616 def write(self): | 629 def write(self): |
617 return self.bytes | 630 return self.bytes |
OLD | NEW |