def startListening(self): if cmpSAM(self.session.samVersion, '3.2') >= 0: active = 8 else: active = 1 for i in range(0, active): self.openAccept()
def sendDestGenerate(self, samVersion, sigType=None): msg = 'DEST GENERATE' if cmpSAM(samVersion, '3.1') >= 0: msg += ' SIGNATURE_TYPE=%s' % (sigType and sigType or 'EdDSA_SHA512_Ed25519') msg += '\n' self.transport.write(msg.encode('utf-8'))
def postLookup(self, dest): # Help keep the session open if cmpSAM(self.factory.samVersion, '3.2') >= 0: self.startPinging() else: try: self.sender.transport.setTcpKeepAlive(1) except AttributeError as e: eprint(e) self.factory.sessionCreated(self, dest)
def sendSessionCreate(self, samVersion, style, id, privKey=None, localPort=None, options={}, sigType=None): msg = 'SESSION CREATE' msg += ' STYLE=%s' % style msg += ' ID=%s' % id msg += ' DESTINATION=%s' % (privKey if privKey else 'TRANSIENT') if cmpSAM(samVersion, '3.1') >= 0 and not privKey: msg += ' SIGNATURE_TYPE=%s' % (sigType and sigType or c.DEFAULT_SIGTYPE) if localPort: msg += ' FROM_PORT=%d' % localPort for key in options: msg += ' %s=%s' % (key, options[key]) msg += '\n' self.transport.write(msg)
def destGenerated(self, result=None, pub=None, priv=None, message=None): if result: # If the user didn't specify a SigType, try falling back if cmpSAM(self.factory.samVersion, '3.1') >= 0 and \ message.startswith('SIGNATURE_TYPE') and \ not self.factory.sigType: fallback = 'ECDSA_SHA256_P256' in message and 'DSA_SHA1' or 'ECDSA_SHA256_P256' eprint('Warning: %s, falling back to %s' % (message, fallback)) self.sender.sendDestGenerate(self.factory.samVersion, fallback) else: self.factory.resultNotOK(result, message) return self.factory.destGenerated(pub, priv) self.sender.transport.loseConnection()
def destGenerated(self, result=None, pub=None, priv=None, message=None): if result: # If the user didn't specify a SigType, try falling back if cmpSAM(self.factory.samVersion, '3.1') >= 0 and \ message.startswith('SIGNATURE_TYPE') and \ not self.factory.sigType: fallback = 'ECDSA_SHA256_P256' in message and 'DSA_SHA1' or 'ECDSA_SHA256_P256' eprint('Warning: %s, falling back to %s' % (message, fallback)) self.sender.sendDestGenerate( self.factory.samVersion, fallback) else: self.factory.resultNotOK(result, message) return self.factory.destGenerated(pub, priv) self.sender.transport.loseConnection()
def create(self, result, destination=None, message=None): if result != c.RESULT_OK: # If the user didn't specify a SigType, try falling back if cmpSAM(self.factory.samVersion, '3.1') >= 0 and \ message.startswith('SIGNATURE_TYPE') and \ not self.factory.sigType: fallback = 'ECDSA_SHA256_P256' in message and 'DSA_SHA1' or 'ECDSA_SHA256_P256' eprint('Warning: %s, falling back to %s' % (message, fallback)) self.sender.sendSessionCreate(self.factory.samVersion, self.factory.style, self.factory.nickname, self.factory.privKey, self.factory.localPort, self.factory.options, fallback) else: self.factory.resultNotOK(result, message) return self.factory.privKey = destination self.sender.sendNamingLookup('ME') self.currentRule = 'State_naming'
def sendSessionCreate(self, samVersion, style, id, privKey=None, localPort=None, options={}, sigType=None): msg = 'SESSION CREATE' msg += ' STYLE=%s' % style msg += ' ID=%s' % id msg += ' DESTINATION=%s' % (privKey if privKey else 'TRANSIENT') if cmpSAM(samVersion, '3.1') >= 0 and not privKey: msg += ' SIGNATURE_TYPE=%s' % (sigType and sigType or c.DEFAULT_SIGTYPE) if localPort: msg += ' FROM_PORT=%d' % localPort for key in options: msg += ' %s=%s' % (key, options[key]) msg += '\n' self.transport.write(msg.encode('utf-8'))
def create(self, result, destination=None, message=None): if result != c.RESULT_OK: # If the user didn't specify a SigType, try falling back if cmpSAM(self.factory.samVersion, '3.1') >= 0 and \ message.startswith('SIGNATURE_TYPE') and \ not self.factory.sigType: fallback = 'ECDSA_SHA256_P256' in message and 'DSA_SHA1' or 'ECDSA_SHA256_P256' eprint('Warning: %s, falling back to %s' % (message, fallback)) self.sender.sendSessionCreate( self.factory.samVersion, self.factory.style, self.factory.nickname, self.factory.privKey, self.factory.localPort, self.factory.options, fallback) else: self.factory.resultNotOK(result, message) return self.factory.privKey = destination self.sender.sendNamingLookup('ME') self.currentRule = 'State_naming'
def sendDestGenerate(self, samVersion, sigType=None): msg = 'DEST GENERATE' if cmpSAM(samVersion, '3.1') >= 0: msg += ' SIGNATURE_TYPE=%s' % (sigType and sigType or 'EdDSA_SHA512_Ed25519') msg += '\n' self.transport.write(msg)