Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Nguyen Van Nguyen <[email protected]>
  • Loading branch information
nguyennv committed Sep 25, 2024
1 parent 08c8374 commit ee20b0c
Show file tree
Hide file tree
Showing 3 changed files with 248 additions and 18 deletions.
221 changes: 221 additions & 0 deletions examples/cleartext-signing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
<?php declare(strict_types=1);

require_once dirname(__DIR__) . '/vendor/autoload.php';

use OpenPGP\OpenPGP;

$passphase = '8pM1b;)|5;lD7/SM51o>p1Vp%F}u=AO7';

$keyData = <<<EOT
-----BEGIN PGP PRIVATE KEY BLOCK-----
Version: PHP Privacy v2
Comment: https://github.com/web-of-trust/php-privacy
xcMGBGbzgU0BCAC+jS+ngfl33Ug9lmmcK5/skfFvQlUn4vtmSnUF5B4ohIX3CEkvCjdtinJlyUHL
MTgqHv3s64WCfMIwJUeRxXPP/g9vtOB2g0VFn695kZ80K8LqBawxEke+vFeXkwxY0hZC8I9dDpLK
8Y8f+R6qWEz2TcWI0Aj10sxLci8ikOYT7tuy2cvvVZ6ZyKKOi5fj+UFqtG8bfML4dOIWqhqXFmm7
jH0ZmeEBW80Z3CLB56c7gENRgzsa59i1qJ8jejalnM2KxFoQ1XKZrG2LfvzcNH1Nx+QH3mfhA+qM
XFI27D9MWqJZaIwWrkE2/k5Z8m/I1LC/I6thvp1XF34Y9QDOx9B/ABEBAAH+BwMIA6y71armwF7g
vRN42z+eWOniefQKGrnqOI2pqcq/Jrgv+dBucB/AG64MKqgs7mYindLIHJTBoRVn37T2s2f9w7LT
GD5bWKGSBASXO1U2EOkPlXOx4XMVzMtOhVLDuiWI+PIXJeZXemyCowILfZeS1CsbMojDhy3mGvOg
MH0nKnhQDXeva2eJy9/DAn7/ts4uBMNk5fhnShMYtErWxfJ+cW6u0S4hMsJGxn3AppxJ/qow4uA6
KP2FpfvbYM8APq8gX9p4M0PSjgEfZlcaYN5+HgKUs/8P5cGTDn6ZZ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k8+eRpxUsSjNzzMOu1rgPQPbNZJy
yuIJllNAjGUivN0W49zwV6o06hiVSMvzjeRbtMuUbN+XvsFaIdRLncBjhnEWoDZLwqsEPOVBTgGO
CXkmKRFcAAJsxoqpGyhuhW7/1JZFERqTk/N98sM3TN6wxtWrzWMTwS8yB9o7P95DmgMjsX17nevQ
I3l0tCo+7hVtm5s50W517T8kZYR+JKYbc8K3KZ6+KwDIENqmAxAvYLV5BX4V+WQGhd3L6h2ldKlC
JufkRd7zuLxBKQIPpDhrZEeGvClv
=B8qK
-----END PGP PRIVATE KEY BLOCK-----
EOT;
$rsaPrivateKey = OpenPGP::decryptPrivateKey(
$keyData,
$passphase,
);

