Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/pskc/key.py
Commit message (Collapse)AuthorAgeFilesLines
* Fix typos (thanks codespell)Arthur de Jong2023-11-121-2/+2
|
* Support bytearray for key valuesArthur de Jong2022-01-301-2/+2
| | | | Related to https://github.com/arthurdejong/python-pskc/issues/5
* Fix typos found by codespellArthur de Jong2021-08-101-1/+1
|
* Be consistent in referencing RFC 6030Arthur de Jong2020-01-051-1/+1
|
* Add and cleanup docstringsArthur de Jong2018-02-151-1/+4
| | | | | | | | This adds docstrings to public methods and cleans up a few other docstrings to pass most flake8 docstring related tests. This also adds noqa statements in a few places so we can remove most entries from the global flake8 ignore list.
* Refactor internal storate of encrypted valuesArthur de Jong2017-12-151-121/+46
| | | | | | | | | | | This changes the way encrypted values are stored internally before being decrypted. For example, the internal _secret property can now be a decrypted plain value or an EncryptedValue instance instead of always being a DataType, simplifying some things (e.g. all XML encoding/decoding is now done in the corresponding module). This should not change the public API but does have consequences for those who use custom serialisers or parsers.
* Provide Key.userid convenience propertyArthur de Jong2017-06-101-1/+6
| | | | | This provides a read-only userid property on Key objects that uses the key_userid or device_userid value, whichever one is defined.
* Allow MAC over plaintext or ciphertextArthur de Jong2016-12-201-14/+13
| | | | | | | | | | | | | | | | | | RFC 6030 implies that the MAC should be performed over the ciphertext but some earlier drafts implied that the MAC should be performed on the plaintext. This change accpets the MAC if either the plaintext or ciphertext match. Note that this change allows for a padding oracle attack when CBC encryption modes are used because decryption (and unpadding) needs to be done before MAC checking. However, this module is not expected to be available to users to process arbitrary PSKC files repeatedly. This removes the tests for a missing MAC key (and replaces it for tests of missing EncryptionMethod) because falling back to using the encryption key (implemented in a444f78) in combination with this change means that decryption is performed before MAC checking and is no longer possible to trigger a missing MAC key error.
* Use custom data descriptors for key propertiesArthur de Jong2016-09-171-24/+25
| | | | | This uses a custom data descriptor (property) for secret, counter, time_offset, time_interval and time_drift.
* Support separate device from keyArthur de Jong2016-09-171-29/+36
| | | | | | | | This allows having multiple keys per device while also maintaining the previous API. Note that having multiple keys per device is not allowed by the RFC 6030 schema but is allowed by some older internet drafts.
* Move XML generation to own moduleArthur de Jong2016-09-171-92/+0
| | | | | Similar to the change for parsing, move the XML serialisation of PSKC data to a single class in a separate module.
* Move document parsing to own moduleArthur de Jong2016-09-171-90/+0
| | | | | | This moves all the parse() functions to a single class in a dedicated module that can be used for parsing PSKC files. This should make it easier to subclass the parser.
* Improve branch coverageArthur de Jong2016-09-141-1/+2
| | | | This enables branch coverage testing and adds tests to improve coverage.
* Fall back to encryption key for MACArthur de Jong2016-04-231-1/+1
| | | | | | This uses the encryption key also as MAC key if no MAC key has been specified in the PSKC file. Earlier versions of the PSKC draft specified this behaviour.
* Remove parse call from constructorsArthur de Jong2016-04-051-7/+2
| | | | This makes the creation if internal instances a litte more consistent.
* Generate MAC valuesArthur de Jong2016-03-261-0/+7
|
* Write out encrypted valuesArthur de Jong2016-03-261-11/+45
| | | | | | | | | The Encryption class now has a fields property that lists the fields that should be encrypted when writing the PSKC file. This adds an encrypt_value() function that performs the encryption and various functions to convert the plain value to binary before writing the encrypted XML elements.
* Improve tests and test coverageArthur de Jong2016-03-191-4/+4
| | | | | | | | | | This adds tests to ensure that incorrect attribute and value types in the PSKC file raise a ValueError exception and extends the tests for invalid encryption options. This removes some code or adds no cover directives to a few places that have unreachable code or are Python version specific and places doctest directives inside the doctests where needed.
* Support both CheckDigit and CheckDigitsArthur de Jong2016-03-191-2/+6
| | | | | | RFC 6030 is not clear about whether the attribute of ChallengeFormat and ResponseFormat should be the singular CheckDigit or the plural CheckDigits. This ensures that both forms are accepted.
* Support various integer representationsArthur de Jong2016-03-191-3/+14
| | | | | | | | | | | | | | | | | | | This extends support for handling various encoding methods for integer values in PSKC files. For encrypted files the decrypted value is first tried to be evaluated as an ASCII representation of the number and after that big-endian decoded. For plaintext values first ASCII decoding is tried after which base64 decoding is tried which tries the same encodings as for decrypted values. There should be no possibility for any base64 encoded value (either of an ASCII value or a big-endian value) to be interpreted as an ASCII value for any 32-bit integer. There is a possibility that a big-endian encoded integer could be incorrectly interpreted as an ASCII value but this is only the case for 110 numbers when only considering 6-digit numbers.
* Refactor out EncryptedValue and ValueMACArthur de Jong2016-01-241-29/+54
| | | | | | | | | This removes the EncryptedValue and ValueMAC classes and instead moves the XML parsing of these values to the DataType class. This will make it easier to support different parsing schemes. This also includes a small consistency improvement in the subclasses of DataType.
* Fix a problem when writing previously encrypted fileArthur de Jong2016-01-241-1/+1
| | | | | This fixes a problem with writing a PSKC file that is based on a read file that was encrypted.
* Strip XML namespaces before parsingArthur de Jong2016-01-241-39/+30
| | | | | | | | | This simplifies calls to the find() family of functions and allows parsing PSKC files that have slightly different namespace URLs. This is especially common when parsing old draft versions of the specification. This also removes passing multiple patterns to the find() functions that was introduced in 68b20e2.
* Make value conversion methods static privateMathias Laurin2015-11-301-11/+20
| | | | | - the conversions do not call self: they are static - the conversions are not to be used out of the class: make private
* Provide abstract methods to clarify APIMathias Laurin2015-11-301-4/+12
|
* Support Python 3Arthur de Jong2015-10-061-2/+5
| | | | | | | | This enables support for Python 3 together with Python 2 support with a single codebase. On Python 3 key data is passed around as bytestrings which makes the doctests a little harder to maintain across Python versions.
* Rename pskc.parse to pskc.xmlArthur de Jong2014-10-091-4/+4
| | | | | | | This renames the parse module to xml to better reflect the purpose of the module and it's functions. This also introduces a parse() function that wraps etree.parse().
* Construct XML document with basic PKSC informationArthur de Jong2014-06-281-0/+75
| | | | | | This introduces make_xml() functions to build an XML document that contains the basic PSKC information and keys. This currently only supports writing unencrypted PSKC files.
* Simplify DataType value handlingArthur de Jong2014-06-271-38/+32
| | | | | | | Only store the native value of the property, not the text representation. This also results in the BinaryDataType and IntegerDataType subclasses only needing from_text() and from_bin() functions.
* Refactor out some functions to parseArthur de Jong2014-06-151-16/+6
| | | | | This introduces the getint() and getbool() functions in parse to avoid some code duplication.
* Add support for setting secretArthur de Jong2014-06-151-24/+39
| | | | | | This supports setters for the secret, counter, time_offset, time_interval and time_drift properties. Setting these values stores the values unencrypted internally.
* Raise exception when MAC validation failsArthur de Jong2014-06-141-16/+15
| | | | | | | | | This changes the way the check() function works to raise an exception when the MAC is not correct. The MAC is also now always checked before attempting decryption. This also renames the internal DataType.value property to a get_value() method for clarity.
* Have parse module provide find() functionsArthur de Jong2014-06-141-43/+39
| | | | | | | | This changes the parse module functions to better match the ElementTree API and extends it with findint(), findtime() and findbin(). It also passes the namespaces to all calls that require it without duplicating this throughout the normal code.
* Use get() instead of attrib.get() (shorter)Arthur de Jong2014-06-141-19/+19
|
* Add a function for adding a new keyArthur de Jong2014-05-251-1/+1
|
* Code simplificationArthur de Jong2014-05-251-9/+5
|
* Fix attribute name in docstringArthur de Jong2014-05-191-1/+1
|
* Provide pskc.key docstringsArthur de Jong2014-04-191-47/+114
| | | | | | | | | This documents most of the information that is available per key and adds a few other minor cosmetic changes. This also re-organises the key properties to be in a slightly more logical order and renames the userid key property to key_userid to more clearly distinguish it from device_userid.
* Move Key class to separate moduleArthur de Jong2014-04-191-0/+232
This also allows re-organising the imports a bit.