lists.arthurdejong.org
RSS feed

python-pskc branch master updated. 0.5-9-g0c00c80

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-pskc branch master updated. 0.5-9-g0c00c80



This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "python-pskc".

The branch, master has been updated
       via  0c00c8047d82a226a1a8d2f29968218b1768cbf7 (commit)
       via  510e6a5fb2c6728b55f34fb941e58fc1f0fed260 (commit)
       via  d72e6cc3069e280756c59d42406a070529ee8498 (commit)
       via  7b106ff8ed5ee0295dfdb8035a3e9e8f2759cc71 (commit)
      from  f0d2991ed71824551db9726fdd4bc975f192ee27 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://arthurdejong.org/git/python-pskc/commit/?id=0c00c8047d82a226a1a8d2f29968218b1768cbf7

commit 0c00c8047d82a226a1a8d2f29968218b1768cbf7
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sat Jun 10 14:11:53 2017 +0200

    Various minor code style improvements

diff --git a/pskc/__init__.py b/pskc/__init__.py
index c63bc0e..def4a33 100644
--- a/pskc/__init__.py
+++ b/pskc/__init__.py
@@ -86,6 +86,7 @@ class PSKC(object):
 
     @property
     def keys(self):
+        """list of keys"""
         return tuple(key for device in self.devices for key in device.keys)
 
     def add_device(self, **kwargs):
diff --git a/pskc/encryption.py b/pskc/encryption.py
index 59ee489..0da9f82 100644
--- a/pskc/encryption.py
+++ b/pskc/encryption.py
@@ -172,7 +172,7 @@ class KeyDerivation(object):
         if self.pbkdf2_prf:
             prf = get_mac_fn(self.pbkdf2_prf)
         if not all((password, self.pbkdf2_salt, self.pbkdf2_key_length,
-                   self.pbkdf2_iterations)):
+                    self.pbkdf2_iterations)):
             raise KeyDerivationError('Incomplete PBKDF2 configuration')
         try:
             return PBKDF2(
@@ -180,7 +180,7 @@ class KeyDerivation(object):
                 count=self.pbkdf2_iterations, prf=prf)
         except DecryptionError:
             raise KeyDerivationError(
-                    'Pseudorandom function unsupported: %r' % self.pbkdf2_prf)
+                'Pseudorandom function unsupported: %r' % self.pbkdf2_prf)
 
     def derive(self, password):
         """Derive a key from the password."""
diff --git a/pskc/parser.py b/pskc/parser.py
index eac9cb8..a899e82 100644
--- a/pskc/parser.py
+++ b/pskc/parser.py
@@ -31,6 +31,8 @@ class PSKCParser(object):
 
     @classmethod
     def parse_file(cls, pskc, filename):
+        """Parse the provided file and store information in the existing
+        PSKC instance."""
         try:
             tree = parse(filename)
         except Exception:
@@ -136,7 +138,8 @@ class PSKCParser(object):
         """Read key information from the provided <KeyPackage> tree."""
 
         key.id = key_elm.get('Id') or key_elm.get('KeyId')
-        key.algorithm = key_elm.get('Algorithm') or key_elm.get('KeyAlgorithm')
+        key.algorithm = (
+            key_elm.get('Algorithm') or key_elm.get('KeyAlgorithm'))
 
         data = find(key_elm, 'Data')
         if data is not None:
diff --git a/pskc/serialiser.py b/pskc/serialiser.py
index dd498d0..57eccf2 100644
--- a/pskc/serialiser.py
+++ b/pskc/serialiser.py
@@ -1,7 +1,7 @@
 # serialiser.py - PSKC file parsing functions
 # coding: utf-8
 #
-# Copyright (C) 2016 Arthur de Jong
+# Copyright (C) 2016-2017 Arthur de Jong
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -202,9 +202,10 @@ class PSKCSerialiser(object):
         # check if any policy attribute is set
         if not policy.key_usage and all(x is None for x in (
                 policy.start_date, policy.expiry_date,
-                policy.number_of_transactions, policy.pin_key_id, 
policy.pin_usage,
-                policy.pin_max_failed_attemtps, policy.pin_min_length,
-                policy.pin_max_length, policy.pin_encoding)):
+                policy.number_of_transactions, policy.pin_key_id,
+                policy.pin_usage, policy.pin_max_failed_attemtps,
+                policy.pin_min_length, policy.pin_max_length,
+                policy.pin_encoding)):
             return
         policy_elm = mk_elem(key_elm, 'pskc:Policy', empty=True)
         mk_elem(policy_elm, 'pskc:StartDate', policy.start_date)
diff --git a/pskc/xml.py b/pskc/xml.py
index ea1e412..65bb174 100644
--- a/pskc/xml.py
+++ b/pskc/xml.py
@@ -1,7 +1,7 @@
 # xml.py - module for parsing and writing XML for PSKC files
 # coding: utf-8
 #
-# Copyright (C) 2014-2016 Arthur de Jong
+# Copyright (C) 2014-2017 Arthur de Jong
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -47,9 +47,13 @@ namespaces = dict(
 )
 
 
