Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: third_party/tlslite/tlslite/messages.py

Issue 1283373002: Implement extended master secret in tlslite (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address davidben's comments Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Authors: 1 # Authors:
2 # Trevor Perrin 2 # Trevor Perrin
3 # Google - handling CertificateRequest.certificate_types 3 # Google - handling CertificateRequest.certificate_types
4 # Google (adapted by Sam Rushing and Marcelo Fernandez) - NPN support 4 # Google (adapted by Sam Rushing and Marcelo Fernandez) - NPN support
5 # Dimitris Moraitis - Anon ciphersuites 5 # Dimitris Moraitis - Anon ciphersuites
6 # Yngve Pettersen (ported by Paul Sokolovsky) - TLS 1.2 6 # Yngve Pettersen (ported by Paul Sokolovsky) - TLS 1.2
7 # 7 #
8 # See the LICENSE file for legal information regarding use of this file. 8 # See the LICENSE file for legal information regarding use of this file.
9 9
10 """Classes representing TLS messages.""" 10 """Classes representing TLS messages."""
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 w = Writer() 85 w = Writer()
86 w.add(self.level, 1) 86 w.add(self.level, 1)
87 w.add(self.description, 1) 87 w.add(self.description, 1)
88 return w.bytes 88 return w.bytes
89 89
90 90
91 class HandshakeMsg(object): 91 class HandshakeMsg(object):
92 def __init__(self, handshakeType): 92 def __init__(self, handshakeType):
93 self.contentType = ContentType.handshake 93 self.contentType = ContentType.handshake
94 self.handshakeType = handshakeType 94 self.handshakeType = handshakeType
95 self.rawMessage = bytearray(0)
davidben 2015/08/17 17:10:22 This and the bit below look like they're not neede
nharper 2015/08/18 00:03:31 Done.
95 96
96 def postWrite(self, w): 97 def postWrite(self, w):
97 headerWriter = Writer() 98 headerWriter = Writer()
98 headerWriter.add(self.handshakeType, 1) 99 headerWriter.add(self.handshakeType, 1)
99 headerWriter.add(len(w.bytes), 3) 100 headerWriter.add(len(w.bytes), 3)
100 return headerWriter.bytes + w.bytes 101 self.rawMessage = headerWriter.bytes + w.bytes
102 return self.rawMessage
101 103
102 class ClientHello(HandshakeMsg): 104 class ClientHello(HandshakeMsg):
103 def __init__(self, ssl2=False): 105 def __init__(self, ssl2=False):
104 HandshakeMsg.__init__(self, HandshakeType.client_hello) 106 HandshakeMsg.__init__(self, HandshakeType.client_hello)
105 self.ssl2 = ssl2 107 self.ssl2 = ssl2
106 self.client_version = (0,0) 108 self.client_version = (0,0)
107 self.random = bytearray(32) 109 self.random = bytearray(32)
108 self.session_id = bytearray(0) 110 self.session_id = bytearray(0)
109 self.cipher_suites = [] # a list of 16-bit values 111 self.cipher_suites = [] # a list of 16-bit values
110 self.certificate_types = [CertificateType.x509] 112 self.certificate_types = [CertificateType.x509]
111 self.compression_methods = [] # a list of 8-bit values 113 self.compression_methods = [] # a list of 8-bit values
112 self.srp_username = None # a string 114 self.srp_username = None # a string
113 self.tack = False 115 self.tack = False
114 self.supports_npn = False 116 self.supports_npn = False
115 self.server_name = bytearray(0) 117 self.server_name = bytearray(0)
116 self.channel_id = False 118 self.channel_id = False
119 self.extended_master_secret = False
117 self.support_signed_cert_timestamps = False 120 self.support_signed_cert_timestamps = False
118 self.status_request = False 121 self.status_request = False
119 122
120 def create(self, version, random, session_id, cipher_suites, 123 def create(self, version, random, session_id, cipher_suites,
121 certificate_types=None, srpUsername=None, 124 certificate_types=None, srpUsername=None,
122 tack=False, supports_npn=False, serverName=None): 125 tack=False, supports_npn=False, serverName=None):
123 self.client_version = version 126 self.client_version = version
124 self.random = random 127 self.random = random
125 self.session_id = session_id 128 self.session_id = session_id
126 self.cipher_suites = cipher_suites 129 self.cipher_suites = cipher_suites
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 while 1: 181 while 1:
179 if p2.atLengthCheck(): 182 if p2.atLengthCheck():
180 break # no host_name, oh well 183 break # no host_name, oh well
181 name_type = p2.get(1) 184 name_type = p2.get(1)
182 hostNameBytes = p2.getVarBytes(2) 185 hostNameBytes = p2.getVarBytes(2)
183 if name_type == NameType.host_name: 186 if name_type == NameType.host_name:
184 self.server_name = hostNameBytes 187 self.server_name = hostNameBytes
185 break 188 break
186 elif extType == ExtensionType.channel_id: 189 elif extType == ExtensionType.channel_id:
187 self.channel_id = True 190 self.channel_id = True
191 elif extType == ExtensionType.extended_master_secret:
192 self.extended_master_secret = True
188 elif extType == ExtensionType.signed_cert_timestamps: 193 elif extType == ExtensionType.signed_cert_timestamps:
189 if extLength: 194 if extLength:
190 raise SyntaxError() 195 raise SyntaxError()
191 self.support_signed_cert_timestamps = True 196 self.support_signed_cert_timestamps = True
192 elif extType == ExtensionType.status_request: 197 elif extType == ExtensionType.status_request:
193 # Extension contents are currently ignored. 198 # Extension contents are currently ignored.
194 # According to RFC 6066, this is not strictly forbidden 199 # According to RFC 6066, this is not strictly forbidden
195 # (although it is suboptimal): 200 # (although it is suboptimal):
196 # Servers that receive a client hello containing the 201 # Servers that receive a client hello containing the
197 # "status_request" extension MAY return a suitable 202 # "status_request" extension MAY return a suitable
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 self.server_version = (0,0) 265 self.server_version = (0,0)
261 self.random = bytearray(32) 266 self.random = bytearray(32)
262 self.session_id = bytearray(0) 267 self.session_id = bytearray(0)
263 self.cipher_suite = 0 268 self.cipher_suite = 0
264 self.certificate_type = CertificateType.x509 269 self.certificate_type = CertificateType.x509
265 self.compression_method = 0 270 self.compression_method = 0
266 self.tackExt = None 271 self.tackExt = None
267 self.next_protos_advertised = None 272 self.next_protos_advertised = None
268 self.next_protos = None 273 self.next_protos = None
269 self.channel_id = False 274 self.channel_id = False
275 self.extended_master_secret = False
270 self.signed_cert_timestamps = None 276 self.signed_cert_timestamps = None
271 self.status_request = False 277 self.status_request = False
272 278
273 def create(self, version, random, session_id, cipher_suite, 279 def create(self, version, random, session_id, cipher_suite,
274 certificate_type, tackExt, next_protos_advertised): 280 certificate_type, tackExt, next_protos_advertised):
275 self.server_version = version 281 self.server_version = version
276 self.random = random 282 self.random = random
277 self.session_id = session_id 283 self.session_id = session_id
278 self.cipher_suite = cipher_suite 284 self.cipher_suite = cipher_suite
279 self.certificate_type = certificate_type 285 self.certificate_type = certificate_type
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 w2.add(len(b), 2) 357 w2.add(len(b), 2)
352 w2.bytes += b 358 w2.bytes += b
353 if self.next_protos_advertised is not None: 359 if self.next_protos_advertised is not None:
354 encoded_next_protos_advertised = self.__next_protos_encoded() 360 encoded_next_protos_advertised = self.__next_protos_encoded()
355 w2.add(ExtensionType.supports_npn, 2) 361 w2.add(ExtensionType.supports_npn, 2)
356 w2.add(len(encoded_next_protos_advertised), 2) 362 w2.add(len(encoded_next_protos_advertised), 2)
357 w2.addFixSeq(encoded_next_protos_advertised, 1) 363 w2.addFixSeq(encoded_next_protos_advertised, 1)
358 if self.channel_id: 364 if self.channel_id:
359 w2.add(ExtensionType.channel_id, 2) 365 w2.add(ExtensionType.channel_id, 2)
360 w2.add(0, 2) 366 w2.add(0, 2)
367 if self.extended_master_secret:
368 w2.add(ExtensionType.extended_master_secret, 2)
369 w2.add(0, 2)
361 if self.signed_cert_timestamps: 370 if self.signed_cert_timestamps:
362 w2.add(ExtensionType.signed_cert_timestamps, 2) 371 w2.add(ExtensionType.signed_cert_timestamps, 2)
363 w2.addVarSeq(bytearray(self.signed_cert_timestamps), 1, 2) 372 w2.addVarSeq(bytearray(self.signed_cert_timestamps), 1, 2)
364 if self.status_request: 373 if self.status_request:
365 w2.add(ExtensionType.status_request, 2) 374 w2.add(ExtensionType.status_request, 2)
366 w2.add(0, 2) 375 w2.add(0, 2)
367 if len(w2.bytes): 376 if len(w2.bytes):
368 w.add(len(w2.bytes), 2) 377 w.add(len(w2.bytes), 2)
369 w.bytes += w2.bytes 378 w.bytes += w2.bytes
370 return self.postWrite(w) 379 return self.postWrite(w)
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 newMsg = ApplicationData().create(self.bytes[:1]) 805 newMsg = ApplicationData().create(self.bytes[:1])
797 self.bytes = self.bytes[1:] 806 self.bytes = self.bytes[1:]
798 return newMsg 807 return newMsg
799 808
800 def parse(self, p): 809 def parse(self, p):
801 self.bytes = p.bytes 810 self.bytes = p.bytes
802 return self 811 return self
803 812
804 def write(self): 813 def write(self):
805 return self.bytes 814 return self.bytes
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698