-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dev/core#2258 - Add services to support encryption #19236
Conversation
(Standard links)
|
@totten So this looks consistent with our discussions and looks ok to me, maybe if others @artfulrobot @pfigel have any ideas on this feedback would be appreciated |
…aintext Example: You have a basic site that has not enabled encrypted fields, but the integration with settings/APIs causes one to use CryptoToken::decrypt()
… being used This moves the factory function from `Container.php` (which is loaded on all page-views on all configurations) to `CryptoRegistry.php` (which is only loaded if the site actually used encrypted fields).
…CRM_SITE_KEY. This was included under the expectation it might make a nicer upgrade. But I don't think it buys a whole lot: 1. You run the upgrader. The SMTP password is converted from rj256-ecb-sitekey to aes-cbc-sitekey. All other credentials are left unencrypted. Afterward, you set CIVICRM_CRED_KEY and run the rekey. 2. You run upgrader. The SMTP password is decrypted. All other credentials are left unencrypted. Afterward, you set CIVICRM_CRED_KEY and run the rekey. Additionally, I think there's a question of risk-management when we get to encrypting more things in the Setting and API layers. If we go with path 2, then we can ramp-up adoption progressively, e.g. * Release 1: Add support as non-default option * Release 2: Enable by default on new builds * Release 3: Display alert to existing sites that don't have encryption keys
This is pre-merge change to the notation in the token. Two things: * Use only one control character instead of multiple. * Use URL-style key-value notation. It should be easier to skim and to tweak.
2eb3939
to
5b394c8
Compare
jenkins, test this please |
This allows the plaintext entries to do have different prioritizations among different keys.
c6dbae1
to
a5eae9c
Compare
@totten A quick comment on this re. hooks. Is there a good reason to add new "old-style" hooks instead of adding "new-style" events via symfony. I'm finding more and more that starting with symfony event listeners gives far more flexibility and, once you've got a basic example, are very easy to use. |
@mattwire for consistency sake I would presume, I'm sure that you are aware but even the hold style hooks are dispatched as events as per https://docs.civicrm.org/dev/en/latest/hooks/usage/symfony/#example-cividispatcher |
@mattwire @seamuslee001 I'm glad the new-style has gotten easier to use while increasing flexibility. I guess my way of rationalizing the two naming conventions (
For the hook added in this PR( There is a good argument to be made for phasing-out dual-dispatch ( |
I'm going to merge this on the basis that it adds new functionality and doesn't break anything existing and that it has tests as well |
Overview
Storing specific fields as encrypted values provides a way to protect confidentiality of particularly sensitive data even if an attacker gains the ability to read the database (e.g. via SQL injection or leaked SQL backup).
In the past, CiviCRM has protected the SMTP password in this way (specifically, using the helper
CRM_Utils_Crypt
). However,CRM_Utils_Crypt
has faced multiple issues which prevented broader/systematic usage.This patchset provides a more robust take on
CRM_Utils_Crypt
which aims to allow broader/systematic usage. It is work toward https://lab.civicrm.org/dev/core/-/issues/2258Before
There is a helper,
CRM_Utils_Crypt
, which provides encrypt and decrypt methods. However, it is problematic in a few ways:encrypt()
is written to disk, it becomes ambiguous. A program which reads the "SMTP password" cannot tell if "YWJjZGVmZ2hp" is a plain-text password or a base64-encoded ciphertext.CIVICRM_SITE_KEY
has competing uses. You can get boxed-in to situations where you need to change for one reason (e.g. pro-actively rotating crypto keys) but must keep it for another reason (e.g. providing stable CiviCase IDs).The saving grace is that this has only been used on one internal field. But the flip-side is that we have not been able to expand crypto storage to other fields.
After
The
CRM_Utils_Crypt
helper still exists exactly as before. This ensures that existing third-party extensions that use it will continue working as-is. But now there is another helper:New characteristics:
CIVICRM_CRED_KEYS
, that can be managed separately.CIVICRM_CRED_KEYS
may list multiple, space-delimited keys.$encrypted
) is unambiguous. One can programmatically distinguish values which were:::abcdefghijklmnopqrstuvwxyz
::123456789
Technical details
This patch-set actually introduces a few programmatic interfaces:
CryptoRegistry
(crypto.registry
): Tracks the list of available keys and ciphershook_civicrm_crypto
: Runs when initializing the registry. Allows one to add more keys and ciphers.CryptoToken
(crypto.token
): Defines a data-format for the encrypted field values. Includes encrypt/decrypt methods.This arrangement makes the system fairly extensible. For example, suppose you were developing a patch to the session-store and wanted to encrypt it with a distinct key. Part of the patch-set would say: