2023-02-12 16:07:49 +00:00
|
|
|
# Copyright 2009-2023 Noviat.
|
2023-05-28 15:01:06 +00:00
|
|
|
# License LGPL-3 or later (http://www.gnu.org/licenses/lgpl).
|
2018-08-14 15:04:39 +00:00
|
|
|
|
|
|
|
import logging
|
|
|
|
|
2020-06-24 21:39:33 +00:00
|
|
|
from odoo import _, fields, models
|
2018-08-14 15:04:39 +00:00
|
|
|
from odoo.exceptions import UserError
|
|
|
|
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
try:
|
|
|
|
import fintech
|
|
|
|
from fintech.ebics import EbicsKeyRing
|
2022-05-10 19:40:54 +00:00
|
|
|
|
|
|
|
fintech.cryptolib = "cryptography"
|
2018-08-14 15:04:39 +00:00
|
|
|
except ImportError:
|
2022-05-10 19:40:54 +00:00
|
|
|
_logger.warning("Failed to import fintech")
|
2018-08-14 15:04:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EbicsChangePassphrase(models.TransientModel):
|
2022-05-10 19:40:54 +00:00
|
|
|
_name = "ebics.change.passphrase"
|
|
|
|
_description = "Change EBICS keys passphrase"
|
2018-08-14 15:04:39 +00:00
|
|
|
|
2020-07-14 21:18:32 +00:00
|
|
|
ebics_userid_id = fields.Many2one(
|
2022-05-10 19:40:54 +00:00
|
|
|
comodel_name="ebics.userid", string="EBICS UserID", readonly=True
|
|
|
|
)
|
2023-12-02 17:35:04 +00:00
|
|
|
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"
|
|
|
|
)
|
2022-05-10 19:40:54 +00:00
|
|
|
note = fields.Text(string="Notes", readonly=True)
|
2018-08-14 15:04:39 +00:00
|
|
|
|
2023-12-02 17:35:04 +00:00
|
|
|
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
|
|
|
|
|
2018-08-14 15:04:39 +00:00
|
|
|
def change_passphrase(self):
|
|
|
|
self.ensure_one()
|
2023-12-02 17:35:04 +00:00
|
|
|
self.note = ""
|
2023-05-28 08:48:17 +00:00
|
|
|
if (
|
|
|
|
self.ebics_userid_id.ebics_passphrase_store
|
2023-12-02 17:35:04 +00:00
|
|
|
and self.old_pass
|
2023-05-28 08:48:17 +00:00
|
|
|
and self.old_pass != self.ebics_userid_id.ebics_passphrase
|
|
|
|
):
|
2022-05-10 19:40:54 +00:00
|
|
|
raise UserError(_("Incorrect old passphrase."))
|
2018-08-14 15:04:39 +00:00
|
|
|
if self.new_pass != self.new_pass_check:
|
2022-05-10 19:40:54 +00:00
|
|
|
raise UserError(_("New passphrase verification error."))
|
2023-12-02 17:35:04 +00:00
|
|
|
if self.new_pass and self.new_pass == self.ebics_userid_id.ebics_passphrase:
|
2022-05-10 19:40:54 +00:00
|
|
|
raise UserError(_("New passphrase equal to old passphrase."))
|
2023-12-02 17:35:04 +00:00
|
|
|
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.")
|
2022-05-10 19:40:54 +00:00
|
|
|
)
|
2023-12-02 17:35:04 +00:00
|
|
|
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:
|
|
|
|
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:
|
2022-10-27 21:48:16 +00:00
|
|
|
raise UserError(str(err)) from err
|
2023-12-02 17:35:04 +00:00
|
|
|
|
|
|
|
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."
|
2018-08-14 15:04:39 +00:00
|
|
|
|
2022-05-10 19:40:54 +00:00
|
|
|
module = __name__.split("addons.")[1].split(".")[0]
|
2018-08-14 15:04:39 +00:00
|
|
|
result_view = self.env.ref(
|
2022-05-10 19:40:54 +00:00
|
|
|
"%s.ebics_change_passphrase_view_form_result" % module
|
|
|
|
)
|
2018-08-14 15:04:39 +00:00
|
|
|
return {
|
2022-05-10 19:40:54 +00:00
|
|
|
"name": _("EBICS Keys Change Passphrase"),
|
|
|
|
"res_id": self.id,
|
|
|
|
"view_type": "form",
|
|
|
|
"view_mode": "form",
|
|
|
|
"res_model": "ebics.change.passphrase",
|
|
|
|
"view_id": result_view.id,
|
|
|
|
"target": "new",
|
|
|
|
"type": "ir.actions.act_window",
|
2018-08-14 15:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def button_close(self):
|
|
|
|
self.ensure_one()
|
2022-05-10 19:40:54 +00:00
|
|
|
return {"type": "ir.actions.act_window_close"}
|