Exemplo n.º 1
0
def main():
    # Creating Connection to Database
    conn = create_connection()
    # Binding Server
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    print("Starting AuthClient on port %s",
          str(constants.KDC_CLIENT_VERIFICATION[1]))
    sock.bind(constants.KDC_CLIENT_VERIFICATION)
    sock.listen()
    while (True):
        print("Waiting for a connection....")
        connection, client_addr = sock.accept()

        # Receiving Input
        input_stream = connection.recv(4096)
        request = crypto.unserial(input_stream)
        user_id = request[constants.USER_ID]
        password = request[constants.PASSWORD]

        # Verifies Client Details with Database
        client_secret_key = authenticate(user_id, password, conn)
        request[constants.USER_ID] = user_id
        if client_secret_key == 0:
            request[constants.STATUS] = constants.FAILURE
        else:
            request[constants.STATUS] = constants.ACCOUNT_PRESENT

        # Sending Response
        data_stream = crypto.serial(request)
        connection.send(data_stream)
        connection.close()
Exemplo n.º 2
0
def main():
    # Connecting with Database
    clear()
    database_init()
    # Bind and wait for Incoming Connection
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    print("Starting AuthServer on port %s", str(constants.KDC[1]))
    sock.bind(constants.KDC)
    sock.listen()

    while True:
        print("Waiting for a connection....")
        connection, client_addr = sock.accept()
        try:
            print("Connection From ", client_addr)
            # Receiving Data
            data = connection.recv(4096)
            user_request = crypto.unserial(data)

            # Handling Requests
            if user_request[constants.REQUEST_TYPE] == constants.INIT:
                handle_init_request(user_request, connection)
            else:
                handle_connection_request(user_request, connection,
                                          client_addr)
        finally:
            print("Response Sent")
        connection.close()
Exemplo n.º 3
0
 def cp(self, filename, newpath):
     # Out: ACK
     data = self.client.root.cp(filename, newpath)
     if data == None:
         return None
     data = crypto.decrypt(data, self.__session_key)
     data = crypto.unserial(data)
     print(colored('RPC Procedure Success', 'green'))
     return data
Exemplo n.º 4
0
 def cat(self, file_name):
     # Out : list(String)
     data = self.client.root.cat(file_name)
     if data == None:
         return None
     data = crypto.decrypt(data, self.__session_key)
     data = crypto.unserial(data)
     print(colored('RPC Procedure Success', 'green'))
     return data
Exemplo n.º 5
0
 def make_dir(self, folder_name):
     # Out: Path
     data = self.client.root.make_dir(folder_name)
     if data == None:
         return None
     data = crypto.decrypt(data, self.__session_key)
     data = crypto.unserial(data)
     print(colored('RPC Procedure Success', 'green'))
     return data
Exemplo n.º 6
0
 def cd_backward(self):
     # Out: Path List
     data = self.client.root.cdbackward()
     if data == None:
         return None
     data = crypto.decrypt(data, self.__session_key)
     data = crypto.unserial(data)
     print(colored('RPC Procedure Success', 'green'))
     return data
Exemplo n.º 7
0
 def ls(self):
     # Out : list of tuples [(name,1 for dir 0 for file)]
     data_en_stream = self.client.root.ls()
     if (data_en_stream == None):
         return None
     data_stream = crypto.decrypt(data_en_stream, self.__session_key)
     data = crypto.unserial(data_stream)
     print(colored('RPC Procedure Success', 'green'))
     return data
Exemplo n.º 8
0
def get_session_key(file_server_id, file_server_port, user_id, client_key):
    # Provides Session Key for accessing a file server
    client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    # client.bind((hostname, port))
    client.connect(constants.KDC)

    data = {}
    data[constants.USER_ID] = user_id
    data[constants.SERVICE_ID] = file_server_id
    data[constants.REQUEST_TYPE] = constants.SPECIFIC
    data_stream = crypto.serial(data)
    client.send(data_stream)
    print("Request sent to the Authentication server for Session Key")
    print("Establishing Session Key Using Needham Schroder Protocol")
    response_stream = client.recv(4096)
    response = crypto.unserial(response_stream)
    if not response[constants.STATUS]:
        print("Bad Request")
        exit(1)

    user_response_encoded = response[constants.SERVER_RESPONSE]
    service_ticket_encoded = response[constants.SERVICE_TICKET]

    user_response = crypto.unserial(
        crypto.decrypt(user_response_encoded, client_key))
    session_key = user_response[constants.SESSION_SERVICE_KEY]
    client.close()
    client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    client.connect(('localhost', file_server_port))
    client.send(service_ticket_encoded)

    response_service_stream = client.recv(4096)
    response_service = crypto.unserial(
        crypto.decrypt(response_service_stream, session_key))

    if response_service[constants.SERVICE_ID] != file_server_id:
        print("Could Not Establish Communication with File server")
        return False, None
    rpc_port = response_service[constants.RPC_PORT]
    return True, session_key, rpc_port
Exemplo n.º 9
0
def get_access_init(user_id):
    # Returns List of all active File servers
    client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    # client.bind((hostname, port))
    client.connect(constants.KDC)  # Authentication server
    print("Connected to Authentication Server")

    data = {}
    data[constants.USER_ID] = user_id
    data[constants.REQUEST_TYPE] = constants.INIT
    data_stream = crypto.serial(data)
    client.send(data_stream)
    print("Request sent to the Authentication server for Initialization")

    response_stream = client.recv(4096)
    response= crypto.unserial(response_stream)
    if response[constants.STATUS]==False:
        print("Could Not Verify with Server")
        exit(1)
    active_file_servers = response[constants.ACTIVE_SERVERS]
    client.close()
    return active_file_servers
Exemplo n.º 10
0
def get_service_ticket(stream, server_key):
    # Decrypt Service Ticket
    dstream = crypto.decrypt(stream, server_key)
    return crypto.unserial(dstream)