lists.arthurdejong.org
RSS feed

python-pskc branch master updated. 1.1-18-gb9e17d3

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

python-pskc branch master updated. 1.1-18-gb9e17d3



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  b9e17d38cd5e0b07756f41a032ae35724061205c (commit)
       via  b543f2a27d6b84074c2be26582db596707c138e6 (commit)
      from  5c02ecf4510facaef6b8bbfd1985a015e4f29ce8 (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=b9e17d38cd5e0b07756f41a032ae35724061205c

commit b9e17d38cd5e0b07756f41a032ae35724061205c
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sun Jan 30 18:06:54 2022 +0100

    Support bytearray for key values
    
    Related to https://github.com/arthurdejong/python-pskc/issues/5

diff --git a/pskc/key.py b/pskc/key.py
index 89a76d2..cd1e4f3 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-2018 Arthur de Jong
+# Copyright (C) 2014-2022 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
@@ -39,7 +39,7 @@ class EncryptedValue(object):
     def create(cls, pskc, value):
         """Construct an encryped value from a plaintext value."""
         # force conversion to bytestring on Python 3
-        if not isinstance(value, type(b'')):
+        if not isinstance(value, (type(b''), bytearray)):
             value = value.encode()  # pragma: no cover (Python 3 specific)
         cipher_value = pskc.encryption.encrypt_value(value)
         mac_value = None
diff --git a/tests/test_write.doctest b/tests/test_write.doctest
index 779fc4c..3b6196a 100644
--- a/tests/test_write.doctest
+++ b/tests/test_write.doctest
@@ -1,6 +1,6 @@
 test_write.doctest - tests for writing PSKC files
 
-Copyright (C) 2014-2018 Arthur de Jong
+Copyright (C) 2014-2022 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
@@ -693,3 +693,59 @@ specify this (and re-using an IV is a bad idea).
   </pskc:Key>
  </pskc:KeyPackage>
 </pskc:KeyContainer>
+
+
+Check that we can add secrets as bytearray values
+
+>>> pskc = PSKC()
+>>> key = pskc.add_key(
+...     id='1', serial='123456', secret=bytearray(b'1234'), counter=42)
+>>> pskc.encryption.setup_preshared_key(
+...     algorithm='aes128-cbc',
+...     key=bytearray(a2b_hex('12345678901234567890123456789012')),
+...     key_name='Pre-shared KEY', fields = ['secret', 'counter'])
+>>> f = tempfile.NamedTemporaryFile()
+>>> pskc.write(f.name)
+>>> with open(f.name, 'r') as r:
+...     x = sys.stdout.write(r.read())  #doctest: +ELLIPSIS +REPORT_UDIFF
+<?xml version="1.0" encoding="UTF-8"?>
+<pskc:KeyContainer ... Version="1.0">
+ <pskc:EncryptionKey>
+  <ds:KeyName>Pre-shared KEY</ds:KeyName>
+ </pskc:EncryptionKey>
+ <pskc:MACMethod Algorithm="http://www.w3.org/2000/09/xmldsig#hmac-sha1";>
+  <pskc:MACKey>
+   <xenc:EncryptionMethod 
Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"/>
+   <xenc:CipherData>
+    <xenc:CipherValue>...</xenc:CipherValue>
+   </xenc:CipherData>
+  </pskc:MACKey>
+ </pskc:MACMethod>
+ <pskc:KeyPackage>
+  <pskc:DeviceInfo>
+   <pskc:SerialNo>123456</pskc:SerialNo>
+  </pskc:DeviceInfo>
+  <pskc:Key Id="1">
+   <pskc:Data>
+    <pskc:Secret>
+     <pskc:EncryptedValue>
+      <xenc:EncryptionMethod 
Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"/>
+      <xenc:CipherData>
+       <xenc:CipherValue>...</xenc:CipherValue>
+      </xenc:CipherData>
+     </pskc:EncryptedValue>
+     <pskc:ValueMAC>...</pskc:ValueMAC>
+    </pskc:Secret>
+    <pskc:Counter>
+     <pskc:EncryptedValue>
+      <xenc:EncryptionMethod 
Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"/>
+      <xenc:CipherData>
+       <xenc:CipherValue>...</xenc:CipherValue>
+      </xenc:CipherData>
+     </pskc:EncryptedValue>
+     <pskc:ValueMAC>...</pskc:ValueMAC>
+    </pskc:Counter>
+   </pskc:Data>
+  </pskc:Key>
+ </pskc:KeyPackage>
+</pskc:KeyContainer>

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

commit b543f2a27d6b84074c2be26582db596707c138e6
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sun Jan 30 17:50:08 2022 +0100

    Add support for Python 3.8 and 3.9

diff --git a/setup.py b/setup.py
index 8470616..99be573 100755
--- a/setup.py
+++ b/setup.py
@@ -61,6 +61,8 @@ setup(
         'Programming Language :: Python :: 3.5',
         'Programming Language :: Python :: 3.6',
         'Programming Language :: Python :: 3.7',
+        'Programming Language :: Python :: 3.8',
+        'Programming Language :: Python :: 3.9',
         'Programming Language :: Python :: Implementation :: PyPy',
         'Topic :: Security :: Cryptography',
         'Topic :: Software Development :: Libraries :: Python Modules',
diff --git a/tox.ini b/tox.ini
index 1783d83..56dbe19 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
 [tox]
-envlist = 
py{27,35,36,37,py,py3}-signxml,py{27,35,36,37,py,py3}{-legacy,-lxml}{,-defusedxml},flake8,docs
+envlist = 
py{27,35,36,37,38,39,py,py3}-signxml,py{27,35,36,37,38,39,py,py3}{-legacy,-lxml}{,-defusedxml},flake8,docs
 skip_missing_interpreters = True
 
 [testenv]
@@ -20,7 +20,7 @@ skip_install = true
 deps = flake8
        flake8-author
        flake8-blind-except
-       py{35,36,37}: flake8-bugbear
+       py{35,36,37,38,39}: flake8-bugbear
        flake8-class-newline
        flake8-commas
        flake8-deprecated

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

Summary of changes:
 pskc/key.py              |  4 ++--
 setup.py                 |  2 ++
 tests/test_write.doctest | 58 +++++++++++++++++++++++++++++++++++++++++++++++-
 tox.ini                  |  4 ++--
 4 files changed, 63 insertions(+), 5 deletions(-)


hooks/post-receive
-- 
python-pskc