#NEWLINE# def rpc_ping( self , sender , nodeid , challenge , signature , certString = None ) : #NEWLINE# #INDENT# '\n        This function is ???\n        Verify `certString` certificate with CA from trust store.\n        Verify `signature` of `challenge`.\n        Store certificate if `certString` is verified.\n\n        ' #NEWLINE# source = Node ( nodeid , sender [ 0 ] , sender [ 1 ] ) #NEWLINE# nodeIdHex = nodeid . encode ( 'hex' ) . upper ( ) #NEWLINE# if ( certString != None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# cert = OpenSSL . crypto . load_certificate ( OpenSSL . crypto . FILETYPE_PEM , certString ) #NEWLINE# store_ctx = OpenSSL . crypto . X509StoreContext ( self . trustedStore , cert ) #NEWLINE# store_ctx . verify_certificate ( ) #NEWLINE# fingerprint = cert . digest ( 'sha256' ) #NEWLINE# id = fingerprint . replace ( ':' , '' ) [ ( - 40 ) : ] #NEWLINE# if ( id != nodeIdHex ) : #NEWLINE# #INDENT# logger ( self . sourceNode , 'RETNONE: Explicit certificate in ping from {} does not match nodeid' . format ( source ) ) #NEWLINE# return None #NEWLINE# #UNINDENT# sourceNodeIdHex = self . sourceNode . id . encode ( 'hex' ) . upper ( ) #NEWLINE# payload = '{}{}' . format ( sourceNodeIdHex , challenge ) #NEWLINE# OpenSSL . crypto . verify ( cert , signature , payload , 'sha256' ) #NEWLINE# if ( not self . certificateExists ( nodeIdHex ) ) : #NEWLINE# #INDENT# self . storeCert ( certString , nodeIdHex ) #NEWLINE# self . transferKeyValues ( source ) #NEWLINE# #UNINDENT# #UNINDENT# except : #NEWLINE# #INDENT# logger ( self . sourceNode , 'RETNONE: Bad signature for sender of ping with explicit certificate: {}' . format ( source ) ) #NEWLINE# return None #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# cert_stored = self . searchForCertificate ( nodeIdHex ) #NEWLINE# if ( cert_stored == None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# private = OpenSSL . crypto . load_privatekey ( OpenSSL . crypto . FILETYPE_PEM , self . priv_key , '' ) #NEWLINE# signature = OpenSSL . crypto . sign ( private , challenge , 'sha256' ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# logger ( self . sourceNode , 'RETNONE: Failed make signature for ping' ) #NEWLINE# return None #NEWLINE# #UNINDENT# logger ( self . sourceNode , 'Certificate for {} not found in store' . format ( source ) ) #NEWLINE# return { #NEWLINE# #INDENT# 'NACK' : None , #NEWLINE# 'signature' : signature , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# sourceNodeIdHex = self . sourceNode . id . encode ( 'hex' ) . upper ( ) #NEWLINE# payload = '{}{}' . format ( sourceNodeIdHex , challenge ) #NEWLINE# OpenSSL . crypto . verify ( cert_stored , signature , payload , 'sha256' ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# logger ( self . sourceNode , 'RETNONE: Bad signature for sender of ping: {}' . format ( source ) ) #NEWLINE# return None #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# private = OpenSSL . crypto . load_privatekey ( OpenSSL . crypto . FILETYPE_PEM , self . priv_key , '' ) #NEWLINE# signature = OpenSSL . crypto . sign ( private , challenge , 'sha256' ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# logger ( self . sourceNode , 'RETNONE: Signing of rpc_ping failed' ) #NEWLINE# return None #NEWLINE# #UNINDENT# return { #NEWLINE# #INDENT# 'id' : self . sourceNode . id , #NEWLINE# 'signature' : signature , #NEWLINE# #UNINDENT# }