Пример #1
0
    dir_path = os.path.dirname(os.path.realpath(__file__))
    key_file = os.path.join(dir_path, f'{username}.key')
    if not os.path.exists(key_file):
        keys = RSA.generate(2048, os.urandom)
        with open(key_file, 'wb') as key_f:
            key_f.write(keys.export_key())
    else:
        with open(key_file, 'rb') as key_f:
            keys = RSA.import_key(key_f.read())

    CLIENT_LOG.debug('Keys loaded')

    db = ClientBase(username)

    try:
        transport = ClientTransport(port, address, db, username, password,
                                    keys)
    except ServerError as err:
        message = QMessageBox()
        message.critical(init_dialog, 'Server Error', str(err))
        exit(1)
    transport.setDaemon(True)
    transport.start()

    del init_dialog

    window = ClientMainWindow(db, transport, keys)
    window.make_connection(transport)
    window.statusBar().showMessage('Connected to TEST server')
    app.exec_()

    transport.transport_shutdown()
Пример #2
0
    key_file = os.path.join(dir_path, f'{client_name}.key')
    if not os.path.exists(key_file):
        keys = RSA.generate(2048, os.urandom)
        with open(key_file, 'wb') as key:
            key.write(keys.export_key())
    else:
        with open(key_file, 'rb') as key:
            keys = RSA.import_key(key.read())

    # !!!keys.publickey().export_key()
    logger.debug("Keys sucsessfully loaded.")
    # Создаём объект базы данных
    database = ClientDatabase(client_name)
    # Создаём объект - транспорт и запускаем транспортный поток
    try:
        transport = ClientTransport(server_port, server_address, database,
                                    client_name, client_passwd, keys)
        logger.debug("Transport ready.")
    except ServerError as error:
        message = QMessageBox()
        message.critical(start_dialog, 'Ошибка сервера', error.text)
        sys.exit(1)
    transport.setDaemon(True)
    transport.start()

    # Удалим объект диалога за ненадобностью
    del start_dialog

    # Создаём GUI
    main_window = ClientMainWindow(database, transport, keys)
    main_window.make_connection(transport)
    main_window.setWindowTitle(f'Чат Программа alpha release - {client_name}')
Пример #3
0
    dir_path = os.path.dirname(os.path.realpath(__file__))
    key_file = os.path.join(dir_path, f'{account_name}.key')
    if not os.path.exists(key_file):
        keys = RSA.generate(2048, os.urandom)
        with open(key_file, 'wb') as key:
            key.write(keys.exportKey())
    else:
        with open(key_file, 'rb') as key:
            keys = RSA.importKey(key.read())

    keys.publickey().exportKey()
    database = ClientDatabase(account_name)

    try:
        transport = ClientTransport(PORT, ADDRESS, database, account_name,
                                    client_passwd, keys)
    except Exception as error:
        print(error)
        exit(1)

    transport.setDaemon(True)
    transport.start()

    main_window = ClientMainWindow(database, transport, keys)
    main_window.make_connection(transport)
    main_window.setWindowTitle(f'Чат Программа alpha release - {account_name}')
    client_app.exec_()

    transport.transport_shutdown()
    transport.join()