-# register the namespaces so the correct short names will be used
-for ns, namespace in namespaces.items():
-    etree.register_namespace(ns, namespace)
+def register_namespaces():
+    """Register the namespaces so the correct short names will be used."""
+    for ns, namespace in namespaces.items():
+        etree.register_namespace(ns, namespace)
+
+
+register_namespaces()
 
 
 def parse(source):
diff --git a/pskc2csv.py b/pskc2csv.py
index 44ef70c..4089968 100755
--- a/pskc2csv.py
+++ b/pskc2csv.py
@@ -58,6 +58,7 @@ class VersionAction(argparse.Action):
         print(version_string)
         parser.exit()
 
+
 epilog = '''
 supported columns:
   id, serial, secret, counter, time_offset, time_interval, interval,
@@ -93,6 +94,8 @@ parser.add_argument(
 # Python 3 compatible version of b2a_hex
 def decode(f):
     return lambda x: str(f(x).decode())
+
+
 b2a_hex = decode(b2a_hex)
 
 

https://arthurdejong.org/git/python-pskc/commit/?id=510e6a5fb2c6728b55f34fb941e58fc1f0fed260

commit 510e6a5fb2c6728b55f34fb941e58fc1f0fed260
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sat Jun 10 13:59:00 2017 +0200

    Normalise key derivation algorithms
    
    This makes KeyDerivation.algorithm and KeyDerivation.pbkdf2_prf
    properties automatically normalise assigned values.

diff --git a/pskc/encryption.py b/pskc/encryption.py
index 0fcc444..59ee489 100644
--- a/pskc/encryption.py
+++ b/pskc/encryption.py
@@ -135,12 +135,34 @@ class KeyDerivation(object):
     """
 
     def __init__(self):
-        self.algorithm = None
+        self._algorithm = None
         # PBKDF2 properties
         self.pbkdf2_salt = None
         self.pbkdf2_iterations = None
         self.pbkdf2_key_length = None
-        self.pbkdf2_prf = None
+        self._pbkdf2_prf = None
+
+    @property
+    def algorithm(self):
+        """Provide the key derivation algorithm used."""
+        if self._algorithm:
+            return self._algorithm
+
+    @algorithm.setter
+    def algorithm(self, value):
+        from pskc.algorithms import normalise_algorithm
+        self._algorithm = normalise_algorithm(value)
+
+    @property
+    def pbkdf2_prf(self):
+        """Provide the PBKDF2 pseudorandom function used."""
+        if self._pbkdf2_prf:
+            return self._pbkdf2_prf
+
+    @pbkdf2_prf.setter
+    def pbkdf2_prf(self, value):
+        from pskc.algorithms import normalise_algorithm
+        self._pbkdf2_prf = normalise_algorithm(value)
 
     def derive_pbkdf2(self, password):
         from Crypto.Protocol.KDF import PBKDF2
@@ -174,8 +196,7 @@ class KeyDerivation(object):
     def setup_pbkdf2(self, password, salt=None, salt_length=16,
                      key_length=None, iterations=None, prf=None):
         from Crypto import Random
-        from pskc.algorithms import normalise_algorithm
-        self.algorithm = normalise_algorithm('pbkdf2')
+        self.algorithm = 'pbkdf2'
         if salt is None:
             salt = Random.get_random_bytes(salt_length)
         self.pbkdf2_salt = salt
@@ -186,7 +207,7 @@ class KeyDerivation(object):
         if key_length:  # pragma: no branch (always specified)
             self.pbkdf2_key_length = key_length
         if prf:
-            self.pbkdf2_prf = normalise_algorithm(prf)
+            self.pbkdf2_prf = prf
         return self.derive_pbkdf2(password)
 
 
diff --git a/pskc/parser.py b/pskc/parser.py
index 98359ca..eac9cb8 100644
--- a/pskc/parser.py
+++ b/pskc/parser.py
@@ -21,7 +21,6 @@
 """Module for parsing PSKC files."""
 
 
-from pskc.algorithms import normalise_algorithm
 from pskc.exceptions import ParseError
 from pskc.xml import (
     find, findall, findbin, findint, findtext, findtime, getbool, getint,
@@ -99,8 +98,7 @@ class PSKCParser(object):
             # pseudorandom function used
             prf = find(pbkdf2, 'PRF')
             if prf is not None:
-                derivation.pbkdf2_prf = normalise_algorithm(
-                    prf.get('Algorithm'))
+                derivation.pbkdf2_prf = prf.get('Algorithm')
 
     @classmethod
     def parse_mac_method(cls, mac, mac_method):

https://arthurdejong.org/git/python-pskc/commit/?id=d72e6cc3069e280756c59d42406a070529ee8498

commit d72e6cc3069e280756c59d42406a070529ee8498
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sat Jun 10 13:51:53 2017 +0200

    Switch to using non-deprecated method
    
    This uses ElementTree.iter() instead of ElementTree.getiterator() for
    going over all the child elements in the tree because the latter is
    deprecated.

diff --git a/pskc/xml.py b/pskc/xml.py
index d5288b3..ea1e412 100644
--- a/pskc/xml.py
+++ b/pskc/xml.py
@@ -60,7 +60,7 @@ def parse(source):
 def remove_namespaces(tree):
     """Remove namespaces from all elements in the tree."""
     import re
-    for elem in tree.getiterator():
+    for elem in tree.iter():
         if isinstance(elem.tag, ''.__class__):  # pragma: no branch
             elem.tag = re.sub(r'^\{[^}]*\}', '', elem.tag)
 

https://arthurdejong.org/git/python-pskc/commit/?id=7b106ff8ed5ee0295dfdb8035a3e9e8f2759cc71

commit 7b106ff8ed5ee0295dfdb8035a3e9e8f2759cc71
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sat Jun 10 13:49:38 2017 +0200

    Provide Key.userid convenience property
    
    This provides a read-only userid property on Key objects that uses the
    key_userid or device_userid value, whichever one is defined.

diff --git a/docs/usage.rst b/docs/usage.rst
index e53d0b8..2c386ec 100644
--- a/docs/usage.rst
+++ b/docs/usage.rst
@@ -223,6 +223,12 @@ The Key class
       The distinguished name of the user associated with the key.
       Also see :attr:`~pskc.device.Device.device_userid`.
 
+   .. attribute:: userid
+
+      The distinguished name of the user associated with the key or the device,
+      taken from :attr:`key_userid` or 
:attr:`~pskc.device.Device.device_userid`
+      whichever one is defined.
+
    .. attribute:: algorithm_suite
 
       Additional algorithm-specific characteristics. For example, in an
diff --git a/pskc/key.py b/pskc/key.py
index 0ff5edb..3ab8681 100644
--- a/pskc/key.py
+++ b/pskc/key.py
@@ -1,7 +1,7 @@
 # key.py - module for handling keys from pskc files
 # coding: utf-8
 #
-# Copyright (C) 2014-2016 Arthur de Jong
+# Copyright (C) 2014-2017 Arthur de Jong
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -275,3 +275,8 @@ class Key(object):
                 self.secret, self.counter, self.time_offset,
                 self.time_interval, self.time_drift)):
             return True
+
+    @property
+    def userid(self):
+        """User identifier (either the key or device userid)."""
+        return self.key_userid or self.device_userid
diff --git a/tests/test_yubico.doctest b/tests/test_yubico.doctest
index d3ed4e5..774e2c9 100644
--- a/tests/test_yubico.doctest
+++ b/tests/test_yubico.doctest
@@ -56,7 +56,7 @@ datetime.datetime(2009, 1, 22, 0, 25, 11, tzinfo=tzutc())
 44
 >>> b2a_hex(key.secret)
 '2b7e151628aed2a6abf7158809cf4f3c'
->>> key.key_userid
+>>> key.userid
 'CN=ekhgjhbctrgn, UID=ca62baca62ba'
 
 
@@ -88,7 +88,7 @@ datetime.datetime(2009, 1, 22, 0, 25, 10, tzinfo=tzutc())
 44
 >>> b2a_hex(key.secret)
 '5698356d30868c4201e26f66c582bb45'
->>> key.key_userid
+>>> key.userid
 'CN=ekhgjhbctrgn, UID=ca62baca62ba'
 >>> key = pskc.keys[1]  # second key
 >>> key.manufacturer
@@ -111,7 +111,7 @@ datetime.datetime(2009, 1, 22, 0, 25, 10, tzinfo=tzutc())
 44
 >>> b2a_hex(key.secret)
 '38892b82abf1807788458fc5a5165c80'
->>> key.key_userid
+>>> key.userid
 'CN=ekhgjhbctrgn, UID=ca62baca62ba'
 
 
@@ -143,7 +143,7 @@ datetime.datetime(2009, 1, 22, 0, 25, 9, tzinfo=tzutc())
 40
 >>> b2a_hex(key.secret)
 '2b7e151628aed2a6abf7158809cf4f3c'
->>> key.key_userid
+>>> key.userid
 'CN=ekhgjhbctrgn, UID=ca62baca62ba'
 
 # TODO: support extensions

-----------------------------------------------------------------------

Summary of changes:
 docs/usage.rst            |  6 ++++++
 pskc/__init__.py          |  1 +
 pskc/encryption.py        | 35 ++++++++++++++++++++++++++++-------
 pskc/key.py               |  7 ++++++-
 pskc/parser.py            |  9 +++++----
 pskc/serialiser.py        |  9 +++++----
 pskc/xml.py               | 14 +++++++++-----
 pskc2csv.py               |  3 +++
 tests/test_yubico.doctest |  8 ++++----
 9 files changed, 67 insertions(+), 25 deletions(-)


hooks/post-receive
-- 
python-pskc
-- 
To unsubscribe send an email to
python-pskc-commits-unsubscribe@lists.arthurdejong.org or see
https://lists.arthurdejong.org/python-pskc-commits/