$keyData = <<<EOT
-----BEGIN PGP PRIVATE KEY BLOCK-----
Version: PHP Privacy v2
Comment: https://github.com/web-of-trust/php-privacy
xcBIBGbzgU4TBSuBBAAjBCMEAGIhXtcV0Xo0x84qunT4ndhgrlKZcXgXYB9dhoPpci/XSsAU2Y6Y
BXOtXZvtj82Ht1GNHa5QgYO85y556aue6rK3AWUkCOZoKvjQ1kNJZwqW7iaXaj1N/cfFn1WQf4+4
1/VGhGk9DZYLgjP4+qoueOvh4amSA0BxdeXUn48lpkz3pDaD/gcDCKVeda8lbRug4CIojtl/xX/F
quYyDLpETGfH0R6ChYEGXbhO7D8JFmliEtnHiWQXm3YS6cxLRqU+SeZ5OUeUCM6bcUbuKtNfR05W
/CAWG+HcQlN9H4bLni66wpPJq2v0rB3BoLo0B8FLGlyrJjMTV5dbzSpOZ3V5ZW4gVmFuIE5ndXll
biA8bmd1eWVubnYxOTgxQGdtYWlsLmNvbT7CwDgEEBMKAGcFAmbzgU4WIQSD6DIwfTk50CHc8qK6
ngqnSMkpzwkQup4Kp0jJKc8CGQE8FAAAAAAAEwAgc2FsdEB3ZWJvZnRydXN0Lm9yZzA4+yJiUZc7
29+BKN8fvsW3GxUlLYNJs0BIz5GjylVLAACwkgII00MsI2571U+ehyJVGJa45YLjsm9IYHJ/FQ/z
Lz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TsezV1oHwCETQfrS0J4OQjFWU2HjW/8ZCi9T2K/aLIGFUweXR7Rs4D//ipI5dHL8C
CQGuZEOaUiVUrykzCiGTJ8g+/RsZnmOSkAafZyFQfTWYnURRJ+xs0HWqVOQsDnuo94+sS9tEgzpi
ZgPDYnRLXCjPFA==
=42yk
-----END PGP PRIVATE KEY BLOCK-----
EOT;
$eccPrivateKey = OpenPGP::decryptPrivateKey(
$keyData,
$passphase,
);

$keyData = <<<EOT
-----BEGIN PGP PRIVATE KEY BLOCK-----
Version: PHP Privacy v2
Comment: https://github.com/web-of-trust/php-privacy
xX0GZvOBThsAAAAgNgTM0VxUPpT+EPeltZCRrLVp4PQtdVLqmrEbln7nqkX+HQcLAwgpPq31t9Lk
AOBxvjCfxzD7nRJShX2aDSjNwsQ9xcUoUQ4Xtho0KFR3KD6xWW/Ud0y/PStRBLeqoPjyf8LVfwiq
1Vml/TdgJzUr+sN18MK7Bh8bCAAAAFwFAmbzgU8iIQbGAUcpguX+iT2VYGIph9cSTS2PhUnmMW5E
v5Mpgkkl1AkQxgFHKYLl/okCGwMDCwcJBCIBAgMFFQgMCg4FFgABAgMCHgsNJwcBCQEHAgkCBwMJ
AwAAAACFOxDChoaac0Z6OStT5W8DATB3qi9uy8j34X1P1BI1AL/hV1+a1rXZhoe75V+xUsnSiX1c
ve+sqiBVCTRf/ipqhKRpmpmXZGaAXeRkoLTCYzXDBs0qTmd1eWVuIFZhbiBOZ3V5ZW4gPG5ndXll
bm52MTk4MUBnbWFpbC5jb20+wr4GEBsIAAAAXwUCZvOBTyIhBsYBRymC5f6JPZVgYimH1xJNLY+F
SeYxbkS/kymCSSXUCRDGAUcpguX+iQIbAwMLBwkEIgECAwUVCAwKDgUWAAECAwIeCw0nBwEJAQcC
CQIHAwkDAhkBAAAAAI19EJiIsqw962c/t8OSfzgWhuV5CXcBAauNrjSEbKRWgL1raLgC7NJNo4HZ
N8bkiiAQYPH2vmHN1h/sA56/ue8HtckXGzyAvWZpRAzQJwGcMT8DzSxOZ3V5ZW4gVmFuIE5ndXll
biA8bmd1eWVubnZAaXdheXZpZXRuYW0uY29tPsK7BhAbCAAAAFwFAmbzgU8iIQbGAUcpguX+iT2V
YGIph9cSTS2PhUnmMW5Ev5Mpgkkl1AkQxgFHKYLl/okCGwMDCwcJBCIBAgMFFQgMCg4FFgABAgMC
HgsNJwcBCQEHAgkCBwMJAwAAAACqCRC+ziQUMGwHLS6z7NphB+Odc5qUKBrPPzUo+t1BsaqPsvo2
cfuqhqY8crbX7+Vjw9jgdyB2sEmQJNE2xdD9ZP7nI+75bcfVmv2qSTtu9SZfBMd9BmbzgU4ZAAAA
IBX6gFdXX115qhtVtF7BrgqiDPPTr0tmhp95fa1ULk4w/h0HCwMIicK0zjrbJKHgaVqj5JU5kjz/
v5GhQ/vr7rA3niwCxv8kJJYU/Uv1bJm/2t+Ttz9U/Krp4UdiHuIgjTNPhItboy5c5+gP9NLC0m7p
2PHClQYYGwgAAAA2BQJm84FPIiEGxgFHKYLl/ok9lWBiKYfXEk0tj4VJ5jFuRL+TKYJJJdQJEMYB
RymC5f6JAhsMAAAAAIzeEKdEOhcv059atWcnzJAxsMyjMZKwwBeQPNwB8rnwKt1sd/zIlF5QWoXp
txnK0umqKGDv5XOmkieuVSSB1p+Ka4tg+0mUiHK4Q6eH8FGCrywO1R44TjFeZcQLtExinfj6VUu4
OWcHlS3cfS2V0+EdtxA=
=xBiu
-----END PGP PRIVATE KEY BLOCK-----
EOT;
$curve25519PrivateKey = OpenPGP::decryptPrivateKey(
$keyData,
$passphase,
);

