From 751b2fd69cf5bd59f0544d74a881dbaed7b8d920 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Fri, 28 Jun 2019 12:16:59 +0300 Subject: [PATCH 01/10] add nfc device search --- tools/testing/tests/tester.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/testing/tests/tester.py b/tools/testing/tests/tester.py index 10cd1d3..b77f690 100644 --- a/tools/testing/tests/tester.py +++ b/tools/testing/tests/tester.py @@ -63,8 +63,17 @@ class Tester: self.client = tester.client def find_device(self,): + print("--- HID ---") print(list(CtapHidDevice.list_devices())) dev = next(CtapHidDevice.list_devices(), None) + if not dev: + try: + from fido2.nfc import CtapNfcDevice + print("--- NFC ---") + print(list(CtapNfcDevice.list_devices())) + dev = next(CtapNfcDevice.list_devices(), None) + except: + print("NFC devices is not supported") if not dev: raise RuntimeError("No FIDO device found") self.dev = dev From 2c500fe25ae47864235db2c69ae97b97dc7c964f Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Fri, 28 Jun 2019 12:32:52 +0300 Subject: [PATCH 02/10] check pyscard module first --- tools/testing/tests/tester.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/testing/tests/tester.py b/tools/testing/tests/tester.py index b77f690..9864417 100644 --- a/tools/testing/tests/tester.py +++ b/tools/testing/tests/tester.py @@ -1,4 +1,4 @@ -import time, struct +import time, struct, sys from fido2.hid import CtapHidDevice from fido2.client import Fido2Client @@ -68,6 +68,8 @@ class Tester: dev = next(CtapHidDevice.list_devices(), None) if not dev: try: + if 'pyscard' not in sys.modules: + print('You have not installed pyscard module') from fido2.nfc import CtapNfcDevice print("--- NFC ---") print(list(CtapNfcDevice.list_devices())) From d1722b85af7a61a14df76edc6982397dec77f2dd Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Tue, 2 Jul 2019 19:45:46 +0300 Subject: [PATCH 03/10] add library not found error --- tools/testing/tests/tester.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/testing/tests/tester.py b/tools/testing/tests/tester.py index 9864417..69fe808 100644 --- a/tools/testing/tests/tester.py +++ b/tools/testing/tests/tester.py @@ -68,14 +68,14 @@ class Tester: dev = next(CtapHidDevice.list_devices(), None) if not dev: try: - if 'pyscard' not in sys.modules: - print('You have not installed pyscard module') from fido2.nfc import CtapNfcDevice print("--- NFC ---") print(list(CtapNfcDevice.list_devices())) dev = next(CtapNfcDevice.list_devices(), None) - except: - print("NFC devices is not supported") + except ModuleNotFoundError: + print("One of NFC library is not installed properly.") + except Exception as e: + print("NFC devices is not supported", e, e.__class__.__name__) if not dev: raise RuntimeError("No FIDO device found") self.dev = dev From 795cf5c4a1653ae811761913d8e3da35e69eded4 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Tue, 2 Jul 2019 19:55:04 +0300 Subject: [PATCH 04/10] selecting NFC key works --- tools/testing/tests/tester.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tools/testing/tests/tester.py b/tools/testing/tests/tester.py index 69fe808..21759ee 100644 --- a/tools/testing/tests/tester.py +++ b/tools/testing/tests/tester.py @@ -68,14 +68,12 @@ class Tester: dev = next(CtapHidDevice.list_devices(), None) if not dev: try: - from fido2.nfc import CtapNfcDevice + from fido2.pcsc import CtapPcscDevice print("--- NFC ---") - print(list(CtapNfcDevice.list_devices())) - dev = next(CtapNfcDevice.list_devices(), None) - except ModuleNotFoundError: + print(list(CtapPcscDevice.list_devices())) + dev = next(CtapPcscDevice.list_devices(), None) + except (ModuleNotFoundError, ImportError) as e: print("One of NFC library is not installed properly.") - except Exception as e: - print("NFC devices is not supported", e, e.__class__.__name__) if not dev: raise RuntimeError("No FIDO device found") self.dev = dev From 91c77da179b22861bd987778c85d79241f34597a Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Wed, 3 Jul 2019 00:43:51 +0300 Subject: [PATCH 05/10] cbor.loads changed to cbor.decode_from --- tools/testing/tests/fido2.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testing/tests/fido2.py b/tools/testing/tests/fido2.py index 778cfb2..94a361d 100644 --- a/tools/testing/tests/fido2.py +++ b/tools/testing/tests/fido2.py @@ -78,7 +78,7 @@ def TestCborKeysSorted(cbor_obj): # https://fidoalliance.org/specs/fido-v2.0-ps-20190130/fido-client-to-authenticator-protocol-v2.0-ps-20190130.html#ctap2-canonical-cbor-encoding-form if isinstance(cbor_obj, bytes): - cbor_obj = cbor.loads(cbor_obj)[0] + cbor_obj = cbor.decode_from(cbor_obj)[0] if isinstance(cbor_obj, dict): l = [x for x in cbor_obj] @@ -341,8 +341,8 @@ class FIDO2Tests(Tester): def test_get_info(self,): with Test("Get info"): info = self.ctap.get_info() - print(bytes(info)) - print(cbor.loads(bytes(info))) + print("data:", bytes(info)) + print("decoded:", cbor.decode_from(bytes(info))) with Test("Check FIDO2 string is in VERSIONS field"): assert "FIDO_2_0" in info.versions From 2d72e02051ed23e9be0115300b1565c6e84d5837 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Wed, 3 Jul 2019 01:03:34 +0300 Subject: [PATCH 06/10] remove unused lib --- tools/testing/tests/tester.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/tests/tester.py b/tools/testing/tests/tester.py index 21759ee..4091ce2 100644 --- a/tools/testing/tests/tester.py +++ b/tools/testing/tests/tester.py @@ -1,4 +1,4 @@ -import time, struct, sys +import time, struct from fido2.hid import CtapHidDevice from fido2.client import Fido2Client From ff53bb1e32b608455d0131f928bac815058b8cf1 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Wed, 3 Jul 2019 01:16:55 +0300 Subject: [PATCH 07/10] fix style --- tools/testing/tests/tester.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/tests/tester.py b/tools/testing/tests/tester.py index 4091ce2..6b0df00 100644 --- a/tools/testing/tests/tester.py +++ b/tools/testing/tests/tester.py @@ -72,7 +72,7 @@ class Tester: print("--- NFC ---") print(list(CtapPcscDevice.list_devices())) dev = next(CtapPcscDevice.list_devices(), None) - except (ModuleNotFoundError, ImportError) as e: + except (ModuleNotFoundError, ImportError): print("One of NFC library is not installed properly.") if not dev: raise RuntimeError("No FIDO device found") From b42e990f675518b7836c096030d095bccad04283 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Wed, 3 Jul 2019 01:39:38 +0300 Subject: [PATCH 08/10] format fix --- tools/testing/tests/tester.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/tests/tester.py b/tools/testing/tests/tester.py index 6b0df00..99f26f6 100644 --- a/tools/testing/tests/tester.py +++ b/tools/testing/tests/tester.py @@ -69,6 +69,7 @@ class Tester: if not dev: try: from fido2.pcsc import CtapPcscDevice + print("--- NFC ---") print(list(CtapPcscDevice.list_devices())) dev = next(CtapPcscDevice.list_devices(), None) From b41cd5d5b872609c63906fd517e5d0577e4f459f Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Wed, 3 Jul 2019 17:54:53 +0300 Subject: [PATCH 09/10] add nfc test force flag --- tools/testing/main.py | 10 ++++++++-- tools/testing/tests/tester.py | 11 +++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tools/testing/main.py b/tools/testing/main.py index 7e105e0..437e938 100644 --- a/tools/testing/main.py +++ b/tools/testing/main.py @@ -19,7 +19,9 @@ from tests import Tester, FIDO2Tests, U2FTests, HIDTests, SoloTests if __name__ == "__main__": if len(sys.argv) < 2: - print("Usage: %s [sim] <[u2f]|[fido2]|[rk]|[hid]|[ping]>") + print("Usage: %s [sim] [nfc] <[u2f]|[fido2]|[rk]|[hid]|[ping]>") + print(" sim - test via UDP simulation backend only") + print(" nfc - test via NFC interface only") sys.exit(0) t = Tester() @@ -31,7 +33,11 @@ if __name__ == "__main__": t.set_sim(True) t.set_user_count(10) - t.find_device() + nfcOnly = False + if "nfc" in sys.argv: + nfcOnly = True + + t.find_device(nfcOnly) if "solo" in sys.argv: SoloTests(t).run() diff --git a/tools/testing/tests/tester.py b/tools/testing/tests/tester.py index 99f26f6..dbc88f9 100644 --- a/tools/testing/tests/tester.py +++ b/tools/testing/tests/tester.py @@ -62,10 +62,13 @@ class Tester: self.ctap1 = tester.ctap1 self.client = tester.client - def find_device(self,): - print("--- HID ---") - print(list(CtapHidDevice.list_devices())) - dev = next(CtapHidDevice.list_devices(), None) + def find_device(self, nfcInterfaceOnly = False): + dev = None + if not nfcInterfaceOnly: + print("--- HID ---") + print(list(CtapHidDevice.list_devices())) + dev = next(CtapHidDevice.list_devices(), None) + if not dev: try: from fido2.pcsc import CtapPcscDevice From b61e5db73672622110aeaf838ec6fc9fc4dd628e Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Wed, 3 Jul 2019 17:57:27 +0300 Subject: [PATCH 10/10] style --- tools/testing/tests/tester.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/tests/tester.py b/tools/testing/tests/tester.py index dbc88f9..011c1c2 100644 --- a/tools/testing/tests/tester.py +++ b/tools/testing/tests/tester.py @@ -62,7 +62,7 @@ class Tester: self.ctap1 = tester.ctap1 self.client = tester.client - def find_device(self, nfcInterfaceOnly = False): + def find_device(self, nfcInterfaceOnly=False): dev = None if not nfcInterfaceOnly: print("--- HID ---")