Ejemplo n.º 1
0
def command_delete(args):
    axo = Pyxolotl(args.db, cryptostorage=get_cryptostorage())
    transport = args.transport_obj
    try:
        transport.send(axo.end_session(args.recipient))
    except NoSessionException:
        print('Session for recipient "{}" doesn\'t exist!'.format(
            args.recipient),
              file=sys.stderr)
        sys.exit(1)
Ejemplo n.º 2
0
def command_exchange(args):
    axo = Pyxolotl(args.db, cryptostorage=get_cryptostorage())
    transport = args.transport_obj
    if not axo.store.containsSession(args.recipient, axo.DEFAULT_DEVICE_ID):
        transport.send(axo.init_key_exchange(args.recipient))
    else:
        print('Session for recipient "{}" already exists!'.format(
            args.recipient),
              file=sys.stderr)
        if args.force:
            print('Sending initial key exchange anyway...', file=sys.stderr)
            print(file=sys.stderr)
            transport.send(axo.init_key_exchange(args.recipient))
        else:
            sys.exit(1)
Ejemplo n.º 3
0
def command_receive(args):
    axo = Pyxolotl(args.db, cryptostorage=get_cryptostorage())
    transport = args.transport_obj
    message = transport.receive(args.encrypted_message)
    decrypted = axo.receive(message)
    if decrypted and isinstance(decrypted, Message):
        print(
            'Received initial key exchange request! '
            'Send this reply to complete key exchange:',
            file=sys.stderr)
        transport.send(decrypted)
    elif decrypted:
        print('DECRYPTED:')
        print(decrypted)
    else:
        print('Initial key exchange completed!', file=sys.stderr)
Ejemplo n.º 4
0
def command_send(args):
    axo = Pyxolotl(args.db, cryptostorage=get_cryptostorage())
    transport = args.transport_obj
    message = args.message or input('Message: ')
    try:
        transport.send(axo.send(args.recipient, message))
    except NoSessionException:
        print('Session for recipient "{}" doesn\'t exist! '
              'Send initial key exchange first.'.format(args.recipient),
              file=sys.stderr)
        sys.exit(1)
    except PendingKeyExchangeException:
        print('Session for recipient "{}" is in pending key exchange state! '
              'Wait for key exchange reply first.'.format(args.recipient),
              file=sys.stderr)
        sys.exit(1)
Ejemplo n.º 5
0
def command_list(args):
    axo = Pyxolotl(args.db, cryptostorage=get_cryptostorage())

    your_public_key = axo.store.getIdentityKeyPair().getPublicKey().serialize()
    print('Your public key: {}'.format(
        binascii.hexlify(your_public_key).decode('ascii')))

    all_sessions = axo.store.sessionStore.getAllSessions()
    if all_sessions:
        print('Existing sessions:')
        for identity, device_id, record in all_sessions:
            try:
                public_key = binascii.hexlify(record.getSessionState(
                ).getRemoteIdentityKey().serialize()).decode('ascii')
            except IndexError:
                public_key = 'UNKNOWN'
            print('\tIdentity: {}, Pending key exchange: {}'.format(
                identity.decode('utf-8'),
                record.getSessionState().hasPendingKeyExchange()))
            print('\t\tPublic key: {}'.format(public_key))
    else:
        print('No sessions found.')