Skip to content

Commit 1798cbb

Browse files
keiscoldcoff
andcommitted
Adapt to work with new fido2 API
In version 0.9.0 of fido2 the API is changed to accept/return new request/response objects. Co-authored-by: Tino Lange <[email protected]>
1 parent 527e160 commit 1798cbb

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

gp-okta.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
Copyright (C) 2019 Taylor Dean ([email protected])
1010
Copyright (C) 2020 Max Lanin ([email protected])
1111
Copyright (C) 2019-2020 Tino Lange ([email protected])
12+
Copyright (C) 2022 David Keijser ([email protected])
1213
1314
Permission is hereby granted, free of charge, to any person obtaining a copy
1415
of this software and associated documentation files (the "Software"), to deal
@@ -56,6 +57,7 @@
5657
from fido2.utils import websafe_decode
5758
from fido2.hid import CtapHidDevice
5859
from fido2.client import Fido2Client
60+
from fido2.webauthn import PublicKeyCredentialRequestOptions, PublicKeyCredentialDescriptor, PublicKeyCredentialType
5961
have_fido = True
6062
except ImportError:
6163
pass
@@ -649,27 +651,35 @@ def okta_mfa_webauthn(conf, factor, state_token):
649651
profile = rfactor['profile']
650652
purl = parse_url(conf.okta_url)
651653
origin = '{0}://{1}'.format(purl[0], purl[1])
652-
challenge = rfactor['_embedded']['challenge']['challenge']
653654
credentialId = websafe_decode(profile['credentialId'])
654655
allow_list = [{'type': 'public-key', 'id': credentialId}]
656+
request_options = PublicKeyCredentialRequestOptions(
657+
challenge = websafe_decode(rfactor['_embedded']['challenge']['challenge']),
658+
rp_id = purl[1],
659+
allow_credentials = [
660+
PublicKeyCredentialDescriptor(
661+
PublicKeyCredentialType.PUBLIC_KEY,
662+
websafe_decode(profile['credentialId']))
663+
]
664+
)
655665
for dev in devices:
656666
client = Fido2Client(dev, origin)
657667
print('!!! Touch the flashing U2F device to authenticate... !!!')
658668
try:
659-
result = client.get_assertion(purl[1], challenge, allow_list)
660-
dbg(conf.debug, 'assertion.result', result)
669+
result = client.get_assertion(request_options)
670+
dbg(conf.debug, 'assertion.result', vars(result))
661671
break
662672
except Exception:
663673
traceback.print_exc(file=sys.stderr)
664674
result = None
665675
if not result:
666676
return None
667-
assertion, client_data = result[0][0], result[1] # only one cred in allowList, so only one response.
677+
response = result.get_response(0) # only one cred in allowList, so only one response.
668678
data = {
669679
'stateToken': state_token,
670-
'clientData': to_n((base64.b64encode(client_data)).decode('ascii')),
671-
'signatureData': to_n((base64.b64encode(assertion.signature)).decode('ascii')),
672-
'authenticatorData': to_n((base64.b64encode(assertion.auth_data)).decode('ascii'))
680+
'clientData': to_n((base64.b64encode(response.client_data)).decode('ascii')),
681+
'signatureData': to_n((base64.b64encode(response.signature)).decode('ascii')),
682+
'authenticatorData': to_n((base64.b64encode(response.authenticator_data)).decode('ascii'))
673683
}
674684
log('mfa {0} signature request [okta_url]'.format(provider))
675685
_, _h, j = send_json_req(conf, 'okta', 'uf2 mfa signature', j['_links']['next']['href'], data, expected_url=conf.okta_url)

0 commit comments

Comments
 (0)