$keyData = <<<EOT
-----BEGIN PGP PRIVATE KEY BLOCK-----
Version: PHP Privacy v2
Comment: https://github.com/web-of-trust/php-privacy
xa8GZvOBTxwAAAA5bkWce7vfRJjxiLiP1G9EJH0Hp+0gKywFeY2/n+9z3FASQZ0aPiyudnXS3svo
XKXtCpibchwzb0CA/h0HCwMIb7Ms2LezV3fgJzYF+rs24aoAuyVsm+DI0+F+fI3Mdr6CfwP5JGv4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PoXBAyLc7yIntF
8M/U4I2Z5qhy61pbWR94zuHjp1TcAxqrYfyv5t2ZV04tj39+3AHtq3A1vVfpEkz0fjBFNqvtbLeE
N0xcaPMUe0/RnkYADNhadd/AvRje+yUPT8zMgiFs2T798ub9/nY5jpXojCwPXK0qUB3bn0i54Z0p
vsCquFeMPdtM7CUAx60GZvOBTxoAAAA4Kvgk6QWiaGCcNIxprmUqQGyjwjYp2sstXDJrckYp8W9F
FKSNg+Gn/SHSdEIXvxyTTIVmQu++dKH+HQcLAwiJ2X7nt0zt9eBKxqW06VG8Blc9tZoMzZHsHSOs
Y6GyaatQzElsOlDjiVl15dDkfNjqa5jcJgRvtEsj7b9SQDhWOvuoHrVIMp+vFGtLlpu9ZalU9lZE
zFdNpdFiT46vE3n6SV9YkcLAFwYYHAoAAAA2BQJm84FQIiEGLaT0nNAiDZHwpbAxVSSG9OZyARJz
Dug06EhjYummZioJEC2k9JzQIg2RAhsMAAAAAFkzIFSCJ/3L5byAbTmIPTNDm0QZBjoQoCU0g1KN
EAvbtCG83QTWGUQlczJsOpZWMo2IJRRDu+0K1BYyM2qhMXqPds2VDk9ppzyRZQLxpK3Wgu/8g41f
/vcRMaWAxgm8uPbQUL5STXqCLwCS1oS0Ioa8y4Mf+eKlPwNVN7VHz9A5VV6QZE1wB5E4G2f/n5Zv
df0zvgUA1R2LL5cFCeqL+v/SEmEuQm3skaPHAPtOusu/60UhyA==
=aLGb
-----END PGP PRIVATE KEY BLOCK-----
EOT;
$curve4489PrivateKey = OpenPGP::decryptPrivateKey(
$keyData,
$passphase,
);

