Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/security/py-u2f security/py-u2f: Add NetBSD support.



details:   https://anonhg.NetBSD.org/pkgsrc/rev/7e2d7f093d23
branches:  trunk
changeset: 437151:7e2d7f093d23
user:      riastradh <riastradh%pkgsrc.org@localhost>
date:      Mon Aug 17 20:57:44 2020 +0000

description:
security/py-u2f: Add NetBSD support.

diffstat:

 security/py-u2f/Makefile                                |    3 +-
 security/py-u2f/PLIST                                   |    5 +-
 security/py-u2f/distinfo                                |    4 +-
 security/py-u2f/patches/patch-pyu2f_hid_____init____.py |   16 ++
 security/py-u2f/patches/patch-pyu2f_hid_netbsd.py       |  121 ++++++++++++++++
 5 files changed, 146 insertions(+), 3 deletions(-)

diffs (190 lines):

diff -r 1a3ab93aca4f -r 7e2d7f093d23 security/py-u2f/Makefile
--- a/security/py-u2f/Makefile  Mon Aug 17 20:37:53 2020 +0000
+++ b/security/py-u2f/Makefile  Mon Aug 17 20:57:44 2020 +0000
@@ -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 -r 1a3ab93aca4f -r 7e2d7f093d23 security/py-u2f/PLIST
--- a/security/py-u2f/PLIST     Mon Aug 17 20:37:53 2020 +0000
+++ b/security/py-u2f/PLIST     Mon Aug 17 20:57:44 2020 +0000
@@ -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/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 -r 1a3ab93aca4f -r 7e2d7f093d23 security/py-u2f/distinfo
--- a/security/py-u2f/distinfo  Mon Aug 17 20:37:53 2020 +0000
+++ b/security/py-u2f/distinfo  Mon Aug 17 20:57:44 2020 +0000
@@ -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 -r 1a3ab93aca4f -r 7e2d7f093d23 security/py-u2f/patches/patch-pyu2f_hid_____init____.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/security/py-u2f/patches/patch-pyu2f_hid_____init____.py   Mon Aug 17 20:57:44 2020 +0000
@@ -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 -r 1a3ab93aca4f -r 7e2d7f093d23 security/py-u2f/patches/patch-pyu2f_hid_netbsd.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/security/py-u2f/patches/patch-pyu2f_hid_netbsd.py Mon Aug 17 20:57:44 2020 +0000
@@ -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))



Home | Main Index | Thread Index | Old Index