OLD | NEW |
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 # | 6 # |
7 # See the LICENSE file for legal information regarding use of this file. | 7 # See the LICENSE file for legal information regarding use of this file. |
8 | 8 |
9 """Classes representing TLS messages.""" | 9 """Classes representing TLS messages.""" |
10 | 10 |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 self.srp_B = bytesToNumber(p.getVarBytes(2)) | 526 self.srp_B = bytesToNumber(p.getVarBytes(2)) |
527 if self.cipherSuite in CipherSuite.srpCertSuites: | 527 if self.cipherSuite in CipherSuite.srpCertSuites: |
528 self.signature = p.getVarBytes(2) | 528 self.signature = p.getVarBytes(2) |
529 elif self.cipherSuite in CipherSuite.anonSuites: | 529 elif self.cipherSuite in CipherSuite.anonSuites: |
530 self.dh_p = bytesToNumber(p.getVarBytes(2)) | 530 self.dh_p = bytesToNumber(p.getVarBytes(2)) |
531 self.dh_g = bytesToNumber(p.getVarBytes(2)) | 531 self.dh_g = bytesToNumber(p.getVarBytes(2)) |
532 self.dh_Ys = bytesToNumber(p.getVarBytes(2)) | 532 self.dh_Ys = bytesToNumber(p.getVarBytes(2)) |
533 p.stopLengthCheck() | 533 p.stopLengthCheck() |
534 return self | 534 return self |
535 | 535 |
536 def write(self): | 536 def write_params(self): |
537 w = Writer() | 537 w = Writer() |
538 if self.cipherSuite in CipherSuite.srpAllSuites: | 538 if self.cipherSuite in CipherSuite.srpAllSuites: |
539 w.addVarSeq(numberToByteArray(self.srp_N), 1, 2) | 539 w.addVarSeq(numberToByteArray(self.srp_N), 1, 2) |
540 w.addVarSeq(numberToByteArray(self.srp_g), 1, 2) | 540 w.addVarSeq(numberToByteArray(self.srp_g), 1, 2) |
541 w.addVarSeq(self.srp_s, 1, 1) | 541 w.addVarSeq(self.srp_s, 1, 1) |
542 w.addVarSeq(numberToByteArray(self.srp_B), 1, 2) | 542 w.addVarSeq(numberToByteArray(self.srp_B), 1, 2) |
543 if self.cipherSuite in CipherSuite.srpCertSuites: | 543 elif self.cipherSuite in CipherSuite.dhAllSuites: |
544 w.addVarSeq(self.signature, 1, 2) | |
545 elif self.cipherSuite in CipherSuite.anonSuites: | |
546 w.addVarSeq(numberToByteArray(self.dh_p), 1, 2) | 544 w.addVarSeq(numberToByteArray(self.dh_p), 1, 2) |
547 w.addVarSeq(numberToByteArray(self.dh_g), 1, 2) | 545 w.addVarSeq(numberToByteArray(self.dh_g), 1, 2) |
548 w.addVarSeq(numberToByteArray(self.dh_Ys), 1, 2) | 546 w.addVarSeq(numberToByteArray(self.dh_Ys), 1, 2) |
549 if self.cipherSuite in []: # TODO support for signed_params | 547 else: |
550 w.addVarSeq(self.signature, 1, 2) | 548 assert(False) |
| 549 return w.bytes |
| 550 |
| 551 def write(self): |
| 552 w = Writer() |
| 553 w.bytes += self.write_params() |
| 554 if self.cipherSuite in CipherSuite.certAllSuites: |
| 555 w.addVarSeq(self.signature, 1, 2) |
551 return self.postWrite(w) | 556 return self.postWrite(w) |
552 | 557 |
553 def hash(self, clientRandom, serverRandom): | 558 def hash(self, clientRandom, serverRandom): |
554 oldCipherSuite = self.cipherSuite | 559 bytes = clientRandom + serverRandom + self.write_params() |
555 self.cipherSuite = None | 560 return MD5(bytes) + SHA1(bytes) |
556 try: | |
557 bytes = clientRandom + serverRandom + self.write()[4:] | |
558 return MD5(bytes) + SHA1(bytes) | |
559 finally: | |
560 self.cipherSuite = oldCipherSuite | |
561 | 561 |
562 class ServerHelloDone(HandshakeMsg): | 562 class ServerHelloDone(HandshakeMsg): |
563 def __init__(self): | 563 def __init__(self): |
564 HandshakeMsg.__init__(self, HandshakeType.server_hello_done) | 564 HandshakeMsg.__init__(self, HandshakeType.server_hello_done) |
565 | 565 |
566 def create(self): | 566 def create(self): |
567 return self | 567 return self |
568 | 568 |
569 def parse(self, p): | 569 def parse(self, p): |
570 p.startLengthCheck(3) | 570 p.startLengthCheck(3) |
(...skipping 29 matching lines...) Expand all Loading... |
600 if self.cipherSuite in CipherSuite.srpAllSuites: | 600 if self.cipherSuite in CipherSuite.srpAllSuites: |
601 self.srp_A = bytesToNumber(p.getVarBytes(2)) | 601 self.srp_A = bytesToNumber(p.getVarBytes(2)) |
602 elif self.cipherSuite in CipherSuite.certSuites: | 602 elif self.cipherSuite in CipherSuite.certSuites: |
603 if self.version in ((3,1), (3,2)): | 603 if self.version in ((3,1), (3,2)): |
604 self.encryptedPreMasterSecret = p.getVarBytes(2) | 604 self.encryptedPreMasterSecret = p.getVarBytes(2) |
605 elif self.version == (3,0): | 605 elif self.version == (3,0): |
606 self.encryptedPreMasterSecret = \ | 606 self.encryptedPreMasterSecret = \ |
607 p.getFixBytes(len(p.bytes)-p.index) | 607 p.getFixBytes(len(p.bytes)-p.index) |
608 else: | 608 else: |
609 raise AssertionError() | 609 raise AssertionError() |
610 elif self.cipherSuite in CipherSuite.anonSuites: | 610 elif self.cipherSuite in CipherSuite.dhAllSuites: |
611 self.dh_Yc = bytesToNumber(p.getVarBytes(2)) | 611 self.dh_Yc = bytesToNumber(p.getVarBytes(2)) |
612 else: | 612 else: |
613 raise AssertionError() | 613 raise AssertionError() |
614 p.stopLengthCheck() | 614 p.stopLengthCheck() |
615 return self | 615 return self |
616 | 616 |
617 def write(self): | 617 def write(self): |
618 w = Writer() | 618 w = Writer() |
619 if self.cipherSuite in CipherSuite.srpAllSuites: | 619 if self.cipherSuite in CipherSuite.srpAllSuites: |
620 w.addVarSeq(numberToByteArray(self.srp_A), 1, 2) | 620 w.addVarSeq(numberToByteArray(self.srp_A), 1, 2) |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 newMsg = ApplicationData().create(self.bytes[:1]) | 756 newMsg = ApplicationData().create(self.bytes[:1]) |
757 self.bytes = self.bytes[1:] | 757 self.bytes = self.bytes[1:] |
758 return newMsg | 758 return newMsg |
759 | 759 |
760 def parse(self, p): | 760 def parse(self, p): |
761 self.bytes = p.bytes | 761 self.bytes = p.bytes |
762 return self | 762 return self |
763 | 763 |
764 def write(self): | 764 def write(self): |
765 return self.bytes | 765 return self.bytes |
OLD | NEW |