[IMP]add support for signature passphrase

This commit is contained in:
Luc De Meyer
2023-12-02 18:35:04 +01:00
parent 2d71ff395c
commit 28da051f9d
7 changed files with 178 additions and 63 deletions

View File

@@ -24,37 +24,75 @@ class EbicsChangePassphrase(models.TransientModel):
ebics_userid_id = fields.Many2one(
comodel_name="ebics.userid", string="EBICS UserID", readonly=True
)
old_pass = fields.Char(string="Old Passphrase", required=True)
new_pass = fields.Char(string="New Passphrase", required=True)
new_pass_check = fields.Char(string="New Passphrase (verification)", required=True)
old_pass = fields.Char(string="Old Passphrase")
new_pass = fields.Char(string="New Passphrase")
new_pass_check = fields.Char(string="New Passphrase (verification)")
old_sig_pass = fields.Char(string="Old Signature Passphrase")
new_sig_pass = fields.Char(string="New Signature Passphrase")
new_sig_pass_check = fields.Char(string="New Signature Passphrase (verification)")
ebics_sig_passphrase_invisible = fields.Boolean(
compute="_compute_ebics_sig_passphrase_invisible"
)
note = fields.Text(string="Notes", readonly=True)
def _compute_ebics_sig_passphrase_invisible(self):
for rec in self:
if fintech.__version_info__ < (7, 3, 1):
rec.ebics_sig_passphrase_invisible = True
else:
rec.ebics_sig_passphrase_invisible = False
def change_passphrase(self):
self.ensure_one()
self.note = ""
if (
self.ebics_userid_id.ebics_passphrase_store
and self.old_pass
and self.old_pass != self.ebics_userid_id.ebics_passphrase
):
raise UserError(_("Incorrect old passphrase."))
if self.new_pass != self.new_pass_check:
raise UserError(_("New passphrase verification error."))
if self.new_pass == self.ebics_userid_id.ebics_passphrase:
if self.new_pass and self.new_pass == self.ebics_userid_id.ebics_passphrase:
raise UserError(_("New passphrase equal to old passphrase."))
if (
self.new_sig_pass
and self.old_sig_pass
and self.new_sig_pass == self.old_sig_pass
):
raise UserError(
_("New signature passphrase equal to old signature passphrase.")
)
if self.new_sig_pass != self.new_sig_pass_check:
raise UserError(_("New signature passphrase verification error."))
passphrase = (
self.ebics_userid_id.ebics_passphrase_store
and self.ebics_userid_id.ebics_passphrase
or self.old_pass
)
try:
passphrase = (
self.ebics_userid_id.ebics_passphrase_store
and self.ebics_userid_id.ebics_passphrase
or self.old_pass
)
keyring = EbicsKeyRing(
keys=self.ebics_userid_id.ebics_keys_fn,
passphrase=passphrase,
)
keyring.change_passphrase(self.new_pass)
except ValueError as err:
keyring_params = {
"keys": self.ebics_userid_id.ebics_keys_fn,
"passphrase": passphrase,
}
if self.new_sig_pass:
keyring_params["sig_passphrase"] = self.old_sig_pass
keyring = EbicsKeyRing(**keyring_params)
change_params = {}
if self.new_pass:
change_params["passphrase"] = self.new_pass
if self.new_sig_pass:
change_params["sig_passphrase"] = self.new_sig_pass
if change_params:
keyring.change_passphrase(**change_params)
except (ValueError, RuntimeError) as err:
raise UserError(str(err)) from err
self.ebics_userid_id.ebics_passphrase = self.new_pass
self.note = "The EBICS Passphrase has been changed."
if self.new_pass:
self.ebics_userid_id.ebics_passphrase = self.new_pass
self.note += "The EBICS Passphrase has been changed."
if self.new_sig_pass:
self.note += "The EBICS Signature Passphrase has been changed."
module = __name__.split("addons.")[1].split(".")[0]
result_view = self.env.ref(