Implémenter la fonctionnalité de téléchargement des certificats depuis le dashboard

Ce commit introduit la possibilité pour vous de télécharger les fichiers de certificats (racine, intermédiaire, final) et la clé privée du certificat racine (administrateurs uniquement) directement depuis la page du tableau de bord.

Changements inclus :
- Ajout d'une méthode `download()` dans `CertificateController` pour gérer la logique de téléchargement sécurisé des fichiers.
- Ajout d'une nouvelle route `GET /certificates/download`.
- Correction et standardisation des liens de téléchargement dans la vue du dashboard pour assurer la transmission correcte des paramètres (type de certificat, nom de fichier, périmètre).
- La méthode de téléchargement inclut la journalisation des tentatives et des erreurs, ainsi que la gestion des permissions pour la clé privée racine.
This commit is contained in:
google-labs-jules[bot]
2025-06-15 12:23:58 +00:00
parent c0351292c8
commit 16458278b9
4 changed files with 256 additions and 1 deletions

View File

@ -27,6 +27,68 @@ require_once APP_ROOT_DIR . '/src/Views/shared/header.php';
<?php endif; ?>
</ul>
</section>
<section class="certificates-overview">
<h2><?= htmlspecialchars($translations['certificates_overview_title'] ?? 'Certificates Overview') ?></h2>
<!-- Root Certificate -->
<h3><?= htmlspecialchars($translations['root_certificate_title'] ?? 'Root Certificate') ?></h3>
<?php if (isset($structuredCertificates['root']) && $structuredCertificates['root']): ?>
<div>
<p><strong><?= htmlspecialchars($translations['name'] ?? 'Name:') ?></strong> <?= htmlspecialchars($structuredCertificates['root']['name']) ?></p>
<p>
<a href="/certificates/download?type=root&file=ca.cert.pem" class="button">
<?= htmlspecialchars($translations['download_certificate_pem'] ?? 'Download Certificate (.pem)') ?>
</a>
</p>
<p>
<a href="/certificates/download?type=root&file=ca.key.pem" class="button">
<?= htmlspecialchars($translations['download_key_pem'] ?? 'Download Private Key (.key)') ?>
</a>
</p>
</div>
<?php else: ?>
<p><?= htmlspecialchars($translations['root_certificate_not_configured'] ?? 'Root certificate is not configured.') ?></p>
<?php endif; ?>
<!-- Intermediate Certificates -->
<h3><?= htmlspecialchars($translations['intermediate_certificates_title'] ?? 'Intermediate Certificates') ?></h3>
<?php if (isset($structuredCertificates['intermediates']) && !empty($structuredCertificates['intermediates'])): ?>
<?php foreach ($structuredCertificates['intermediates'] as $intermediate): ?>
<div class="intermediate-certificate">
<h4><?= htmlspecialchars($intermediate['name']) ?> (<?= htmlspecialchars($translations['perimeter'] ?? 'Perimeter:') ?> <?= htmlspecialchars($intermediate['perimeter_name']) ?>)</h4>
<p>
<a href="/certificates/download?type=intermediate&perimeter=<?= urlencode($intermediate['perimeter_name']) ?>&file=intermediate.cert.pem" class="button">
<?= htmlspecialchars($translations['download_certificate_pem'] ?? 'Download Certificate (.pem)') ?>
</a>
</p>
<h5><?= htmlspecialchars($translations['associated_final_certificates_title'] ?? 'Associated Final Certificates') ?></h5>
<?php if (isset($intermediate['final_certificates']) && !empty($intermediate['final_certificates'])): ?>
<ul>
<?php foreach ($intermediate['final_certificates'] as $finalCert): ?>
<li>
<?= htmlspecialchars($finalCert['name']) ?>
(<?= htmlspecialchars($translations['type'] ?? 'Type:') ?> <?= htmlspecialchars($finalCert['type']) ?>,
<?= htmlspecialchars($translations['expires'] ?? 'Expires:') ?> <?= htmlspecialchars($finalCert['expiration_date']) ?>,
<?= htmlspecialchars($translations['revoked'] ?? 'Revoked:') ?> <?= $finalCert['is_revoked'] ? htmlspecialchars($translations['yes'] ?? 'Yes') : htmlspecialchars($translations['no'] ?? 'No') ?>)
<p>
<a href="/certificates/download?type=simple&perimeter=<?= urlencode($intermediate['perimeter_name']) ?>&file=<?= urlencode($finalCert['name']) ?>" class="button download-button-small">
<?= htmlspecialchars($translations['download_certificate_pem'] ?? 'Download Certificate (.pem)') ?>
</a>
</p>
</li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p><?= htmlspecialchars($translations['no_associated_final_certificates'] ?? 'No final certificates associated with this intermediate.') ?></p>
<?php endif; ?>
</div>
<?php endforeach; ?>
<?php else: ?>
<p><?= htmlspecialchars($translations['no_intermediate_certificates_found'] ?? 'No intermediate certificates found.') ?></p>
<?php endif; ?>
</section>
</div>
<?php