Skip to content

Commit

Permalink
show bits not entire key
Browse files Browse the repository at this point in the history
  • Loading branch information
antedebaas committed Nov 1, 2024
1 parent 5a956ae commit 2aadaa6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Controller/DomainsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(EntityManagerInterface $em, UrlGeneratorInterface $r
}

#[Route('/domains', name: 'app_domains')]
public function index(): Response
public function index(Request $request): Response
{
if (!$this->getUser() || !$this->isGranted('IS_AUTHENTICATED')) {
return $this->redirectToRoute('app_login');
Expand Down Expand Up @@ -99,6 +99,7 @@ public function index(): Response
'domains' => $domains,
'bimivmcinfo' => $bimivmcinfo,
'pages' => $pages,
//'now' => , //Todo-Ante: this is the now for VMC date checking, it needs to be current time but check time notation
'page' => array(
'menu' => array(
'category' => 'domains',
Expand Down
41 changes: 41 additions & 0 deletions src/Twig/RSABits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
namespace App\Twig;

use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

class RSABits extends AbstractExtension
{
public function getFilters(): array
{
return [
new TwigFilter('rsabits', [$this, 'rsabitsFilter']),
];
}

public function rsabitsFilter($rsakey)
{
if (empty($rsakey)) {
return '';
}
$keyDetails= $this->getRsaKeyBitLengthFromDnsRecord($rsakey);
return $keyDetails['bits'];
}

function getRsaKeyBitLengthFromDnsRecord($dkimKeyStr) {
$dkimKeyStr = str_replace(["\n", "\r", " "], "", $dkimKeyStr);
$binaryKey = base64_decode($dkimKeyStr);
if ($binaryKey === false) {
throw new Exception("Invalid base64 encoding in DKIM key.");
}
$formattedKey = "-----BEGIN PUBLIC KEY-----\n" . chunk_split(base64_encode($binaryKey), 64, "\n") . "-----END PUBLIC KEY-----";
$publicKey = openssl_pkey_get_public($formattedKey);
if ($publicKey === false) {
throw new Exception("Failed to parse DKIM key.");
}
$keyDetails = openssl_pkey_get_details($publicKey);
openssl_free_key($publicKey);

return $keyDetails;
}
}
2 changes: 1 addition & 1 deletion templates/domains/check.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<div class="clearfix">
<b>Value</b>:<br>
{% if value.0 is defined and value.0.k is defined %}<span class="mx-4"><b>Type</b>: {{ value.0.k }}</span><br>{% endif %}
{% if value.0.p is defined %}<span class="mx-4"><b>Key</b>: {{ value.0.p[:50] ~ '...' }}</span><br>{% endif %}
{% if value.0.p is defined %}<span class="mx-4"><b>Bits</b>: {{ value.0.p|rsabits }}</span><br>{% endif %}
</div>
</li>
{% case 'BIMI' %}
Expand Down

0 comments on commit 2aadaa6

Please sign in to comment.