| OLD | NEW |
| 1 # Authors: | 1 # Authors: |
| 2 # Trevor Perrin | 2 # Trevor Perrin |
| 3 # Google (adapted by Sam Rushing) - NPN support | 3 # Google (adapted by Sam Rushing) - NPN support |
| 4 # Martin von Loewis - python 3 port | 4 # Martin von Loewis - python 3 port |
| 5 # | 5 # |
| 6 # 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. |
| 7 | 7 |
| 8 """Helper class for TLSConnection.""" | 8 """Helper class for TLSConnection.""" |
| 9 from __future__ import generators | 9 from __future__ import generators |
| 10 | 10 |
| 11 from .utils.compat import * | 11 from .utils.compat import * |
| 12 from .utils.cryptomath import * | 12 from .utils.cryptomath import * |
| 13 from .utils.cipherfactory import createAES, createRC4, createTripleDES | 13 from .utils.cipherfactory import createAES, createRC4, createTripleDES |
| 14 from .utils.codec import * | 14 from .utils.codec import * |
| 15 from .errors import * | 15 from .errors import * |
| 16 from .messages import * | 16 from .messages import * |
| 17 from .mathtls import * | 17 from .mathtls import * |
| 18 from .constants import * | 18 from .constants import * |
| 19 from .utils.cryptomath import getRandomBytes | 19 from .utils.cryptomath import getRandomBytes |
| 20 | 20 |
| 21 import socket | 21 import socket |
| 22 import struct |
| 22 import errno | 23 import errno |
| 23 import traceback | 24 import traceback |
| 24 | 25 |
| 25 class _ConnectionState(object): | 26 class _ConnectionState(object): |
| 26 def __init__(self): | 27 def __init__(self): |
| 27 self.macContext = None | 28 self.macContext = None |
| 28 self.encContext = None | 29 self.encContext = None |
| 29 self.seqnum = 0 | 30 self.seqnum = 0 |
| 30 | 31 |
| 31 def getSeqNumBytes(self): | 32 def getSeqNumBytes(self): |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 self.session.resumable = False | 517 self.session.resumable = False |
| 517 | 518 |
| 518 | 519 |
| 519 def _sendError(self, alertDescription, errorStr=None): | 520 def _sendError(self, alertDescription, errorStr=None): |
| 520 alert = Alert().create(alertDescription, AlertLevel.fatal) | 521 alert = Alert().create(alertDescription, AlertLevel.fatal) |
| 521 for result in self._sendMsg(alert): | 522 for result in self._sendMsg(alert): |
| 522 yield result | 523 yield result |
| 523 self._shutdown(False) | 524 self._shutdown(False) |
| 524 raise TLSLocalAlert(alert, errorStr) | 525 raise TLSLocalAlert(alert, errorStr) |
| 525 | 526 |
| 527 def _abruptClose(self, reset=False): |
| 528 if reset: |
| 529 #Set an SO_LINGER timeout of 0 to send a TCP RST. |
| 530 self.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, |
| 531 struct.pack('ii', 1, 0)) |
| 532 self._shutdown(False) |
| 533 |
| 526 def _sendMsgs(self, msgs): | 534 def _sendMsgs(self, msgs): |
| 527 randomizeFirstBlock = True | 535 randomizeFirstBlock = True |
| 528 for msg in msgs: | 536 for msg in msgs: |
| 529 for result in self._sendMsg(msg, randomizeFirstBlock): | 537 for result in self._sendMsg(msg, randomizeFirstBlock): |
| 530 yield result | 538 yield result |
| 531 randomizeFirstBlock = True | 539 randomizeFirstBlock = True |
| 532 | 540 |
| 533 def _sendMsg(self, msg, randomizeFirstBlock = True): | 541 def _sendMsg(self, msg, randomizeFirstBlock = True): |
| 534 #Whenever we're connected and asked to send an app data message, | 542 #Whenever we're connected and asked to send an app data message, |
| 535 #we first send the first byte of the message. This prevents | 543 #we first send the first byte of the message. This prevents |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1144 imac_md5.update(compatHMAC(label + masterSecret + bytearray([0x36]*48))) | 1152 imac_md5.update(compatHMAC(label + masterSecret + bytearray([0x36]*48))) |
| 1145 imac_sha.update(compatHMAC(label + masterSecret + bytearray([0x36]*40))) | 1153 imac_sha.update(compatHMAC(label + masterSecret + bytearray([0x36]*40))) |
| 1146 | 1154 |
| 1147 md5Bytes = MD5(masterSecret + bytearray([0x5c]*48) + \ | 1155 md5Bytes = MD5(masterSecret + bytearray([0x5c]*48) + \ |
| 1148 bytearray(imac_md5.digest())) | 1156 bytearray(imac_md5.digest())) |
| 1149 shaBytes = SHA1(masterSecret + bytearray([0x5c]*40) + \ | 1157 shaBytes = SHA1(masterSecret + bytearray([0x5c]*40) + \ |
| 1150 bytearray(imac_sha.digest())) | 1158 bytearray(imac_sha.digest())) |
| 1151 | 1159 |
| 1152 return md5Bytes + shaBytes | 1160 return md5Bytes + shaBytes |
| 1153 | 1161 |
| OLD | NEW |