Skip to content

Commit 5e7ede3

Browse files
authored
Handle OpenPGP-compliant CSF message verfication (#40)
GnuPG has traditionally emitted a spurious newline when outputting the text verified from a cleartext signing framework message, if the signed message doesn't contain a trailing newline. This is clearly wrong according to the OpenPGP specification, which says: > The line ending (i.e., the <CR><LF>) before the '-----BEGIN PGP > SIGNATURE-----' line that terminates the signed text is not > considered part of the signed text. The test in Crypt_GPG presumes that the trailing newline is returned, as that has been traditional GnuPG (mis)behavior. This change adjusts the test suite so that it passes regardless of whether GnuPG conforms to the specification or misbehaves in the traditional way. See https://dev.gnupg.org/T7106 for discussion with upstream. See also https://gitlab.com/freepg/gnupg/-/merge_requests/15, where the FreePG project is bringing a patched version of GnuPG into compliance with the specification. Finally, please also see the discussion over on https://bugs.debian.org/1099043 -- debian's GnuPG is being brought into compliance with the OpenPGP standard for CSF messages, so we need something like this to ensure that the Crypt_GPG test suite succeeds.
1 parent e0799f5 commit 5e7ede3

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

tests/DecryptAndVerifyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ public function testDecryptVerifySignedOnlyBadSignature()
939939
// }}}
940940

941941
$results = $this->gpg->decryptAndVerify($clearsignedData);
942-
$this->assertDecryptAndVerifyResultsEquals($expectedResults, $results);
942+
$this->assertDecryptAndVerifyResultsEquals($expectedResults, $results, true);
943943
}
944944

945945
/**

tests/TestCase.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ protected function getTempFilename($filename)
634634
return __DIR__ . '/' . self::TEMPDIR . '/' . $filename;
635635
}
636636

637-
protected function assertDecryptAndVerifyResultsEquals(array $expected, array $actual)
637+
protected function assertDecryptAndVerifyResultsEquals(array $expected, array $actual, $csf = false)
638638
{
639639
$this->assertEquals(
640640
count($expected),
@@ -666,6 +666,11 @@ protected function assertDecryptAndVerifyResultsEquals(array $expected, array $a
666666
'Actual result does not include signatures.'
667667
);
668668

669+
if ($csf && (substr($actual['data'], -1) != "\n")) {
670+
// see discussion around GnuPG's handling of trailing
671+
// newlines in CSF messages at https://dev.gnupg.org/T7106
672+
$actual['data'] = $actual['data']."\n";
673+
}
669674
$this->assertEquals(
670675
$expected['data'],
671676
$actual['data'],

0 commit comments

Comments
 (0)