View | Details | Raw Unified | Return to bug 240774
Collapse All | Expand All

(-)security/py-fido2/Makefile (-2 / +1 lines)
Lines 1-8 Link Here
1
# $FreeBSD$
1
# $FreeBSD$
2
2
3
PORTNAME=	fido2
3
PORTNAME=	fido2
4
PORTVERSION=	0.7.0
4
PORTVERSION=	0.7.1
5
PORTREVISION=	1
6
CATEGORIES=	security python
5
CATEGORIES=	security python
7
MASTER_SITES=	CHEESESHOP
6
MASTER_SITES=	CHEESESHOP
8
PKGNAMEPREFIX=	${PYTHON_PKGNAMEPREFIX}
7
PKGNAMEPREFIX=	${PYTHON_PKGNAMEPREFIX}
(-)security/py-fido2/distinfo (-3 / +3 lines)
Lines 1-3 Link Here
1
TIMESTAMP = 1561156306
1
TIMESTAMP = 1569250691
2
SHA256 (fido2-0.7.0.tar.gz) = 47b02852780849bb4bb698b9727d61970ee77a83eb25715fe7c6235ebd648d87
2
SHA256 (fido2-0.7.1.tar.gz) = 4483b48ab3da0a3f3cc8e2f11d833160dfa2e6d12148e938982df4acd10b2682
3
SIZE (fido2-0.7.0.tar.gz) = 171787
3
SIZE (fido2-0.7.1.tar.gz) = 176790
(-)security/py-fido2/files/patch-README.adoc (-25 lines)
Lines 1-25 Link Here
1
This was part of a pull request that has been merged uptream. Most likely
2
this patch can be removed on the next release of python-fido2.
3
4
See https://github.com/Yubico/python-fido2/pull/64 and
5
https://github.com/Yubico/python-fido2/commit/19c86d5459931b8a76d1adc76420a8a1e0c0cf2e
6
7
--- README.adoc.orig	2019-06-17 12:31:00 UTC
8
+++ README.adoc
9
@@ -64,10 +64,15 @@ KERNEL=="hidraw*", SUBSYSTEM=="hidraw", \
10
   MODE="0664", GROUP="plugdev", ATTRS{idVendor}=="1050"
11
 ----
12
 
13
+Under FreeBSD you will either need to run as root or add rules for your device
14
+to /etc/devd.conf, which can be automated by installing security/u2f-devd:
15
 
16
+  # pkg install u2f-devd
17
+
18
+
19
 === Dependencies
20
 fido2 is compatible with CPython 2.7 (2.7.6 and up), 3.4 onwards, and is tested
21
-on Windows, MacOS, and Linux.
22
+on Windows, MacOS, FreeBSD, and Linux.
23
 
24
 This project depends on Cryptography. For instructions on installing this
25
 dependency, see https://cryptography.io/en/latest/installation/.
(-)security/py-fido2/files/patch-fido2___pyu2f_____init____.py (-18 lines)
Lines 1-18 Link Here
1
This was part of a pull request that has been merged upstream. Most likely
2
this patch can be removed on the next release of python-fido2.
3
4
See https://github.com/Yubico/python-fido2/pull/64 and
5
https://github.com/Yubico/python-fido2/commit/19c86d5459931b8a76d1adc76420a8a1e0c0cf2e
6
7
--- fido2/_pyu2f/__init__.py.orig	2019-09-10 15:15:37 UTC
8
+++ fido2/_pyu2f/__init__.py
9
@@ -47,6 +47,9 @@ def InternalPlatformSwitch(funcname, *args, **kwargs):
10
   elif sys.platform.startswith('darwin'):
11
     from . import macos
12
     clz = macos.MacOsHidDevice
13
+  elif sys.platform.startswith('freebsd'):
14
+    from . import freebsd
15
+    clz = freebsd.FreeBSDHidDevice
16
 
17
   if not clz:
18
     raise Exception('Unsupported platform: ' + sys.platform)
