Skip to content

Commit 558553a

Browse files
committed
feat: implement TSA
Was used a hardcoded TSA server and without authentication for now Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 8fb5ef0 commit 558553a

File tree

8 files changed

+545
-12
lines changed

8 files changed

+545
-12
lines changed

lib/Handler/SignEngine/JSignPdfHandler.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,18 @@ private function listParamsToString(array $params): string {
408408

409409
private function signWrapper(JSignPDF $jSignPDF): string {
410410
try {
411+
$params = [
412+
'--hash-algorithm' => $this->getHashAlgorithm(),
413+
'--tsa-server-url' => $this->appConfig->getValueString(Application::APP_ID, 'tsa_url', ''),
414+
];
415+
if (empty($params['--tsa-server-url'])) {
416+
unset($params['--tsa-server-url']);
417+
}
411418
$param = $this->getJSignParam();
412419
$param
413420
->setJSignParameters(
414421
$this->jSignParam->getJSignParameters()
415-
. ' --hash-algorithm ' . $this->getHashAlgorithm()
422+
. $this->listParamsToString($params)
416423
);
417424
$jSignPDF->setParam($param);
418425
return $jSignPDF->sign();

lib/Handler/SignEngine/Pkcs12Handler.php

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,26 @@ public function getCertificateChain($resource): array {
9999
continue;
100100
}
101101

102-
if (!isset($fromFallback['signingTime'])) {
103-
// Probably the best way to do this would be:
104-
// ASN1::asn1map($decoded[0], Maps\TheMapName::MAP);
105-
// But, what's the MAP to use?
106-
//
107-
// With maps also could be possible read all certificate data and
108-
// maybe discart openssl at this pint
109-
try {
110-
$decoded = ASN1::decodeBER($signature);
111-
$certificates[$signerCounter]['signingTime'] = $decoded[0]['content'][1]['content'][0]['content'][4]['content'][0]['content'][3]['content'][1]['content'][1]['content'][0]['content'];
112-
} catch (\Throwable) {
102+
$tsa = new TSA();
103+
$decoded = ASN1::decodeBER($signature);
104+
try {
105+
$certificates[$signerCounter]['timestamp'] = $tsa->extract($decoded);
106+
} catch (\Throwable $e) {
107+
}
108+
109+
if (!isset($fromFallback['signingTime']) || !$fromFallback['signingTime'] instanceof \DateTime) {
110+
$certificates[$signerCounter]['signingTime'] = $tsa->getSigninTime($decoded);
111+
if (!$certificates[$signerCounter]['signingTime'] instanceof \DateTime) {
112+
// Probably the best way to do this would be:
113+
// ASN1::asn1map($decoded[0], Maps\TheMapName::MAP);
114+
// But, what's the MAP to use?
115+
//
116+
// With maps also could be possible read all certificate data and
117+
// maybe discart openssl at this pint
118+
try {
119+
$certificates[$signerCounter]['signingTime'] = $decoded[0]['content'][1]['content'][0]['content'][4]['content'][0]['content'][3]['content'][1]['content'][1]['content'][0]['content'];
120+
} catch (\Throwable) {
121+
}
113122
}
114123
}
115124

0 commit comments

Comments
 (0)