From 9250990cf5de3ca46f55ef6e54046525ae984abd Mon Sep 17 00:00:00 2001 From: Nguyen Van Nguyen Date: Wed, 25 Sep 2024 13:10:30 +0700 Subject: [PATCH] WIP Signed-off-by: Nguyen Van Nguyen --- examples/cleartext-signing.php | 10 +++++----- src/Common/Helper.php | 2 +- src/Packet/Key/MontgomerySessionKeyCryptor.php | 9 +++++---- src/Type/SessionKeyCryptorInterface.php | 1 + 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/examples/cleartext-signing.php b/examples/cleartext-signing.php index 3f58a2d..2b86e83 100755 --- a/examples/cleartext-signing.php +++ b/examples/cleartext-signing.php @@ -179,7 +179,7 @@ =aLGb -----END PGP PRIVATE KEY BLOCK----- EOT; -$curve4489PrivateKey = OpenPGP::decryptPrivateKey( +$curve448PrivateKey = OpenPGP::decryptPrivateKey( $keyData, $passphase, ); @@ -203,7 +203,7 @@ $rsaPrivateKey, $eccPrivateKey, $curve25519PrivateKey, - $curve4489PrivateKey, + $curve448PrivateKey, ], ); echo $armored = $signedMessage->armor() . PHP_EOL; @@ -213,7 +213,7 @@ $rsaPrivateKey->toPublic(), $eccPrivateKey->toPublic(), $curve25519PrivateKey->toPublic(), - $curve4489PrivateKey->toPublic(), + $curve448PrivateKey->toPublic(), ]); foreach ($verifications as $verification) { echo "Key ID: {$verification->getKeyID(true)}" . PHP_EOL; @@ -228,7 +228,7 @@ $rsaPrivateKey, $eccPrivateKey, $curve25519PrivateKey, - $curve4489PrivateKey, + $curve448PrivateKey, ], ); echo $armored = $signature->armor() . PHP_EOL; @@ -241,7 +241,7 @@ $rsaPrivateKey->toPublic(), $eccPrivateKey->toPublic(), $curve25519PrivateKey->toPublic(), - $curve4489PrivateKey->toPublic(), + $curve448PrivateKey->toPublic(), ], ); foreach ($verifications as $verification) { diff --git a/src/Common/Helper.php b/src/Common/Helper.php index 43137b5..aa05e59 100644 --- a/src/Common/Helper.php +++ b/src/Common/Helper.php @@ -168,7 +168,7 @@ public static function generatePassword(int $length = 32): string { return preg_replace_callback( '/\*/u', - static fn () => chr(random_int(33, 126)), + static fn () => chr(random_int(40, 126)), str_repeat('*', $length), ); } diff --git a/src/Packet/Key/MontgomerySessionKeyCryptor.php b/src/Packet/Key/MontgomerySessionKeyCryptor.php index 59e9ab8..a123f26 100644 --- a/src/Packet/Key/MontgomerySessionKeyCryptor.php +++ b/src/Packet/Key/MontgomerySessionKeyCryptor.php @@ -88,7 +88,8 @@ public static function encryptSessionKey( MontgomeryCurve $curve = MontgomeryCurve::Curve25519, ): self { - if ($sessionKey->getSymmetric() !== $curve->symmetricAlgorithm()) { + $pkeskV6 = $pkeskVersion === self::PKESK_VERSION_6; + if ($pkeskV6 && $sessionKey->getSymmetric() !== $curve->symmetricAlgorithm()) { throw new \InvalidArgumentException( 'Symmetric algorithm of the session key mismatch!' ); @@ -120,9 +121,9 @@ public static function encryptSessionKey( $ephemeralKey, $keyWrapper->wrap( $kek, - $pkeskVersion === self::PKESK_VERSION_3 ? - $sessionKey->toBytes() : - $sessionKey->getEncryptionKey(), + $pkeskV6 ? + $sessionKey->getEncryptionKey() : + $sessionKey->toBytes(), ), $pkeskVersion, $curve, diff --git a/src/Type/SessionKeyCryptorInterface.php b/src/Type/SessionKeyCryptorInterface.php index 1545360..8422f7b 100644 --- a/src/Type/SessionKeyCryptorInterface.php +++ b/src/Type/SessionKeyCryptorInterface.php @@ -18,6 +18,7 @@ interface SessionKeyCryptorInterface { const PKESK_VERSION_3 = 3; + const PKESK_VERSION_6 = 6; /** * Decrypt session key by using secret key packet