Skip to content
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

Extraction of private digital signature parameters to external configuration #462

Open
wants to merge 1 commit into
base: MOODLE_38_STABLE
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion element/digitalsignature/classes/element.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@

/**
* The customcert element digital signature's core interaction API.
*
* The digital signature private elements (private key and password) can be hidden behind
* the Moodle's instance configuration, so they are not exposed in the site interface.
*
* These parameters are two associative arrays, customcert_signature_private_keys and
* customcert_signature_passwords, storing the private keys and passwords respectively,
* of the digitalsignature instances (both with the same structure). The keys in these
* arrays are the elements' context ids. As a fallback, a special key '*' can be used
* for every instance. In case none of these is defined for either the private key or
* the password, falls back to the default behaviour (configuring it through the site
* administration interface).
*
* @package customcertelement_digitalsignature
* @copyright 2017 Mark Nelson <[email protected]>
Expand Down Expand Up @@ -232,7 +243,17 @@ public function render($pdf, $preview, $user) {
'Reason' => $imageinfo->signaturereason,
'ContactInfo' => $imageinfo->signaturecontactinfo
];
$pdf->setSignature('file://' . $location, '', $imageinfo->signaturepassword, '', 2, $info);
global $CFG;
$configured_private_key = property_exists($CFG, 'customcert_signature_private_keys') ? $CFG->customcert_signature_private_keys[$imageinfo->signaturecontextid] ?? $CFG->customcert_signature_private_keys['*'] : null;
$configured_password = property_exists($CFG, 'customcert_signature_passwords') ? $CFG->customcert_signature_passwords[$imageinfo->signaturecontextid] ?? $CFG->customcert_signature_passwords['*'] : null;
$pdf->setSignature(
'file://' . $location,
$configured_private_key ?? '',
$configured_password ?? $imageinfo->signaturepassword,
'',
2,
$info
);
$pdf->setSignatureAppearance($this->get_posx(), $this->get_posy(), $imageinfo->width, $imageinfo->height);
}
}
Expand Down
2 changes: 1 addition & 1 deletion element/digitalsignature/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@

defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');

$plugin->version = 2019111800; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2021092200; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2019111800; // Requires this Moodle version (3.8).
$plugin->component = 'customcertelement_digitalsignature';