From 90fc1e3d2472b9c64533245254787f760fb9b957 Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Fri, 20 Aug 2021 02:58:11 +0200 Subject: [PATCH] Add support for writing protected properties. --- kpwriter.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kpwriter.py b/kpwriter.py index db66b3a..6616a01 100644 --- a/kpwriter.py +++ b/kpwriter.py @@ -36,5 +36,11 @@ class KpWriter: if not otp_url: otp_url = "otpauth://totp/Sample:username?secret={}&algorithm=SHA1&digits=6&period=30&issuer=Sample".format(quote_plus(init_string)) # TODO: Support multiple / don't overwrite - self.current_entry.set_custom_property("TimeOtp-Secret-Base32", init_string) - self.current_entry.set_custom_property("otp", otp_url) + self.set_prop("TimeOtp-Secret-Base32", init_string, True) + self.set_prop("otp", otp_url) + + def set_prop(self, key, value, protected=False): + self.current_entry.set_custom_property(key, value) + if protected: + # https://github.com/libkeepass/pykeepass/issues/89 + self.current_entry._element.xpath('String[Key[text()="{}"]]/Value'.format(key))[0].attrib["Protected"] = "True"