$text = <<<EOT
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc felis neque, interdum id iaculis ut, faucibus a ex.
Nam quam tortor, pharetra at dignissim ut, semper nec arcu. Vivamus mollis tortor vitae urna fringilla lacinia id
vel nunc. Ut laoreet pellentesque mattis. Curabitur viverra enim venenatis, mattis velit sed, fringilla lacus. Donec
nulla dui, vestibulum aliquam ultrices hendrerit, euismod iaculis magna. Praesent vitae ipsum id risus feugiat
auctor ac eget tellus.
What we need from the grocery store:
- tofu
- vegetables
- noodles
EOT;
$signedMessage = OpenPGP::signCleartext(
$text,
[
$rsaPrivateKey,
$eccPrivateKey,
$curve25519PrivateKey,
$curve4489PrivateKey,
],
);
echo $armored = $signedMessage->armor() . PHP_EOL;

echo 'Verify signed message:' . PHP_EOL . PHP_EOL;
$verifications = OpenPGP::verify($armored, [
$rsaPrivateKey->toPublic(),
$eccPrivateKey->toPublic(),
$curve25519PrivateKey->toPublic(),
$curve4489PrivateKey->toPublic(),
]);
foreach ($verifications as $verification) {
echo "Key ID: {$verification->getKeyID(true)}" . PHP_EOL;
echo "Signature is verified: {$verification->isVerified()}" . PHP_EOL;
echo "Verification error: {$verification->getVerificationError()}" . PHP_EOL . PHP_EOL;
}
2 changes: 1 addition & 1 deletion src/Common/Armor.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public static function encode(
Helper::EOL,
array_map(static fn ($hashAlgo) => "Hash: $hashAlgo", $hashAlgos)
) . Helper::EOL . Helper::EOL : Helper::EOL,
preg_replace(self::DASH_PATTERN, '- -', $text) . Helper::EOL, // Dash-escape text
preg_replace(self::DASH_PATTERN, '- - ', $text) . Helper::EOL, // Dash-escape text
self::SIGNATURE_BEGIN,
self::addHeader($customComment) . Helper::EOL,
chunk_split(Strings::base64_encode($data), self::TRUNK_SIZE, Helper::EOL),
Expand Down
43 changes: 26 additions & 17 deletions src/Message/Signature.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use OpenPGP\Type\{
CleartextMessageInterface,
KeyInterface,
KeyPacketInterface,
LiteralDataInterface,
PacketListInterface,
SignatureInterface,
Expand Down Expand Up @@ -113,29 +114,37 @@ public function verify(
$verifications = [];
foreach ($this->packetList as $packet) {
foreach ($verificationKeys as $key) {
$isVerified = false;
$verificationError = '';
$keyPacket = $key->toPublic()->getSigningKeyPacket(
$packet->getIssuerKeyID()
);
$keyPacket = null;
try {
$isVerified = $packet->verify(
$keyPacket,
$literalData->getSignBytes(),
$time,
$keyPacket = $key->toPublic()->getSigningKeyPacket(
$packet->getIssuerKeyID()
);
}
catch (\Throwable $e) {
$verificationError = $e->getMessage();
Config::getLogger()->error($verificationError);
Config::getLogger()->error($e->getMessage());
}
if ($keyPacket instanceof KeyPacketInterface) {
$isVerified = false;
$verificationError = '';
try {
$isVerified = $packet->verify(
$keyPacket,
$literalData->getSignBytes(),
$time,
);
}
catch (\Throwable $e) {
$verificationError = $e->getMessage();
Config::getLogger()->error($verificationError);
}

$verifications[] = new Verification(
$keyPacket->getKeyID(),
$packet,
$isVerified,
$verificationError,
);
$verifications[] = new Verification(
$keyPacket->getKeyID(),
$packet,
$isVerified,
$verificationError,
);
}
}
}
return $verifications;
Expand Down

0 comments on commit ee20b0c

Please sign in to comment.