From 735b66606e25b20089b653977c23115e30170a1f Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Thu, 13 Dec 2012 11:48:46 -0600 Subject: bcfg2-crypt: fixed edge case where value is decrypted with the wrong key to produce gibberish --- src/sbin/bcfg2-crypt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/sbin/bcfg2-crypt') diff --git a/src/sbin/bcfg2-crypt b/src/sbin/bcfg2-crypt index 961a8dc58..9eab7bd29 100755 --- a/src/sbin/bcfg2-crypt +++ b/src/sbin/bcfg2-crypt @@ -355,10 +355,20 @@ class PropertiesEncryptor(Encryptor): if not crypted.text or not crypted.text.strip(): self.logger.warning("Skipping empty element %s" % crypted.tag) return crypted - crypted.text = Bcfg2.Encryption.ssl_decrypt( + decrypted = Bcfg2.Encryption.ssl_decrypt( crypted.text, passphrase, Bcfg2.Encryption.get_algorithm(self.setup)).strip() + try: + crypted.text = decrypted.encode('ascii', 'xmlcharrefreplace') + except UnicodeDecodeError: + # we managed to decrypt the value, but it contains content + # that can't even be encoded into xml entities. what + # probably happened here is that we coincidentally could + # decrypt a value encrypted with a different key, and + # wound up with gibberish. + self.logger.warning("Decrypted %s to gibberish, skipping" % + crypted.tag) return crypted -- cgit v1.2.3-1-g7c22