Skip to content

Commit 1d3af79

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 <coldcoff@yahoo.com>
1 parent a24fef4 commit 1d3af79

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

gp-okta.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
Copyright (C) 2019 Taylor Dean (taylor@makeshift.dev)
1010
Copyright (C) 2020 Max Lanin (mlanin@evolutiongaming.com)
1111
Copyright (C) 2019-2020 Tino Lange (coldcoff@yahoo.com)
12+
Copyright (C) 2022 David Keijser (keijser@gmail.com)
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
@@ -657,27 +659,35 @@ def okta_mfa_webauthn(conf, factor, state_token):
657659
profile = rfactor['profile']
658660
purl = parse_url(conf.okta_url)
659661
origin = '{0}://{1}'.format(purl[0], purl[1])
660-
challenge = rfactor['_embedded']['challenge']['challenge']
661662
credentialId = websafe_decode(profile['credentialId'])
662663
allow_list = [{'type': 'public-key', 'id': credentialId}]
664+
request_options = PublicKeyCredentialRequestOptions(
665+
challenge = websafe_decode(rfactor['_embedded']['challenge']['challenge']),
666+
rp_id = purl[1],
667+
allow_credentials = [
668+
PublicKeyCredentialDescriptor(
669+
PublicKeyCredentialType.PUBLIC_KEY,
670+
websafe_decode(profile['credentialId']))
671+
]
672+
)
663673
for dev in devices:
664674
client = Fido2Client(dev, origin)
665675
print('!!! Touch the flashing U2F device to authenticate... !!!')
666676
try:
667-
result = client.get_assertion(purl[1], challenge, allow_list)
668-
dbg(conf.debug, 'assertion.result', result)
677+
result = client.get_assertion(request_options)
678+
dbg(conf.debug, 'assertion.result', vars(result))
669679
break
670680
except Exception:
671681
traceback.print_exc(file=sys.stderr)
672682
result = None
673683
if not result:
674684
return None
675-
assertion, client_data = result[0][0], result[1] # only one cred in allowList, so only one response.
685+
response = result.get_response(0) # only one cred in allowList, so only one response.
676686
data = {
677687
'stateToken': state_token,
678-
'clientData': to_n((base64.b64encode(client_data)).decode('ascii')),
679-
'signatureData': to_n((base64.b64encode(assertion.signature)).decode('ascii')),
680-
'authenticatorData': to_n((base64.b64encode(assertion.auth_data)).decode('ascii'))
688+
'clientData': to_n((base64.b64encode(response.client_data)).decode('ascii')),
689+
'signatureData': to_n((base64.b64encode(response.signature)).decode('ascii')),
690+
'authenticatorData': to_n((base64.b64encode(response.authenticator_data)).decode('ascii'))
681691
}
682692
log('mfa {0} signature request [okta_url]'.format(provider))
683693
_, _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)