def _handshakeStart(self, client): self._handshake_in_progress = True self._client = client self._handshake_md5 = md5.md5() self._handshake_sha = sha.sha() self._handshake_sha256 = sha256.sha256() self._handshakeBuffer = [] self.allegedSharedKeyUsername = None self.allegedSrpUsername = None self._refCount = 1
def __init__(self, sock): self.sock = sock #My session object (Session instance; read-only) self.session = None #Am I a client or server? self._client = None #Is a handshake in progress? self._handshake_in_progress = False #Is renegotiation of the connection allowed self.renegotiationAllowed = True self.renegotiationStarted = False self.peer_verify_data = None self.our_verify_data = None #Application data allowed to flow? self._application_enabled = False self.do_false_start = False # Application data queue when application data is not eneabled self._application_queue = None #Buffers for processing messages self._handshakeBuffer = [] self._readBuffer = "" #Handshake digests self._handshake_md5 = md5.md5() self._handshake_sha = sha.sha() self._handshake_sha256 = sha256.sha256() #TLS Protocol Version self.version = (0,0) #read-only self.rec_version = (3,0) self.detected_version = (0,0) self._versionCheck = False #Once we choose a version, this is True #Current and Pending connection states self._writeState = _ConnectionState() self._readState = _ConnectionState() self._pendingWriteState = _ConnectionState() self._pendingReadState = _ConnectionState() #Is the connection open? self.closed = True #read-only self._refCount = 0 #Used to trigger closure #Is this a resumed (or shared-key) session? self.resumed = False #read-only #What username did the client claim in his handshake? self.allegedSharedKeyUsername = None self.allegedSrpUsername = None #On a call to close(), do we close the socket? (writeable) self.closeSocket = False #If the socket is abruptly closed, do we ignore it #and pretend the connection was shut down properly? (writeable) self.ignoreAbruptClose = False #Fault we will induce, for testing purposes self.fault = None self.received_SNI_alert = False self.extra_padding_bytes = 0 self.use_partial_app_record = False self.part_app_record_len = 0 self.part_app_record_collect = False self.collected_records = None
def generateSecondHash(self, string): tohash = str(MAGIC_STRING_SECOND_HASH + string) hash = sha256.sha256(tohash).digest() return hash
def generateFirstHash(self, string): tohash = str(MAGIC_STRING_FIRST_HASH_A + string + MAGIC_STRING_FIRST_HASH_B) hash = sha256.sha256(tohash).digest() return hash