Beispiel #1
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))
Beispiel #2
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
Beispiel #3
0
 async def test_generate(self, cli, tmpdir):
     private_key_file = tmpdir.join('tmp_private_key')
     public_key_file = tmpdir.join('tmp_public_key')
     await cli('generate', str(private_key_file), str(public_key_file))
     private_key = Key.decode(private_key_file.read().strip(), Key.Type.private)
     public_key = Key.decode(public_key_file.read().strip(), Key.Type.public)
     assert private_key
     assert public_key
Beispiel #4
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')
 def __init__(self):
     self.threema_jpg = os.path.join(_res_path, 'threema.jpg')
     self.threema_mp4 = os.path.join(_res_path, 'threema.mp4')
     key = b'4a6a1b34dcef15d43cb74de2fd36091be99fbbaf126d099d47d83d919712c72b'
     self.echoecho_key = key
     self.echoecho_encoded_key = 'public:' + key.decode('ascii')
     decoded_private_key = Key.decode(pytest.msgapi.private,
                                      Key.Type.private)
     self.mocking_key = Key.derive_public(decoded_private_key).hex_pk()
     self.blobs = {}
     self.latest_blob_ids = []
     self.routes = [
         web.get('/pubkeys/{key}', self.pubkeys),
         web.get('/lookup/phone/{phone}', self.lookup_phone),
         web.get('/lookup/phone_hash/{phone_hash}', self.lookup_phone_hash),
         web.get('/lookup/email/{email}', self.lookup_email),
         web.get('/lookup/email_hash/{email_hash}', self.lookup_email_hash),
         web.get('/capabilities/{id}', self.capabilities),
         web.get('/credits', self.credits),
         web.post('/send_simple', self.send_simple),
         web.post('/send_e2e', self.send_e2e),
         web.post('/upload_blob', self.upload_blob),
         web.get('/blobs/{blob_id}', self.download_blob),
     ]
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)
Beispiel #7
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))
Beispiel #8
0
 def key(self, key):
     if isinstance(key, str):
         key = Key.decode(key, Key.Type.public)
     self._key = key