#NEWLINE# def handleSignedBucketResponse( self , result , node , challenge ) : #NEWLINE# #INDENT# '\n        ???\n        `result` is an array and element 1 contains a dict.\n        Return None if any error occur and dont tell anyone.\n        ' #NEWLINE# logger ( self . sourceNode , 'handleSignedBucketResponse {}' . format ( str ( result ) ) ) #NEWLINE# nodeIdHex = node . id . encode ( 'hex' ) . upper ( ) #NEWLINE# if result [ 0 ] : #NEWLINE# #INDENT# if ( 'NACK' in result [ 1 ] ) : #NEWLINE# #INDENT# return ( False , self . handleSignedNACKResponse ( result , node , challenge ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( 'bucket' in result [ 1 ] ) and ( 'signature' in result [ 1 ] ) ) : #NEWLINE# #INDENT# cert_stored = self . searchForCertificate ( nodeIdHex ) #NEWLINE# if ( buIdReq == None ) : #NEWLINE# #INDENT# logger ( self . sourceNode , 'RETFALSENONE: Certificate for sender of bucket: {} not present in store' . format ( node ) ) #NEWLINE# return ( False , None ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# OpenSSL . crypto . verify ( cert_stored , result [ 1 ] [ 'signature' ] , challenge , 'sha256' ) #NEWLINE# self . router . addContact ( node ) #NEWLINE# newbucket = list ( ) #NEWLINE# for bucketnode in result [ 1 ] [ 'bucket' ] : #NEWLINE# #INDENT# buId = bucketnode [ 0 ] #NEWLINE# buIdHex = buId . encode ( 'hex' ) . upper ( ) #NEWLINE# buIp = bucketnode [ 1 ] #NEWLINE# buPort = bucketnode [ 2 ] #NEWLINE# if ( not self . certificateExists ( buIdHex ) ) : #NEWLINE# #INDENT# nonCertifiedNode = Node ( buId , buIp , buPort ) #NEWLINE# buIdDigest = digest ( str ( buIdHex ) ) #NEWLINE# buIdReq = '{}cert' . format ( Node ( buIdDigest ) ) #NEWLINE# self . callCertFindValue ( nonCertifiedNode , buIdReq ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# newbucket . append ( bucketnode ) #NEWLINE# #UNINDENT# #UNINDENT# return ( result [ 0 ] , newbucket ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# logger ( self . sourceNode , 'RETFALSENONE: Bad signature for sender of bucket: {}' . format ( node ) ) #NEWLINE# return ( False , None ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( not result [ 1 ] [ 'signature' ] ) : #NEWLINE# #INDENT# logger ( self . sourceNode , 'RETFALSENONE: Signature not present for sender of bucket: {}' . format ( node ) ) #NEWLINE# #UNINDENT# return ( False , None ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# logger ( self . sourceNode , 'RETFALSENONE: No response from {}, removing from bucket' . format ( node ) ) #NEWLINE# self . router . removeContact ( node ) #NEWLINE# #UNINDENT# return ( False , None )