(-)security/py-fido2/files/patch-fido2___pyu2f_freebsd.py (-63 lines)
Lines 1-63 Link Here
1
This was part of a pull request that has been merged upstream. Most likely
2
this patch can be removed on the next release of python-fido2.
3
4
See https://github.com/Yubico/python-fido2/pull/64 and
5
https://github.com/Yubico/python-fido2/commit/19c86d5459931b8a76d1adc76420a8a1e0c0cf2e
6
7
--- fido2/_pyu2f/freebsd.py.orig	2019-09-12 11:35:02 UTC
8
+++ fido2/_pyu2f/freebsd.py
9
@@ -0,0 +1,54 @@
10
+# Copyright 2016 Google Inc. All Rights Reserved.
11
+#
12
+# Licensed under the Apache License, Version 2.0 (the "License");
13
+# you may not use this file except in compliance with the License.
14
+# You may obtain a copy of the License at
15
+#
16
+#    http://www.apache.org/licenses/LICENSE-2.0
17
+#
18
+# Unless required by applicable law or agreed to in writing, software
19
+# distributed under the License is distributed on an "AS IS" BASIS,
20
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+# See the License for the specific language governing permissions and
22
+# limitations under the License.
23
+
24
+"""Implements raw HID interface on FreeBSD using sysctl and device files."""
25
+
26
+from __future__ import absolute_import
27
+
28
+import os
29
+import uhid_freebsd
30
+
31
+from . import linux
32
+
33
+
34
+class FreeBSDHidDevice(linux.LinuxHidDevice):
35
+    """Implementation of HID device for FreeBSD.
36
+    """
37
+
38
+    @staticmethod
39
+    def Enumerate():
40
+        for dev in uhid_freebsd.enumerate():
41
+            desc = linux.base.DeviceDescriptor()
42
+            desc.path = dev["path"]
43
+            desc.vendor_id = dev["vendor_id"]
44
+            desc.product_id = dev["product_id"]
45
+            desc.product_string = dev["product_desc"]
46
+            fd = os.open(desc.path, os.O_RDONLY)
47
+            linux.ParseReportDescriptor(
48
+                uhid_freebsd.get_report_data(fd, 3), desc)
49
+            os.close(fd)
50
+            yield desc.ToPublicDict()
51
+
52
+    def __init__(self, path):
53
+        linux.base.HidDevice.__init__(self, path)
54
+        self.dev = os.open(path, os.O_RDWR)
55
+        self.desc = linux.base.DeviceDescriptor()
56
+        self.desc.path = path
57
+        linux.ParseReportDescriptor(
58
+            uhid_freebsd.get_report_data(self.dev, 3), self.desc)
59
+
60
+    def Write(self, packet):
61
+        """See base class."""
62
+        out = bytes(bytearray([0]*64 + packet))  # 64 zero bytes (report ID)
63
+        os.write(self.dev, out)
(-)security/py-fido2/files/patch-setup.py (-24 lines)
Lines 1-24 Link Here
1
This was part of a pull request that has been merged upstream. Most likely
2
this patch can be removed on the next release of python-fido2.
3
4
See https://github.com/Yubico/python-fido2/pull/64 and
5
https://github.com/Yubico/python-fido2/commit/19c86d5459931b8a76d1adc76420a8a1e0c0cf2e
6
7
--- setup.py.orig	2019-06-17 10:59:34 UTC
8
+++ setup.py
9
@@ -48,13 +48,14 @@ setup(
10
     install_requires=[
11
         'six',
12
         'cryptography>=1.5',
13
+        'uhid-freebsd>=1.2.1;platform_system=="FreeBSD"',
14
     ],
15
     extras_require={
16
         ':python_version < "3.4"': ['enum34'],
17
         'pcsc': ['pyscard']
18
     },
19
     test_suite='test',
20
-    tests_require=['mock>=1.0.1', 'pyfakefs>=3.4'],
21
+    tests_require=['mock>=1.0.1', 'pyfakefs>=3.4;platform_system=="Linux"'],
22
     classifiers=[
23
         'License :: OSI Approved :: BSD License',
24
         'License :: OSI Approved :: Apache Software License',
(-)security/py-fido2/files/patch-test___pyu2f_freebsd__test.py (-131 lines)
Lines 1-131 Link Here
1
This was part of a pull request that has been merged upstream. Most likely
2
this patch can be removed on the next release of python-fido2.
3
4
See https://github.com/Yubico/python-fido2/pull/64 and
5
https://github.com/Yubico/python-fido2/commit/19c86d5459931b8a76d1adc76420a8a1e0c0cf2e
6
7
--- test/_pyu2f/freebsd_test.py.orig	2019-09-13 11:01:05 UTC
8
+++ test/_pyu2f/freebsd_test.py
9
@@ -0,0 +1,122 @@
10
+# Copyright 2016 Google Inc. All Rights Reserved.
11
+#
12
+# Licensed under the Apache License, Version 2.0 (the "License");
13
+# you may not use this file except in compliance with the License.
14
+# You may obtain a copy of the License at
15
+#
16
+#    http://www.apache.org/licenses/LICENSE-2.0
17
+#
18
+# Unless required by applicable law or agreed to in writing, software
19
+# distributed under the License is distributed on an "AS IS" BASIS,
20
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+# See the License for the specific language governing permissions and
22
+# limitations under the License.
23
+
24
+"""Tests for _pyu2f.hid.freebsd."""
25
+
26
+import base64
27
+import os
28
+import sys
29
+
30
+import six
31
+from six.moves import builtins
32
+from mock import patch
33
+
34
+if sys.platform.startswith('freebsd'):
35
+    from fido2._pyu2f import freebsd
36
+
37
+if sys.version_info[:2] < (2, 7):
38
+    import unittest2 as unittest  # pylint: disable=g-import-not-at-top
39
+else:
40
+    import unittest  # pylint: disable=g-import-not-at-top
41
+
42
+
43
+# These are base64 encoded report descriptors of a Yubico token
44
+# and a Logitech keyboard.
45
+YUBICO_RD = 'BtDxCQGhAQkgFQAm/wB1CJVAgQIJIRUAJv8AdQiVQJECwA=='
46
+KEYBOARD_RD = (
47
+    'BQEJAqEBCQGhAAUJGQEpBRUAJQGVBXUBgQKVAXUDgQEFAQkwCTEJOBWBJX91CJUDgQbAwA==')
48
+
49
+
50
+class FakeUhidFreeBSDModule():
51
+    def enumerate(self):
52
+        return [{'device': 'uhid0',
53
+                 'path': '/dev/uhid0',
54
+                 'vendor_id': 0x046d,
55
+                 'product_id': 0xc31c,
56
+                 'product_desc': 'Logitech Keyboard'},
57
+                {'device': 'uhid1',
58
+                 'path': '/dev/uhid1',
59
+                 'vendor_id': 0x1050,
60
+                 'product_id': 0x0407,
61
+                 'product_desc': 'Yubico U2F'}]
62
+
63
+    def get_report_data(self, fd, unused_report_id):
64
+        if fd:
65
+            return base64.b64decode(YUBICO_RD)
66
+        else:
67
+            return base64.b64decode(KEYBOARD_RD)
68
+
69
+
70
+class FakeOsModule():
71
+    O_RDONLY = os.O_RDONLY
72
+    O_RDWR = os.O_RDWR
73
+    path = os.path
74
+
75
+    data_written = None
76
+    data_to_return = None
77
+
78
+    def open(self, path, unused_opts):  # pylint: disable=invalid-name
79
+        if path.find('uhid1') >= 0:
80
+            return 1  # fd == 1 => magic number to return Yubikey RD below
81
+        else:
82
+            return 0
83
+
84
+    def write(self, unused_dev, data):  # pylint: disable=invalid-name
85
+        self.data_written = data
86
+
87
+    def read(self, unused_dev, unused_length):  # pylint: disable=invalid-name
88
+        return self.data_to_return
89
+
90
+    def close(self, unused_dev):  # pylint: disable=invalid-name
91
+        pass
92
+
93
+
94
+@unittest.skipIf(not sys.platform.startswith('freebsd'),
95
+                 'FreeBSD specific test case')
96
+class FreeBSDTest(unittest.TestCase):
97
+    @patch('fido2._pyu2f.freebsd.os', FakeOsModule())
98
+    @patch('fido2._pyu2f.freebsd.uhid_freebsd', FakeUhidFreeBSDModule())
99
+    def testCallEnumerate(self):
100
+        devs = list(freebsd.FreeBSDHidDevice.Enumerate())
101
+        devs = sorted(devs, key=lambda k: k['vendor_id'])
102
+
103
+        self.assertEqual(len(devs), 2)
104
+        self.assertEqual(devs[0]['vendor_id'], 0x046d)
105
+        self.assertEqual(devs[0]['product_id'], 0xc31c)
106
+        self.assertEqual(devs[1]['vendor_id'], 0x1050)
107
+        self.assertEqual(devs[1]['product_id'], 0x0407)
108
+        self.assertEqual(devs[1]['usage_page'], 0xf1d0)
109
+        self.assertEqual(devs[1]['usage'], 1)
110
+
111
+    @patch('fido2._pyu2f.freebsd.uhid_freebsd', FakeUhidFreeBSDModule())
112
+    def testCallOpen(self):
113
+        fake_os = FakeOsModule()
114
+        with patch('fido2._pyu2f.linux.os', fake_os):
115
+            with patch('fido2._pyu2f.freebsd.os', fake_os):
116
+                dev = freebsd.FreeBSDHidDevice('/dev/uhid1')
117
+                self.assertEqual(dev.GetInReportDataLength(), 64)
118
+                self.assertEqual(dev.GetOutReportDataLength(), 64)
119
+
120
+                dev.Write(list(range(0, 64)))
121
+                # The HidDevice implementation prepends one zero-byte-packet
122
+                # (64 bytes) representing the report ID + padding
123
+                self.assertEqual(list(six.iterbytes(fake_os.data_written)),
124
+                                 [0]*64 + list(range(0, 64)))
125
+
126
+                fake_os.data_to_return = b'x' * 64
127
+                self.assertEqual(dev.Read(), [120] * 64)  # chr(120) = 'x'
128
+
129
+
130
+if __name__ == '__main__':
131
+    unittest.main()
(-)security/py-fido2/files/patch-test___pyu2f_linux__test.py (-30 lines)
Lines 1-30 Link Here
1
This was part of a pull request that has been merged upstream. Most likely
2
this patch can be removed on the next release of python-fido2.
3
4
See https://github.com/Yubico/python-fido2/pull/64 and
5
https://github.com/Yubico/python-fido2/commit/19c86d5459931b8a76d1adc76420a8a1e0c0cf2e
6
7
--- test/_pyu2f/linux_test.py.orig	2019-09-13 11:17:23 UTC
8
+++ test/_pyu2f/linux_test.py
9
@@ -27,7 +27,11 @@ from fido2._pyu2f import linux
10
 try:
11
   from pyfakefs import fake_filesystem  # pylint: disable=g-import-not-at-top
12
 except ImportError:
13
-  from fakefs import fake_filesystem  # pylint: disable=g-import-not-at-top
14
+  try:
15
+    from fakefs import fake_filesystem  # pylint: disable=g-import-not-at-top
16
+  except ImportError:
17
+    if sys.platform.startswith('linux'):
18
+      raise
19
 
20
 if sys.version_info[:2] < (2, 7):
21
   import unittest2 as unittest  # pylint: disable=g-import-not-at-top
22
@@ -71,6 +75,8 @@ class FakeDeviceOsModule(object):
23
     return self.data_to_return
24
 
25
 
26
+@unittest.skipIf(not sys.platform.startswith('linux'),
27
+                 'Linux specific test case')
28
 class LinuxTest(unittest.TestCase):
29
   def setUp(self):
30
     self.fs = fake_filesystem.FakeFilesystem()
(-)security/py-fido2/files/patch-test___pyu2f_macos__test.py (-17 lines)
Lines 1-17 Link Here
1
This was part of a pull request that has been merged upstream. Most likely
2
this patch can be removed on the next release of python-fido2.
3
4
See https://github.com/Yubico/python-fido2/pull/64 and
5
https://github.com/Yubico/python-fido2/commit/19c86d5459931b8a76d1adc76420a8a1e0c0cf2e
6
7
--- test/_pyu2f/macos_test.py.orig	2018-07-04 13:27:36 UTC
8
+++ test/_pyu2f/macos_test.py
9
@@ -44,6 +44,8 @@ def init_mock_get_int_property(mock_get_int_property):
10
   mock_get_int_property.return_value = 64
11
 
12
 
13
+@unittest.skipIf(not sys.platform.startswith('darwin'),
14
+                 'MacOS specific test case')
15
 class MacOsTest(unittest.TestCase):
16
 
17
   @classmethod

Return to bug 240774