lists.arthurdejong.org
RSS feed

python-pskc branch master updated. 0.5-36-g20bf9c5

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

python-pskc branch master updated. 0.5-36-g20bf9c5



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  20bf9c5b0ad9f05f763e88231b3aa7c47d34e1d5 (commit)
      from  c365a7004cec756ea573fb4414973ddf50739665 (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=20bf9c5b0ad9f05f763e88231b3aa7c47d34e1d5

commit 20bf9c5b0ad9f05f763e88231b3aa7c47d34e1d5
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Fri Dec 15 23:32:03 2017 +0100

    Add an is_encrypted property
    
    This property can be use to see whether the PSKC file needs an
    additional pre-shared key or passphrase to decrypt any stored
    information.

diff --git a/docs/encryption.rst b/docs/encryption.rst
index b1d008a..a6e26d1 100644
--- a/docs/encryption.rst
+++ b/docs/encryption.rst
@@ -61,6 +61,12 @@ The Encryption class
       ``http://www.w3.org/2001/04/xmlenc#tripledes-cbc``.
 
 
+   .. attribute:: is_encrypted
+
+      An indicator of whether the PSKC file requires an additional pre-shared
+      key or passphrase to decrypt the contents of the file. Will be ``True``
+      if a key or passphrase is needed, ``False`` otherwise.
+
    .. attribute:: key_names
 
       List of names provided for the encryption key.
diff --git a/pskc/encryption.py b/pskc/encryption.py
index 6d20daa..6a1358f 100644
--- a/pskc/encryption.py
+++ b/pskc/encryption.py
@@ -314,6 +314,18 @@ class Encryption(object):
         from pskc.algorithms import normalise_algorithm
         self._algorithm = normalise_algorithm(value)
 
+    @property
+    def is_encrypted(self):
+        """Test whether the PSKC file requires a decryption key."""
+        from pskc.exceptions import DecryptionError
+        try:
+            for key in self.pskc.keys:
+                key.secret, key.counter, key.time_offset
+                key.time_interval, key.time_drift
+        except DecryptionError:
+            return True
+        return False
+
     def derive_key(self, password):
         """Derive a key from the password."""
         self.key = self.derivation.derive(password)
diff --git a/pskc2csv.py b/pskc2csv.py
index b6cba09..66008c9 100755
--- a/pskc2csv.py
+++ b/pskc2csv.py
@@ -111,17 +111,6 @@ def get_column(key, column, encoding):
     return value
 
 
-def is_encrypted(pskcfile):
-    """Check whether the PSKC file is encrypted."""
-    try:
-        pskcfile.keys[0].secret
-    except DecryptionError:
-        return True
-    except IndexError:
-        pass
-    return False
-
-
 def main():
     # parse command-line arguments
     args = parser.parse_args()
@@ -140,7 +129,7 @@ def main():
             pskcfile.encryption.derive_key(passwd)
         else:
             pskcfile.encryption.derive_key(args.password)
-    elif sys.stdin.isatty() and is_encrypted(pskcfile):
+    elif sys.stdin.isatty() and pskcfile.encryption.is_encrypted:
         # prompt for a password
         prompt = 'Password: '
         if pskcfile.encryption.key_name:
diff --git a/tests/test_rfc6030.doctest b/tests/test_rfc6030.doctest
index 33d0d01..df5193b 100644
--- a/tests/test_rfc6030.doctest
+++ b/tests/test_rfc6030.doctest
@@ -160,9 +160,13 @@ encryption.
 Traceback (most recent call last):
     ...
 DecryptionError: No key available
+>>> pskc.encryption.is_encrypted
+True
 >>> pskc.encryption.key_name
 'Pre-shared-key'
 >>> pskc.encryption.key = a2b_hex('12345678901234567890123456789012')
+>>> pskc.encryption.is_encrypted
+False
 >>> pskc.encryption.algorithm
 'http://www.w3.org/2001/04/xmlenc#aes128-cbc'
 >>> b2a_hex(pskc.mac.key)
@@ -186,7 +190,11 @@ This tests a derived master key using PBKDF2 as seen in 
figure 7 of RFC 6030.
 >>> pskc = PSKC('tests/rfc6030/figure7.pskcxml')
 >>> pskc.encryption.key_name
 'My Password 1'
+>>> pskc.encryption.is_encrypted
+True
 >>> pskc.encryption.derive_key('qwerty')
+>>> pskc.encryption.is_encrypted
+False
 >>> b2a_hex(pskc.encryption.key)
 '651e63cd57008476af1ff6422cd02e41'
 >>> pskc.encryption.algorithm

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

Summary of changes:
 docs/encryption.rst        |  6 ++++++
 pskc/encryption.py         | 12 ++++++++++++
 pskc2csv.py                | 13 +------------
 tests/test_rfc6030.doctest |  8 ++++++++
 4 files changed, 27 insertions(+), 12 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/