示例#1
0
def msgapi_plugin():
    private = 'private:dd9413d597092b004fedc4895db978425efa328ba1f1ec6729e46e09231b8a7e'
    public = Key.encode(
        Key.derive_public(Key.decode(private, Key.Type.private)))
    msgapi = {
        'msgapi': {
            'cli_path':
            os.path.join(
                os.path.dirname(__file__),
                '../threema/gateway/bin/gateway_client.py',
            ),
            'cert_path':
            os.path.join(_res_path, 'cert.pem'),
            'base_url':
            'https://msgapi.threema.ch',
            'ip':
            '127.0.0.1',
            'id':
            '*MOCKING',
            'secret':
            'mock',
            'private':
            private,
            'public':
            public,
            'nocredit_id':
            'NOCREDIT',
            'noexist_id':
            '*NOEXIST',
        }
    }
    return msgapi
示例#2
0
def derive(private_key):
    # Get private key instance and derive public key
    private_key = util.read_key_or_key_file(private_key, Key.Type.private)
    public_key = Key.derive_public(private_key)

    # Return hex encoded public key
    click.echo(Key.encode(public_key))
示例#3
0
def generate(private_key_file, public_key_file):
    # Generate key pair and hexlify both keys
    private_key, public_key = [Key.encode(key) for key in Key.generate_pair()]

    # Write keys to files
    with open(private_key_file, 'w') as sk_file, open(public_key_file,
                                                      'w') as pk_file:
        sk_file.write(private_key + '\n')
        pk_file.write(public_key + '\n')
示例#4
0
async def main():
    connection = Connection(
        identity='*YOUR_GATEWAY_THREEMA_ID',
        secret='YOUR_GATEWAY_THREEMA_ID_SECRET',
    )
    try:
        async with connection:
            print(await connection.get_credits())
            print(await connection.get_id(phone='41791234567'))
            hash_ = 'ad398f4d7ebe63c6550a486cc6e07f9baa09bd9d8b3d8cb9d9be106d35a7fdbc'
            print(await connection.get_id(phone_hash=hash_))
            print(await connection.get_id(email='*****@*****.**'))
            hash_ = '1ea093239cc5f0e1b6ec81b866265b921f26dc4033025410063309f4d1a8ee2c'
            print(await connection.get_id(email_hash=hash_))
            key = await connection.get_public_key('ECHOECHO')
            print(Key.encode(key))
            print(await connection.get_reception_capabilities('ECHOECHO'))
    except GatewayError as exc:
        print('Error:', exc)
示例#5
0
async def lookup(ctx, **arguments):
    modes = ['email', 'phone', 'id']
    mode = {
        key: value
        for key, value in arguments.items()
        if key in modes and value is not None
    }

    # Check that one of the modes has been selected
    if len(mode) != 1:
        error = 'Please specify exactly one ID, one email address or one phone number.'
        raise click.ClickException(error)

    # Create connection
    connection = Connection(arguments['from'],
                            secret=arguments['secret'],
                            **ctx.obj)
    async with connection:
        # Do lookup
        if 'id' in mode:
            public_key = await connection.get_public_key(arguments['id'])
            click.echo(Key.encode(public_key))
        else:
            click.echo(await connection.get_id(**mode))