def __init__(self,port,mode,fsprivate_key,fspublic_key,fcpublic_key): """ Initializing the Server Socket and binding it on the port. param:port The port number on which the server is listening. param:mode The mode(Trusted/Untrusted) of Server. """ self.host ="localhost" self.port = port self.mode = mode self.fsprivate_key = fsprivate_key self.fspublic_key = fspublic_key self.fcpublic_key = fcpublic_key serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) try: serversocket.bind((self.host,self.port)) except socket.error as error: print ("Socket binding failed with %s",error) exit() # Allowing only one(1) Client to connect. count=0 while True: serversocket.listen(1) if count==0: count+=1 Common.gen_rsa('server') #Generate the RSA Keys(if not exists) (clientsocket,clientaddress) = serversocket.accept() self.recv_data(clientsocket) elif count==1: self.normallisten(serversocket) break
def rsa(self): """ RSA wrapper. If the file <client_private.pem> or <client_public.pem> exists,does not creates them. """ Common.gen_rsa('client')