Skip to content

Commit 523eeea

Browse files
author
Jeremy T
committed
Merge branch 'jul/oidc' into 'master'
Jul/oidc See merge request TankerHQ/sdk-python!225
2 parents d111be4 + 98b9b5a commit 523eeea

File tree

4 files changed

+24
-39
lines changed

4 files changed

+24
-39
lines changed

build_tanker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def on_import() -> None:
8282
]
8383
# macOS system libs + compiler flags are already in the env
8484
# thanks to the virtualenv generated by conan in setup.py
85-
system_libs = []
85+
system_libs: List[str] = []
8686

8787
tanker_ext.set_source(
8888
"_tanker",

cffi_defs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,10 @@ tanker_future_t* tanker_verify_identity(
398398

399399
tanker_future_t* tanker_stop(tanker_t* tanker);
400400

401+
tanker_future_t* tanker_create_oidc_nonce(tanker_t* tanker);
402+
403+
tanker_future_t* tanker_set_oidc_test_nonce(tanker_t* tanker, char const* nonce);
404+
401405
enum tanker_status tanker_status(tanker_t* tanker);
402406

403407
tanker_future_t* tanker_device_id(tanker_t* session);

tankersdk/tanker.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,21 @@ async def stop(self) -> None:
720720
c_future = tankerlib.tanker_stop(self.c_tanker)
721721
await ffihelpers.handle_tanker_future(c_future)
722722

723+
async def create_oidc_nonce(self) -> str:
724+
"""Create a nonce to use in oidc authorization code flow"""
725+
c_future = tankerlib.tanker_create_oidc_nonce(self.c_tanker)
726+
c_voidp = await ffihelpers.handle_tanker_future(c_future)
727+
c_str = ffi.cast("char*", c_voidp)
728+
res = ffihelpers.c_string_to_str(c_str)
729+
tankerlib.tanker_free_buffer(c_str)
730+
return res
731+
732+
async def _set_oidc_test_nonce(self, nonce: str) -> None:
733+
"""Set the oidc nonce to use during the next verification operation"""
734+
c_nonce = ffihelpers.str_to_c_string(nonce)
735+
c_future = tankerlib.tanker_set_oidc_test_nonce(self.c_tanker, c_nonce)
736+
await ffihelpers.handle_tanker_future(c_future)
737+
723738
async def encrypt(
724739
self, clear_data: bytes, options: Optional[EncryptionOptions] = None
725740
) -> bytes:

test/test_tanker.py

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,9 @@ async def test_oidc_verification(
12031203
app["id"], app["secret"], str(uuid.uuid4())
12041204
)
12051205

1206+
nonce = await martine_phone.create_oidc_nonce()
12061207
await martine_phone.start(identity)
1208+
await martine_phone._set_oidc_test_nonce(nonce)
12071209
await martine_phone.register_identity(OidcIdTokenVerification(oidc_id_token))
12081210
await martine_phone.stop()
12091211

@@ -1213,6 +1215,8 @@ async def test_oidc_verification(
12131215
await martine_laptop.start(identity)
12141216

12151217
assert martine_laptop.status == TankerStatus.IDENTITY_VERIFICATION_NEEDED
1218+
nonce = await martine_laptop.create_oidc_nonce()
1219+
await martine_laptop._set_oidc_test_nonce(nonce)
12161220
await martine_laptop.verify_identity(OidcIdTokenVerification(oidc_id_token))
12171221
assert martine_laptop.status == TankerStatus.READY
12181222

@@ -1223,44 +1227,6 @@ async def test_oidc_verification(
12231227
await martine_laptop.stop()
12241228

12251229

1226-
@pytest.mark.asyncio
1227-
async def test_oidc_preshare(tmp_path: Path, app: Dict[str, str], admin: Admin) -> None:
1228-
email, oidc_id_token = set_up_oidc(app, admin, "martine")
1229-
alice = await create_user_session(tmp_path, app)
1230-
1231-
provisional_identity = tankersdk_identity.create_provisional_identity(
1232-
app["id"], email
1233-
)
1234-
public_provisional_identity = tankersdk_identity.get_public_identity(
1235-
provisional_identity
1236-
)
1237-
1238-
message = b"hello OIDC user"
1239-
encrypted = await alice.session.encrypt(
1240-
message, EncryptionOptions(share_with_users=[public_provisional_identity])
1241-
)
1242-
1243-
martine_phone = create_tanker(app["id"], persistent_path=tmp_path)
1244-
identity = tankersdk_identity.create_identity(
1245-
app["id"], app["secret"], str(uuid.uuid4())
1246-
)
1247-
1248-
status = await martine_phone.start(identity)
1249-
assert status == TankerStatus.IDENTITY_REGISTRATION_NEEDED
1250-
await martine_phone.register_identity(OidcIdTokenVerification(oidc_id_token))
1251-
attach_result = await martine_phone.attach_provisional_identity(
1252-
provisional_identity
1253-
)
1254-
assert attach_result.status == TankerStatus.IDENTITY_VERIFICATION_NEEDED
1255-
await martine_phone.verify_provisional_identity(
1256-
OidcIdTokenVerification(oidc_id_token)
1257-
)
1258-
clear_data = await alice.session.decrypt(encrypted)
1259-
assert clear_data == message
1260-
await martine_phone.stop()
1261-
await alice.session.stop()
1262-
1263-
12641230
@pytest.mark.asyncio
12651231
async def test_register_fails_with_preverified_email(
12661232
tmp_path: Path, app: Dict[str, str], admin: Admin

0 commit comments

Comments
 (0)