-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: test compatibility between askar and authlib
And add a failing test for further debugging Signed-off-by: Daniel Bluhm <[email protected]>
- Loading branch information
Showing
5 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
"""Test compabibility between Askar and Authlib.""" | ||
import json | ||
from aries_askar import Key, KeyAlg | ||
from authlib.jose import OKPKey | ||
import pytest | ||
|
||
from didcomm_messaging.crypto.backend.askar import ( | ||
AskarCryptoService, | ||
AskarKey, | ||
AskarSecretKey, | ||
) | ||
from didcomm_messaging.crypto.backend.authlib import ( | ||
AuthlibCryptoService, | ||
AuthlibKey, | ||
AuthlibSecretKey, | ||
) | ||
|
||
|
||
ALICE_KID = "did:example:alice#key-1" | ||
BOB_KID = "did:example:bob#key-1" | ||
|
||
|
||
@pytest.fixture | ||
def alice_askar_key(): | ||
yield Key.generate(KeyAlg.X25519) | ||
|
||
|
||
@pytest.fixture | ||
def bob_askar_key(): | ||
yield Key.generate(KeyAlg.X25519) | ||
|
||
|
||
@pytest.fixture | ||
def alice_authlib_key(alice_askar_key: Key): | ||
yield OKPKey.import_key(json.loads(alice_askar_key.get_jwk_public())) | ||
|
||
|
||
@pytest.fixture | ||
def bob_authlib_key(bob_askar_key: Key): | ||
yield OKPKey.import_key(json.loads(bob_askar_key.get_jwk_secret())) | ||
|
||
|
||
@pytest.fixture | ||
def alice(alice_askar_key: Key, alice_authlib_key: OKPKey): | ||
yield AskarSecretKey(alice_askar_key, ALICE_KID), AuthlibKey( | ||
alice_authlib_key, ALICE_KID | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def bob(bob_askar_key: Key, bob_authlib_key: OKPKey): | ||
yield AuthlibSecretKey(bob_authlib_key, BOB_KID), AskarKey(bob_askar_key, BOB_KID) | ||
|
||
|
||
@pytest.fixture | ||
def askar(): | ||
yield AskarCryptoService() | ||
|
||
|
||
@pytest.fixture | ||
def authlib(): | ||
yield AuthlibCryptoService() | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_compat( | ||
askar: AskarCryptoService, | ||
authlib: AuthlibCryptoService, | ||
alice: tuple[AskarSecretKey, AuthlibKey], | ||
bob: tuple[AuthlibSecretKey, AskarKey], | ||
): | ||
"""Test compabibility between Askar and Authlib. | ||
Alice uses Askar, Bob uses Authlib. | ||
""" | ||
alice_sk, alice_pk = alice | ||
bob_sk, bob_pk = bob | ||
|
||
to_alice = b"Dear alice, please decrypt this" | ||
enc_message = await authlib.ecdh_1pu_encrypt([alice_pk], bob_sk, to_alice) | ||
plaintext = await askar.ecdh_1pu_decrypt(enc_message, alice_sk, bob_pk) | ||
assert plaintext == to_alice | ||
|
||
to_bob = b"Dear bob, please decrypt this" | ||
enc_message = await askar.ecdh_1pu_encrypt([bob_pk], alice_sk, to_bob) | ||
plaintext = await authlib.ecdh_1pu_decrypt(enc_message, bob_sk, alice_pk) | ||
assert plaintext == to_bob |
File renamed without changes.