summaryrefslogtreecommitdiff
path: root/security
diff options
context:
space:
mode:
authorriastradh <riastradh@pkgsrc.org>2020-08-17 20:57:44 +0000
committerriastradh <riastradh@pkgsrc.org>2020-08-17 20:57:44 +0000
commit1df1f0e18a745d0d1494fb63b8a22c7212ec977e (patch)
tree7b98e68d5d76c264fed7900c1a6c12b33d51b472 /security
parenta5df19469392f04a1859029bac69d966916189b9 (diff)
downloadpkgsrc-1df1f0e18a745d0d1494fb63b8a22c7212ec977e.tar.gz
security/py-u2f: Add NetBSD support.
Diffstat (limited to 'security')
-rw-r--r--security/py-u2f/Makefile3
-rw-r--r--security/py-u2f/PLIST5
-rw-r--r--security/py-u2f/distinfo4
-rw-r--r--security/py-u2f/patches/patch-pyu2f_hid_____init____.py16
-rw-r--r--security/py-u2f/patches/patch-pyu2f_hid_netbsd.py121
5 files changed, 146 insertions, 3 deletions
diff --git a/security/py-u2f/Makefile b/security/py-u2f/Makefile
index c3917aa9520..b6b4776ee71 100644
--- a/security/py-u2f/Makefile
+++ b/security/py-u2f/Makefile
@@ -1,7 +1,8 @@
-# $NetBSD: Makefile,v 1.1 2018/05/30 16:09:52 bsiegert Exp $
+# $NetBSD: Makefile,v 1.2 2020/08/17 20:57:44 riastradh Exp $
DISTNAME= pyu2f-0.1.4
PKGNAME= ${PYPKGPREFIX}-${DISTNAME:S/py//}
+PKGREVISION= 1
CATEGORIES= security python
MASTER_SITES= ${MASTER_SITE_PYPI:=p/pyu2f/}
diff --git a/security/py-u2f/PLIST b/security/py-u2f/PLIST
index 0c881d38e57..e809a9450d9 100644
--- a/security/py-u2f/PLIST
+++ b/security/py-u2f/PLIST
@@ -1,4 +1,4 @@
-@comment $NetBSD: PLIST,v 1.1 2018/05/30 16:09:52 bsiegert Exp $
+@comment $NetBSD: PLIST,v 1.2 2020/08/17 20:57:44 riastradh Exp $
${PYSITELIB}/${EGG_INFODIR}/PKG-INFO
${PYSITELIB}/${EGG_INFODIR}/SOURCES.txt
${PYSITELIB}/${EGG_INFODIR}/dependency_links.txt
@@ -44,6 +44,9 @@ ${PYSITELIB}/pyu2f/hid/linux.pyo
${PYSITELIB}/pyu2f/hid/macos.py
${PYSITELIB}/pyu2f/hid/macos.pyc
${PYSITELIB}/pyu2f/hid/macos.pyo
+${PYSITELIB}/pyu2f/hid/netbsd.py
+${PYSITELIB}/pyu2f/hid/netbsd.pyc
+${PYSITELIB}/pyu2f/hid/netbsd.pyo
${PYSITELIB}/pyu2f/hid/try.py
${PYSITELIB}/pyu2f/hid/try.pyc
${PYSITELIB}/pyu2f/hid/try.pyo
diff --git a/security/py-u2f/distinfo b/security/py-u2f/distinfo
index 9aebcde2601..4be86fdd114 100644
--- a/security/py-u2f/distinfo
+++ b/security/py-u2f/distinfo
@@ -1,6 +1,8 @@
-$NetBSD: distinfo,v 1.1 2018/05/30 16:09:52 bsiegert Exp $
+$NetBSD: distinfo,v 1.2 2020/08/17 20:57:44 riastradh Exp $
SHA1 (pyu2f-0.1.4.tar.gz) = 49be1741ad1c853ddfea6b82faf5113daaa8f1df
RMD160 (pyu2f-0.1.4.tar.gz) = 4cd83ad544d5d9700d4b6d9855443874d8ac053f
SHA512 (pyu2f-0.1.4.tar.gz) = 1c2a23acd3ab25f07a2800c21f556da1eee1e28269f02f4bab057e38494d5345837d1e015a323d769e594751fb0f852e00e718d6350b1a75b2596dae6cd9bdd5
Size (pyu2f-0.1.4.tar.gz) = 23261 bytes
+SHA1 (patch-pyu2f_hid_____init____.py) = 2f648792c78432776c4074e3bb2df0a195f65154
+SHA1 (patch-pyu2f_hid_netbsd.py) = d8df1b3805ad5e830548df5b6a601abf09a5dfa3
diff --git a/security/py-u2f/patches/patch-pyu2f_hid_____init____.py b/security/py-u2f/patches/patch-pyu2f_hid_____init____.py
new file mode 100644
index 00000000000..72859cad430
--- /dev/null
+++ b/security/py-u2f/patches/patch-pyu2f_hid_____init____.py
@@ -0,0 +1,16 @@
+$NetBSD: patch-pyu2f_hid_____init____.py,v 1.1 2020/08/17 20:57:44 riastradh Exp $
+
+Add NetBSD support.
+
+--- pyu2f/hid/__init__.py.orig 2020-08-17 20:48:34.101158593 +0000
++++ pyu2f/hid/__init__.py
+@@ -41,6 +41,9 @@ def InternalPlatformSwitch(funcname, *ar
+ elif sys.platform.startswith('darwin'):
+ from pyu2f.hid import macos
+ clz = macos.MacOsHidDevice
++ elif sys.platform.startswith('netbsd'):
++ from pyu2f.hid import netbsd
++ clz = netbsd.NetBSDHidDevice
+
+ if not clz:
+ raise Exception('Unsupported platform: ' + sys.platform)
diff --git a/security/py-u2f/patches/patch-pyu2f_hid_netbsd.py b/security/py-u2f/patches/patch-pyu2f_hid_netbsd.py
new file mode 100644
index 00000000000..5365a1efde7
--- /dev/null
+++ b/security/py-u2f/patches/patch-pyu2f_hid_netbsd.py
@@ -0,0 +1,121 @@
+$NetBSD: patch-pyu2f_hid_netbsd.py,v 1.1 2020/08/17 20:57:44 riastradh Exp $
+
+Add NetBSD support.
+
+--- pyu2f/hid/netbsd.py.orig 2020-08-17 20:43:03.167593821 +0000
++++ pyu2f/hid/netbsd.py
+@@ -0,0 +1,114 @@
++# Copyright 2016 Google Inc. All Rights Reserved.
++#
++# Licensed under the Apache License, Version 2.0 (the "License");
++# you may not use this file except in compliance with the License.
++# You may obtain a copy of the License at
++#
++# http://www.apache.org/licenses/LICENSE-2.0
++#
++# Unless required by applicable law or agreed to in writing, software
++# distributed under the License is distributed on an "AS IS" BASIS,
++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
++# See the License for the specific language governing permissions and
++# limitations under the License.
++
++"""Implements raw HID interface on NetBSD."""
++
++from __future__ import absolute_import
++
++import errno
++import os
++import select
++import struct
++import sys
++
++from fcntl import ioctl
++
++from pyu2f.hid import base
++from pyu2f.hid import linux
++
++
++# struct usb_ctl_report_desc {
++# int ucrd_size;
++# unsigned char ucrd_data[1024];
++# };
++
++SIZEOF_USB_CTL_REPORT_DESC = 4 + 1024
++USB_GET_REPORT_DESC = 0x44045515 # _IOR('U', 21, struct usb_ctl_report_desc)
++
++SIZEOF_USB_DEVICE_INFO = 1268
++USB_DEVICE_INFO_PRODUCT = 1168
++USB_DEVICE_INFO_VENDOR = 1170
++USB_GET_DEVICE_INFO = 0x44f45570 # _IOR('U', 112, struct usb_device_info)
++
++USB_HID_SET_RAW = 0x80046802 # _IOW('h', 2, int)
++
++
++FIDO_USAGE_PAGE = 0xf1d0
++FIDO_USAGE_U2FHID = 0x01
++
++
++class NetBSDHidDevice(linux.LinuxHidDevice):
++ """Implementation of HID device for NetBSD.
++ """
++
++ @classmethod
++ def _setup(cls, fd, path):
++ devinfo = bytearray([0] * SIZEOF_USB_DEVICE_INFO)
++ ioctl(fd, USB_GET_DEVICE_INFO, devinfo, True)
++ vendor = devinfo[USB_DEVICE_INFO_VENDOR:USB_DEVICE_INFO_VENDOR + 2]
++ product = devinfo[USB_DEVICE_INFO_PRODUCT:USB_DEVICE_INFO_PRODUCT + 2]
++ descbuf = bytearray([0] * SIZEOF_USB_CTL_REPORT_DESC)
++ ioctl(fd, USB_GET_REPORT_DESC, descbuf, True)
++ descsize = struct.unpack('@i', descbuf[0:4])[0]
++ descdata = descbuf[4:4 + descsize]
++ desc = base.DeviceDescriptor()
++ desc.path = path
++ desc.vendor_id = struct.unpack('@H', vendor)[0]
++ desc.product_id = struct.unpack('@H', product)[0]
++ linux.ParseReportDescriptor(descdata, desc)
++ if desc.usage_page != FIDO_USAGE_PAGE:
++ raise Exception('usage page != fido')
++ if desc.usage != FIDO_USAGE_U2FHID:
++ raise Exception('fido usage != u2fhid')
++ ioctl(fd, USB_HID_SET_RAW, struct.pack('@i', 1))
++ ping = bytearray([0] * 64)
++ ping[0:7] = bytearray([0xff,0xff,0xff,0xff,0x81,0,1])
++ for i in range(10):
++ os.write(fd, ping)
++ poll = select.poll()
++ poll.register(fd, select.POLLIN)
++ if poll.poll(100):
++ os.read(fd, 64 + 1)
++ break
++ else:
++ raise Exception('u2f ping timeout')
++ return desc
++
++ @classmethod
++ def Enumerate(cls):
++ for i in range(100):
++ path = '/dev/uhid{}'.format(i)
++ fd = None
++ try:
++ fd = os.open(path, os.O_RDWR|os.O_CLOEXEC)
++ desc = cls._setup(fd, path)
++ except OSError as e:
++ if e.errno == errno.ENOENT:
++ break
++ continue
++ finally:
++ if fd is not None:
++ os.close(fd)
++ yield desc.ToPublicDict()
++
++ def __init__(self, path):
++ base.HidDevice.__init__(self, path)
++ self.dev = os.open(path, os.O_RDWR)
++ self.desc = self._setup(self.dev, path)
++
++ def __del__(self):
++ os.close(self.dev)
++
++ def Write(self, packet):
++ os.write(self.dev, bytearray(packet))