OpenKMIP / PyKMIP

A Python implementation of the KMIP specification.
Apache License 2.0
273 stars 134 forks source link

Get operation not respecting flexible DES/TDES key lengths #449

Open pfunk1978 opened 6 years ago

pfunk1978 commented 6 years ago

Clear DES/TDES keys when exported can/may have their cryptographic lengths be multiples of 7 bytes instead of 8 due to parity bits. On get operations a 3des key can have a key material which is 192 bits, but the cryptographic length is reported as 168 bits, causing validation to raise a ValueError.

I patched mine locally in kmip/pie/objects.py line 674:

        if not self.key_wrapping_data:
            if ((len(self.value) * 8) != self.cryptographic_length) and \
               (self.cryptographic_algorithm ==
                enums.CryptographicAlgorithm.TRIPLE_DES and
               (len(self.value) * 7) != self.cryptographic_length):
                msg = "key length ({0}) not equal to key value length ({1})"
                msg = msg.format(
                    self.cryptographic_length,
                    len(self.value) * 8
                )
                raise ValueError(msg)
PeterHamilton commented 6 years ago

@pfunk1978 Thanks for filing this. After doing a bit of research, I agree that this is a legitimate issue for DES-style keys. I'll whip up a patch that incorporates your suggested fix.

Thanks again!