fix IV fixed part validation on decryption
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Thu, 6 Apr 2017 15:06:05 +0000 (17:06 +0200)
committerPhilipp Gesang <philipp.gesang@intra2net.com>
Mon, 7 Aug 2017 12:02:45 +0000 (14:02 +0200)
deltatar/crypto.py

index 0226a48..56b0e61 100755 (executable)
@@ -71,6 +71,10 @@ class InvalidHeader (Exception):
     """Header not valid."""
     pass
 
+class InvalidIVFixedPart (Exception):
+    """IV fixed part not in supplied list."""
+    pass
+
 class DecryptionError (Exception):
     """Error during decryption."""
     pass
@@ -518,8 +522,7 @@ class Decrypt (Crypto):
         if fixedparts is not None:
             self.pfx = fixedparts
             self.pfx.sort ()
-            super().__init__ (password, paramversion, nacl, counter=counter,
-                              nextpfx=lambda: self.pfx.pop())
+            super().__init__ (password, paramversion, nacl, counter=counter)
         super().__init__ (password, paramversion, nacl, counter=counter)
 
 
@@ -539,7 +542,9 @@ class Decrypt (Crypto):
         self.set_object_counter (self.cnt + 1)
         iv = hdr ["iv"]
         if self.pfx is not None and self.valid_pfx (iv) is False:
-            raise Exception ("XXX iv %r has invalid fixed part" % iv)
+            fixed, _ = struct.unpack (FMT_I2N_IV, iv)
+            raise InvalidIVFixedPart ("iv [%r] has invalid fixed part [%r]"
+                                      % (iv, fixed))
         self.tag = hdr ["tag"]
         defs = ENCRYPTION_PARAMETERS.get(paramversion)
         enc = defs ["enc"]