-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a956ae
commit 2aadaa6
Showing
3 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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,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; | ||
} | ||
} |
This file contains 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