forked from Nitrokey/libnitrokey
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Nitrokey#32 from solokeys/challenge-response
Add challenge-response via hmac-secret
- Loading branch information
Showing
5 changed files
with
121 additions
and
2 deletions.
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
0.0.13 | ||
0.0.14 |
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
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
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,78 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright 2019 SoloKeys Developers | ||
# | ||
# Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or | ||
# http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or | ||
# http://opensource.org/licenses/MIT>, at your option. This file may not be | ||
# copied, modified, or distributed except according to those terms. | ||
|
||
|
||
import binascii | ||
import hashlib | ||
|
||
from fido2.extensions import HmacSecretExtension | ||
|
||
import solo.client | ||
|
||
|
||
def simple_secret( | ||
secret_input, | ||
credential_id=None, | ||
relying_party="example.org", | ||
user_id="they", | ||
serial=None, | ||
pin=None, | ||
): | ||
user_id = user_id.encode() | ||
|
||
client = solo.client.find(solo_serial=serial).client | ||
hmac_ext = HmacSecretExtension(client.ctap2) | ||
|
||
if credential_id is None: | ||
rp = {"id": relying_party, "name": "Example RP"} | ||
client.rp = relying_party | ||
client.origin = f"https://{client.rp}" | ||
client.user_id = user_id | ||
user = {"id": user_id, "name": "A. User"} | ||
# challenge = "Y2hhbGxlbmdl" | ||
challenge = "123" | ||
|
||
print("Touch your authenticator to generate a credential...") | ||
attestation_object, client_data = client.make_credential( | ||
rp, user, challenge, extensions=hmac_ext.create_dict(), pin=pin | ||
) | ||
credential = attestation_object.auth_data.credential_data | ||
credential_id = credential.credential_id | ||
|
||
# Show credential_id for convenience | ||
print(f"credential ID (hex-encoded):") | ||
print(credential_id.hex()) | ||
else: | ||
credential_id = binascii.a2b_hex(credential_id) | ||
|
||
allow_list = [{"type": "public-key", "id": credential_id}] | ||
|
||
# challenge = 'Q0hBTExFTkdF' # Use a new challenge for each call. | ||
challenge = "abc" | ||
|
||
# Generate a salt for HmacSecret: | ||
|
||
h = hashlib.sha256() | ||
h.update(secret_input.encode()) | ||
salt = h.digest() | ||
# print(f"salt = {salt.hex()}") | ||
|
||
print("Touch your authenticator to generate the response...") | ||
assertions, client_data = client.get_assertion( | ||
relying_party, | ||
challenge, | ||
allow_list, | ||
extensions=hmac_ext.get_dict(salt), | ||
pin=pin, | ||
) | ||
|
||
assertion = assertions[0] # Only one cred in allowList, only one response. | ||
secret = hmac_ext.results_for(assertion.auth_data)[0] | ||
print("hmac-secret (hex-encoded):") | ||
print(secret.hex()) |