Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2014-05-29 14:49:05 +0200
committerArthur de Jong <arthur@arthurdejong.org>2014-05-29 14:50:07 +0200
commit76ef42bf1009e542b90814dc0b629e0ee5b0356c (patch)
tree0371ed999f3b492788c3b3f1bec09fc47c4047e0
parent7f26dc68c898ed7465a621d4f77544f473437491 (diff)
Add test for missing key encryption algorithm
This also introduces a toplevel PSKCError exception that all exceptions have as parent.
-rw-r--r--pskc/encryption.py2
-rw-r--r--pskc/exceptions.py19
-rw-r--r--tests/invalid-encryption.pskcxml18
-rw-r--r--tests/test_invalid.doctest7
4 files changed, 37 insertions, 9 deletions
diff --git a/pskc/encryption.py b/pskc/encryption.py
index 4e6a661..cd5720a 100644
--- a/pskc/encryption.py
+++ b/pskc/encryption.py
@@ -72,6 +72,8 @@ class EncryptedValue(object):
key = self.encryption.key
if key is None:
raise DecryptionError('No key available')
+ if self.algorithm is None:
+ raise DecryptionError('No algorithm specified')
if self.algorithm.endswith('#aes128-cbc') or \
self.algorithm.endswith('#aes192-cbc') or \
self.algorithm.endswith('#aes256-cbc'):
diff --git a/pskc/exceptions.py b/pskc/exceptions.py
index 9203dfe..801de20 100644
--- a/pskc/exceptions.py
+++ b/pskc/exceptions.py
@@ -21,21 +21,24 @@
"""Collection of exceptions."""
-class ParseError(Exception):
+class PSKCError(Exception):
+ """General top-level exception."""
+
+ def __str__(self):
+ return getattr(self, 'message', '')
+
+
+class ParseError(PSKCError):
"""Something went wrong with parsing the PSKC file.
Either the file is invalid XML or required elements or attributes are
missing."""
-
- def __str__(self):
- return getattr(self, 'message', '')
+ pass
-class DecryptionError(Exception):
+class DecryptionError(PSKCError):
"""There was a problem decrypting the value.
The encrypted value as available but something went wrong with decrypting
it."""
-
- def __str__(self):
- return getattr(self, 'message', '')
+ pass
diff --git a/tests/invalid-encryption.pskcxml b/tests/invalid-encryption.pskcxml
index 18ee5f1..d900dc9 100644
--- a/tests/invalid-encryption.pskcxml
+++ b/tests/invalid-encryption.pskcxml
@@ -2,7 +2,7 @@
<!--
Based on the Figure 6 example, this file includes an unknown encryption
- algorithm.
+ algorithm and a key without an algorithm specified.
-->
<KeyContainer Version="1.0"
@@ -28,4 +28,20 @@ AAECAwQFBgcICQoLDA0OD+cIHItlB3Wra1DUpxVvOx2lef1VmNPCMl8jwZqIUqGv
</Data>
</Key>
</KeyPackage>
+ <KeyPackage>
+ <Key Id="45678901" Algorithm="urn:ietf:params:xml:ns:keyprov:pskc:hotp">
+ <Data>
+ <Secret>
+ <EncryptedValue>
+ <xenc:EncryptionMethod/>
+ <xenc:CipherData>
+ <xenc:CipherValue>
+AAECAwQFBgcICQoLDA0OD+cIHItlB3Wra1DUpxVvOx2lef1VmNPCMl8jwZqIUqGv
+ </xenc:CipherValue>
+ </xenc:CipherData>
+ </EncryptedValue>
+ </Secret>
+ </Data>
+ </Key>
+ </KeyPackage>
</KeyContainer>
diff --git a/tests/test_invalid.doctest b/tests/test_invalid.doctest
index 2665bae..7c291e1 100644
--- a/tests/test_invalid.doctest
+++ b/tests/test_invalid.doctest
@@ -55,3 +55,10 @@ DecryptionError: No key available
Traceback (most recent call last):
...
DecryptionError: Unsupported algorithm: ...
+>>> key = pskc.keys[1]
+>>> key.id
+'45678901'
+>>> key.secret
+Traceback (most recent call last):
+ ...
+DecryptionError: No algorithm specified