diff --git a/composer.json b/composer.json index a6e5c888..beee4327 100644 --- a/composer.json +++ b/composer.json @@ -55,6 +55,7 @@ "drupal/simple_ldap": "^1.0@alpha", "drupal/simplesamlphp_auth": "^3.2", "drupal/smtp": "^1.0@beta", + "drupal/sodium": "^2.4", "drupal/switch_page_theme": "^4.0", "drupal/telephone_validation": "^2.2", "drupal/token": "^1.5", @@ -62,7 +63,7 @@ "drupal/user_default_page": "^2.1", "drupal/webform": "^6.1", "drupal/webform_composite": "^1.0@RC", - "drupal/webform_encrypt": "^1.0@beta", + "drupal/webform_encrypt": "^2.0@alpha", "drupal/webform_migrate": "^1.1", "drupal/webform_node_element": "^1.2", "drupal/webform_remote_handlers": "^1.6.0", diff --git a/modules/os2forms_encrypt/config/install/encrypt.profile.webform.yml b/modules/os2forms_encrypt/config/install/encrypt.profile.webform.yml new file mode 100644 index 00000000..19891dfd --- /dev/null +++ b/modules/os2forms_encrypt/config/install/encrypt.profile.webform.yml @@ -0,0 +1,13 @@ +uuid: 98e9a380-a5d6-4d2a-9176-7c50a9ec7c47 +langcode: en +status: true +dependencies: + config: + - key.key.webform + module: + - sodium +id: webform +label: Webform +encryption_method: sodium +encryption_method_configuration: { } +encryption_key: webform diff --git a/modules/os2forms_encrypt/config/install/key.key.webform.yml b/modules/os2forms_encrypt/config/install/key.key.webform.yml new file mode 100644 index 00000000..aaabea7f --- /dev/null +++ b/modules/os2forms_encrypt/config/install/key.key.webform.yml @@ -0,0 +1,17 @@ +uuid: be3383e8-1b0e-4b50-989f-e132900d02a0 +langcode: en +status: true +dependencies: { } +id: webform +label: Webform +description: 'Encrypt webform submissions' +key_type: encryption +key_type_settings: + key_size: 256 +key_provider: config +key_provider_settings: + key_value: LWD5+0klWZn48ZVs13UVHaHJYawX62PAMd3sklkKj/w= + base64_encoded: true +key_input: text_field +key_input_settings: + base64_encoded: true diff --git a/modules/os2forms_encrypt/config/install/os2forms_encrypt.settings.yml b/modules/os2forms_encrypt/config/install/os2forms_encrypt.settings.yml new file mode 100644 index 00000000..cbd7f1bb --- /dev/null +++ b/modules/os2forms_encrypt/config/install/os2forms_encrypt.settings.yml @@ -0,0 +1 @@ +enabled: 1 diff --git a/modules/os2forms_encrypt/os2forms_encrypt.info.yml b/modules/os2forms_encrypt/os2forms_encrypt.info.yml new file mode 100644 index 00000000..5e1e7edf --- /dev/null +++ b/modules/os2forms_encrypt/os2forms_encrypt.info.yml @@ -0,0 +1,11 @@ +name: OS2Forms Encrypt +description: Encryption functionality for OS2Forms web-forms +package: OS2Forms +type: module +version: 1.0.0 +core_version_requirement: ^8 || ^9 || ^10 +dependencies: + - 'drupal:webform_encrypt' + - 'drupal:sodium' + +configure: os2forms_encrypt.admin_settings diff --git a/modules/os2forms_encrypt/os2forms_encrypt.links.menu.yml b/modules/os2forms_encrypt/os2forms_encrypt.links.menu.yml new file mode 100644 index 00000000..c7c63f8c --- /dev/null +++ b/modules/os2forms_encrypt/os2forms_encrypt.links.menu.yml @@ -0,0 +1,5 @@ +os2forms_encrypt.admin_settings: + title: 'OS2Forms Encrypt settings' + parent: system.admin_config_system + description: 'Settings for the OS2Forms Encrypt module' + route_name: os2forms_encrypt.admin_settings diff --git a/modules/os2forms_encrypt/os2forms_encrypt.module b/modules/os2forms_encrypt/os2forms_encrypt.module new file mode 100644 index 00000000..506f6df9 --- /dev/null +++ b/modules/os2forms_encrypt/os2forms_encrypt.module @@ -0,0 +1,18 @@ + &$definition) { + if ($element_id === 'webform_element_encrypt') { + $definition['#process'][] = [ + 'Drupal\os2forms_encrypt\Element\WebformElementEncrypt', + 'processWebformElementEncrypt', + ]; + } + } +} diff --git a/modules/os2forms_encrypt/os2forms_encrypt.routing.yml b/modules/os2forms_encrypt/os2forms_encrypt.routing.yml new file mode 100644 index 00000000..2b23f680 --- /dev/null +++ b/modules/os2forms_encrypt/os2forms_encrypt.routing.yml @@ -0,0 +1,7 @@ +os2forms_encrypt.admin_settings: + path: '/admin/config/os2forms_encrypt/settings' + defaults: + _form: '\Drupal\os2forms_encrypt\Form\SettingsForm' + _title: 'OS2Forms Encrypt settings' + requirements: + _permission: 'administer encrypt' diff --git a/modules/os2forms_encrypt/src/Element/WebformElementEncrypt.php b/modules/os2forms_encrypt/src/Element/WebformElementEncrypt.php new file mode 100644 index 00000000..3ae1c7be --- /dev/null +++ b/modules/os2forms_encrypt/src/Element/WebformElementEncrypt.php @@ -0,0 +1,23 @@ +get('enabled')) { + $element['element_encrypt']['encrypt']['#default_value'] = TRUE; + } + + return $element; + } +} diff --git a/modules/os2forms_encrypt/src/Form/SettingsForm.php b/modules/os2forms_encrypt/src/Form/SettingsForm.php new file mode 100644 index 00000000..504d523a --- /dev/null +++ b/modules/os2forms_encrypt/src/Form/SettingsForm.php @@ -0,0 +1,56 @@ +config('os2forms_encrypt.settings'); + + $form['enabled'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Enabled encryption'), + '#description' => $this->t('Enable encryption for all webform fields. Please note that encryption will be applied only to those fields that are modified after enabling this option.'), + '#default_value' => $config->get('enabled'), + ]; + + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state): void { + parent::submitForm($form, $form_state); + + $this->config(self::$configName) + ->set('enabled', $form_state->getValue('enabled')) + ->save(); + } + +}