-
Notifications
You must be signed in to change notification settings - Fork 3
Digital Signature #167
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
Merged
Digital Signature #167
Changes from 14 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
ae97710
DIgital signature first version
stankut 987b6ac
OS-110 code refactoring, security
stankut 53fb77e
OS-110 upload file for signature
stankut ff96214
Upload digital document
stankut 3be3b70
OS-110 Signing service: Support for adding an extra page with signing…
stankut f60bfbc
Merge commit '841076066c102e5236808e7a9c020ca6092bc5cd' into f/OS-110
stankut d06c862
OS-144 - adding return URL
stankut 5d36f4a
OS-145 adding websubmissions automatic cleaning
stankut 8d3b2a7
OS-161 Disabling annotation page by default
stankut 43e5a04
OS-144 Fixing cancel digital signature
stankut 2b4a5a1
Merge commit '7ace38332357344358eca1935f43ae2a30c23fa4' into f/OS-110
stankut 0db0714
OS-167 adding Digital signature validation text
stankut 592ddd1
Merge commit 'eecb47a101ea651f749c7f1bce1ea7313ae3cdce' into f/OS-110
stankut 6d6af9f
Adding module description
stankut b7e53b9
OS-110 proper dependency injections
stankut 51706b5
OS-110 refactoring, removing comment lines
stankut 9abfcbd
OS-110 phpcs formatting
stankut 3130081
OS-110 phpcs formatting
stankut 1599ed0
Merge branch 'develop' into f/OS-110
stankut 9ae977f
OS-110 injecting dependency
stankut e01f0c1
OS-110 refactoring
stankut 23fa488
OS-110 refactoring, service injections
stankut 4681c85
OS-110 refactoring, service injections
stankut 2482846
OS-110 refactoring, phpcs
stankut 7346ebc
Merge branch 'develop' into f/OS-110
stankut File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # OS2Forms Digital Signature module | ||
|
|
||
| ## Module purpose | ||
|
|
||
| This module provides functionality for adding digital signature to the webform PDF submissions. | ||
|
|
||
| ## How does it work | ||
|
|
||
| ### Activating Digital Signature | ||
|
|
||
| 1. Add the OS2forms attachment element to the form. | ||
| 2. Indicate that the OS2Forms attachment requires a digital signature. | ||
| 3. Add the Digital Signature Handler to the webform. | ||
| 4. If the form requires an email handler, ensure the trigger is set to **...when submission is locked** in the handler’s *Additional settings*. | ||
|
|
||
| ### Flow Explained | ||
|
|
||
| 1. Upon form submission, a PDF is generated, saved in the private directory, and sent to the signature service via URL. | ||
| 2. The user is redirected to the signature service to provide their signature. | ||
| 3. After signing, the user is redirected back to the webform solution. | ||
| 4. The signed PDF is downloaded and stored in Drupal’s private directory. | ||
| 5. When a submission PDF is requested (e.g., via download link or email), the signed PDF is served instead of generating a new one on the fly. | ||
|
|
||
| ## Settings page | ||
|
|
||
| URL: `admin/os2forms_digital_signature/settings` | ||
|
|
||
| - **Signature server URL** | ||
|
|
||
| The URL of the service providing digital signature. This is the example of a known service https://signering.bellcom.dk/sign.php? | ||
|
|
||
|
|
||
| - **Hash Salt used for signature** | ||
|
|
||
| Must match hash salt on the signature server | ||
|
|
||
|
|
||
| - **List IP's which can download unsigned PDF submissions** | ||
|
|
||
| Only requests from this IP will be able to download PDF which are to be signed. | ||
9 changes: 9 additions & 0 deletions
9
modules/os2forms_digital_signature/os2forms_digital_signature.info.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| name: 'OS2Forms Digital Signature' | ||
| type: module | ||
| description: 'Provides digital signature functionality' | ||
| package: 'OS2Forms' | ||
| core_version_requirement: ^9 || ^10 | ||
| dependencies: | ||
| - 'webform:webform' | ||
|
|
||
| configure: os2forms_digital_signature.settings |
5 changes: 5 additions & 0 deletions
5
modules/os2forms_digital_signature/os2forms_digital_signature.links.menu.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| os2forms_digital_signature.admin.settings: | ||
| title: OS2Forms digital signature | ||
| description: Configure the OS2Forms digital signature module | ||
| parent: system.admin_config_system | ||
| route_name: os2forms_digital_signature.settings |
72 changes: 72 additions & 0 deletions
72
modules/os2forms_digital_signature/os2forms_digital_signature.module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| <?php | ||
|
|
||
| use Drupal\Core\Form\FormStateInterface; | ||
| use Drupal\Core\StreamWrapper\StreamWrapperManager; | ||
| use Drupal\os2forms_digital_signature\Form\SettingsForm; | ||
|
|
||
| /** | ||
| * Implements hook_cron(). | ||
| * | ||
| * Deletes stalled webform submissions that were left unsigned. | ||
| */ | ||
| function os2forms_digital_signature_cron() { | ||
| /** @var \Drupal\os2forms_digital_signature\Service\SigningService $service */ | ||
| $service = \Drupal::service('os2forms_digital_signature.signing_service'); | ||
| $service->deleteStalledSubmissions(); | ||
| } | ||
|
|
||
| /** | ||
| * Implements hook_webform_submission_form_alter(). | ||
| * | ||
| * Replaces submit button title, if digital signature present. | ||
| */ | ||
| function os2forms_digital_signature_webform_submission_form_alter(array &$form, FormStateInterface $form_state, $form_id) { | ||
| /** @var \Drupal\webform\WebformSubmissionInterface Interface $webformSubmission */ | ||
| $webformSubmission = $form_state->getFormObject()->getEntity(); | ||
| /** @var \Drupal\webform\WebformInterface $webform */ | ||
| $webform = $webformSubmission->getWebform(); | ||
|
|
||
| // Checking for os2forms_digital_signature handler presence. | ||
| foreach ($webform->getHandlers()->getConfiguration() as $handlerConf) { | ||
| if ($handlerConf['id'] == 'os2forms_digital_signature') { | ||
| $config = \Drupal::config('webform.settings'); | ||
| $settings = $config->get('settings'); | ||
|
|
||
| // Checking if the title has not been overridden. | ||
| if ($settings['default_submit_button_label'] == $form['actions']['submit']['#value']){ | ||
| $form['actions']['submit']['#value'] = t('Sign and submit'); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Implements hook_file_download(). | ||
| * | ||
| * Custom access control for private files. | ||
| */ | ||
| function os2forms_digital_signature_file_download($uri) { | ||
| // Only operate on files in the private directory. | ||
| if (StreamWrapperManager::getScheme($uri) === 'private' && str_starts_with(StreamWrapperManager::getTarget($uri), 'signing/')) { | ||
| // Get allowed IPs settings. | ||
| $config = \Drupal::config(SettingsForm::$configName); | ||
| $allowedIps = $config->get('os2forms_digital_signature_submission_allowed_ips'); | ||
|
|
||
| $allowedIpsArr = explode(',', $allowedIps); | ||
| $remoteIp = Drupal::request()->getClientIp(); | ||
|
|
||
| // IP list is empty, or request IP is allowed. | ||
| if (empty($allowedIpsArr) || in_array($remoteIp, $allowedIpsArr)) { | ||
| $basename = basename($uri); | ||
| return [ | ||
| 'Content-disposition' => 'attachment; filename="' . $basename . '"', | ||
| ]; | ||
| } | ||
|
|
||
| // Otherwise - Deny access. | ||
| return -1; | ||
| } | ||
|
|
||
| // Not submission file, allow normal access. | ||
| return NULL; | ||
| } |
16 changes: 16 additions & 0 deletions
16
modules/os2forms_digital_signature/os2forms_digital_signature.routing.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Webform os2forms_attachment_component routes. | ||
| os2forms_digital_signature.sign_callback: | ||
| path: '/os2forms_digital_signature/{uuid}/{hash}/sign_callback/{fid}' | ||
| defaults: | ||
| _controller: '\Drupal\os2forms_digital_signature\Controller\DigitalSignatureController::signCallback' | ||
| fid: '' | ||
| requirements: | ||
| _permission: 'access content' | ||
| os2forms_digital_signature.settings: | ||
| path: '/admin/os2forms_digital_signature/settings' | ||
| defaults: | ||
| _form: '\Drupal\os2forms_digital_signature\Form\SettingsForm' | ||
| _title: 'Digital signature settings' | ||
| requirements: | ||
| _permission: 'administer site configuration' | ||
|
|
4 changes: 4 additions & 0 deletions
4
modules/os2forms_digital_signature/os2forms_digital_signature.services.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| services: | ||
| os2forms_digital_signature.signing_service: | ||
| class: Drupal\os2forms_digital_signature\Service\SigningService | ||
| arguments: ['@config.factory'] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.