View | Details | Raw Unified | Return to bug 240476 | Differences between
and this patch

Collapse All | Expand All

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

Return to bug 240476