Skip to content

Commit 526bfdb

Browse files
[stable32] fix: improve TSA DNS/network error guidance (#7431)
* test: require DNS/network/firewall hint for unresolved TSA host Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> * fix: clarify TSA DNS/network/firewall validation failure Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> * test: cover TSA handler DNS/network/firewall guidance Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> * fix: align TSA handler errors with connectivity guidance Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --------- Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Co-authored-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 3632f02 commit 526bfdb

4 files changed

Lines changed: 27 additions & 4 deletions

File tree

lib/Handler/SignEngine/JSignPdfHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,10 +671,10 @@ private function checkTsaError(string $errorMessage): void {
671671

672672
if ($isTsaError) {
673673
if (str_contains($errorMessage, 'Invalid TSA') && preg_match("/Invalid TSA '([^']+)'/", $errorMessage, $matches)) {
674-
$friendlyMessage = 'Timestamp Authority (TSA) service is unavailable or misconfigured: ' . $matches[1];
674+
$friendlyMessage = 'Timestamp Authority (TSA) service is unavailable. Check DNS/network/firewall connectivity from this server: ' . $matches[1];
675675
} else {
676676
$friendlyMessage = 'Timestamp Authority (TSA) service error.' . "\n"
677-
. 'Please check the TSA configuration.';
677+
. 'Check TSA endpoint and DNS/network/firewall connectivity from this server.';
678678
}
679679
throw new LibresignException($friendlyMessage);
680680
}

lib/Service/TsaValidationService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private function validateTsaHostResolution(string $tsaUrl): void {
6262
}
6363

6464
if (!@gethostbyname($host) || gethostbyname($host) === $host) {
65-
throw new LibresignException('Timestamp Authority (TSA) service is unavailable or misconfigured: ' . $tsaUrl);
65+
throw new LibresignException('Timestamp Authority (TSA) service is unavailable. Check DNS/network/firewall connectivity from this server: ' . $tsaUrl);
6666
}
6767
}
6868
}

tests/php/Unit/Handler/SignEngine/JSignPdfHandlerTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use OCA\Libresign\DataObjects\VisibleElementAssoc;
1313
use OCA\Libresign\Db\FileElement;
1414
use OCA\Libresign\Enum\DocMdpLevel;
15+
use OCA\Libresign\Exception\LibresignException;
1516
use OCA\Libresign\Handler\CertificateEngine\CertificateEngineFactory;
1617
use OCA\Libresign\Handler\SignEngine\JSignPdfHandler;
1718
use OCA\Libresign\Helper\JavaHelper;
@@ -732,4 +733,26 @@ public static function providerGetSignatureText(): array {
732733
['GRAPHIC_ONLY', 'a$a', '""'],
733734
];
734735
}
736+
737+
public function testCheckTsaErrorInvalidTsaMentionsDnsNetworkFirewall(): void {
738+
$jSignPdfHandler = $this->getInstance();
739+
740+
$this->expectException(LibresignException::class);
741+
$this->expectExceptionMessage('Timestamp Authority (TSA) service is unavailable. Check DNS/network/firewall connectivity from this server: https://invalid-tsa.example.com/tsr');
742+
743+
self::invokePrivate($jSignPdfHandler, 'checkTsaError', [
744+
"Invalid TSA 'https://invalid-tsa.example.com/tsr'",
745+
]);
746+
}
747+
748+
public function testCheckTsaErrorUnknownHostMentionsDnsNetworkFirewall(): void {
749+
$jSignPdfHandler = $this->getInstance();
750+
751+
$this->expectException(LibresignException::class);
752+
$this->expectExceptionMessage("Timestamp Authority (TSA) service error.\nCheck TSA endpoint and DNS/network/firewall connectivity from this server.");
753+
754+
self::invokePrivate($jSignPdfHandler, 'checkTsaError', [
755+
'TSAClientBouncyCastle: java.net.UnknownHostException: invalid-tsa.example.com',
756+
]);
757+
}
735758
}

tests/php/Unit/Service/TsaValidationServiceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static function provideInvalidTsaUrls(): array {
7979
],
8080
'unresolvable host' => [
8181
'https://invalid-tsa-server-abc123xyz.example.com/tsr',
82-
'/Timestamp Authority \(TSA\) service is unavailable or misconfigured/',
82+
'/Timestamp Authority \(TSA\) service is unavailable\. Check DNS\/network\/firewall connectivity from this server/',
8383
true,
8484
],
8585
];

0 commit comments

Comments
 (0)