<s> """<STR_LIT>""" <EOL> from . utils . compat import * <EOL> from . mathtls import * <EOL> from . constants import * <EOL> class Session : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . masterSecret = createByteArraySequence ( [ ] ) <EOL> self . sessionID = createByteArraySequence ( [ ] ) <EOL> self . cipherSuite = <NUM_LIT:0> <EOL> self . srpUsername = None <EOL> self . sharedKeyUsername = None <EOL> self . clientCertChain = None <EOL> self . serverCertChain = None <EOL> self . resumable = False <EOL> self . sharedKey = False <EOL> def _clone ( self ) : <EOL> other = Session ( ) <EOL> other . masterSecret = self . masterSecret <EOL> other . sessionID = self . sessionID <EOL> other . cipherSuite = self . cipherSuite <EOL> other . srpUsername = self . srpUsername <EOL> other . sharedKeyUsername = self . sharedKeyUsername <EOL> other . clientCertChain = self . clientCertChain <EOL> other . serverCertChain = self . serverCertChain <EOL> other . resumable = self . resumable <EOL> other . sharedKey = self . sharedKey <EOL> return other <EOL> def _calcMasterSecret ( self , version , premasterSecret , clientRandom , <EOL> serverRandom ) : <EOL> if version == ( <NUM_LIT:3> , <NUM_LIT:0> ) : <EOL> self . masterSecret = PRF_SSL ( premasterSecret , <EOL> concatArrays ( clientRandom , serverRandom ) , <NUM_LIT> ) <EOL> elif version in ( ( <NUM_LIT:3> , <NUM_LIT:1> ) , ( <NUM_LIT:3> , <NUM_LIT:2> ) ) : <EOL> self . masterSecret = PRF ( premasterSecret , "<STR_LIT>" , <EOL> concatArrays ( clientRandom , serverRandom ) , <NUM_LIT> ) <EOL> else : <EOL> raise AssertionError ( ) <EOL> def valid ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . resumable or self . sharedKey <EOL> def _setResumable ( self , boolean ) : <EOL> if not self . sharedKey : <EOL> if ( not boolean ) or ( boolean and self . sessionID ) : <EOL> self . resumable = boolean <EOL> def getCipherName ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . cipherSuite in CipherSuite . aes128Suites : <EOL> return "<STR_LIT>" <EOL> elif self . cipherSuite in CipherSuite . aes256Suites : <EOL> return "<STR_LIT>" <EOL> elif self . cipherSuite in CipherSuite . rc4Suites : <EOL> return "<STR_LIT>" <EOL> elif self . cipherSuite in CipherSuite . tripleDESSuites : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return None <EOL> def _createSharedKey ( self , sharedKeyUsername , sharedKey ) : <EOL> if len ( sharedKeyUsername ) > <NUM_LIT:16> : <EOL> raise ValueError ( ) <EOL> if len ( sharedKey ) > <NUM_LIT> : <EOL> raise ValueError ( ) <EOL> self . sharedKeyUsername = sharedKeyUsername <EOL> self . sessionID = createByteArrayZeros ( <NUM_LIT:16> ) <EOL> for x in range ( len ( sharedKeyUsername ) ) : <EOL> self . sessionID [ x ] = ord ( sharedKeyUsername [ x ] ) <EOL> premasterSecret = createByteArrayZeros ( <NUM_LIT> ) <EOL> sharedKey = chr ( len ( sharedKey ) ) + sharedKey <EOL> for x in range ( <NUM_LIT> ) : <EOL> premasterSecret [ x ] = ord ( sharedKey [ x % len ( sharedKey ) ] ) <EOL> self . masterSecret = PRF ( premasterSecret , "<STR_LIT>" , <EOL> createByteArraySequence ( [ ] ) , <NUM_LIT> ) <EOL> self . sharedKey = True <EOL> return self </s>
