CryptoKeys - Converting CryptoException into status messages
Overview
From time to time, we clone/replicate our live sites into our development servers to do some reviews/coding enhancements etc. Since the live sites are having a different key from the development site(s), whenever we try to access the path /civicrm/admin/setting/smtp?reset=1
(and assuming that we had set the configuration to SMTP with a username & password in live), we end up with an exception error: "Failed to find key by ID or tag", leaving us unable to access the page so that we can modify or re-enter the SMTP password.
Reproduction steps
- Configure
CIVICRM_CRED_KEYS
- Go to
/civicrm/admin/setting/smtp?reset=1
- Set up the mailer as SMTP and store a password
- Clone the site's database and filebase (except the
civicrm.settings.php
) into another site OR change theCIVICRM_CRED_KEYS
- Try to access the page
/civicrm/admin/setting/smtp?reset=1
. You will get an exception error and the page won't load.
Expected behaviour
- Manage to get to the page
/civicrm/admin/setting/smtp?reset=1
but throw a status message that there's something wrong with the stored password.
Proposed solution
- On
/Civi/Crypto/CryptoRegistry.php
convert theCryptoException
s into Status messages - On
/Civi/Crypto/CryptoToken.php
check if the variable$key
is null or set and if not, return the$plaintext
This way, even if the system cannot decode/decrypt properly the key, we will still be able to return to the password page but also throw the notices to the visitor.
I'm assuming that this exact behaviour/effect fires up wherever we use the crypto functionality.
I am also aware that in order to fix this, one needs to also configure the same CIVICRM_CRED_KEY
as seen in the live site.
If this makes any sense, I can provide a patch/PR.
Environment information
- CiviCRM: 5.57
- PHP: 7.4.33
- CMS: Drupal 9.4.15