mirror of
https://github.com/tips-of-mine/gestion-certificats2.git
synced 2025-12-17 01:54:38 +01:00
**Adding Private Key Downloads to the Dashboard for Admins**
This update allows administrators to download the private keys for intermediate and simple certificates directly from the Dashboard page. It also fixes a bug in an intermediate certificate download link.
Here's a breakdown of the changes:
1. **In `app/src/Views/dashboard/index.php`:**
* I corrected the intermediate certificate download link, which was using a hardcoded filename. It now uses the actual certificate name.
* I added "Download Private Key (.key)" links for each listed intermediate certificate. These links are only visible if you are logged in with the 'admin' role.
* I also added "Download Private Key (.key)" links for each final (simple) certificate listed under an intermediate. These links are also only visible to administrators.
* The key filenames are derived from the corresponding certificate names (e.g., `cert.pem` becomes `key.pem`).
2. **In `app/src/Controllers/CertificateController.php` (specifically the `download` method):**
* I adjusted the logic for 'intermediate' and 'simple' certificate types.
* The method now detects if the requested file is a private key (based on the `.key.pem` suffix).
* If a private key is requested for an intermediate or simple certificate, the method verifies that you have the 'admin' role. If not, access is denied.
* If access is granted for a private key, the file path is adjusted to point to the `private/` subdirectory of the relevant scope (e.g., `INTERMEDIATE_CA_PATH_BASE/[perimeter]/private/[keyfile.key.pem]`).
* If a certificate file (`.cert.pem`) is requested, it is served from the `certs/` subdirectory as before.
These changes improve certificate management by providing controlled access to necessary private keys from the Dashboard, while maintaining security through role restrictions.