|
9 | 9 | Copyright (C) 2019 Taylor Dean (taylor@makeshift.dev) |
10 | 10 | Copyright (C) 2020 Max Lanin (mlanin@evolutiongaming.com) |
11 | 11 | Copyright (C) 2019-2020 Tino Lange (coldcoff@yahoo.com) |
| 12 | + Copyright (C) 2022 David Keijser (keijser@gmail.com) |
12 | 13 |
|
13 | 14 | Permission is hereby granted, free of charge, to any person obtaining a copy |
14 | 15 | of this software and associated documentation files (the "Software"), to deal |
|
56 | 57 | from fido2.utils import websafe_decode |
57 | 58 | from fido2.hid import CtapHidDevice |
58 | 59 | from fido2.client import Fido2Client |
| 60 | + from fido2.webauthn import PublicKeyCredentialRequestOptions, PublicKeyCredentialDescriptor, PublicKeyCredentialType |
59 | 61 | have_fido = True |
60 | 62 | except ImportError: |
61 | 63 | pass |
@@ -657,27 +659,35 @@ def okta_mfa_webauthn(conf, factor, state_token): |
657 | 659 | profile = rfactor['profile'] |
658 | 660 | purl = parse_url(conf.okta_url) |
659 | 661 | origin = '{0}://{1}'.format(purl[0], purl[1]) |
660 | | - challenge = rfactor['_embedded']['challenge']['challenge'] |
661 | 662 | credentialId = websafe_decode(profile['credentialId']) |
662 | 663 | 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 | + ) |
663 | 673 | for dev in devices: |
664 | 674 | client = Fido2Client(dev, origin) |
665 | 675 | print('!!! Touch the flashing U2F device to authenticate... !!!') |
666 | 676 | 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)) |
669 | 679 | break |
670 | 680 | except Exception: |
671 | 681 | traceback.print_exc(file=sys.stderr) |
672 | 682 | result = None |
673 | 683 | if not result: |
674 | 684 | 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. |
676 | 686 | data = { |
677 | 687 | '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')) |
681 | 691 | } |
682 | 692 | log('mfa {0} signature request [okta_url]'.format(provider)) |
683 | 693 | _, _h, j = send_json_req(conf, 'okta', 'uf2 mfa signature', j['_links']['next']['href'], data, expected_url=conf.okta_url) |
|
0 commit comments