-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdemo-ts-ltv.php
More file actions
86 lines (70 loc) · 2.89 KB
/
Copy pathdemo-ts-ltv.php
File metadata and controls
86 lines (70 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/* This demo shows you how to add a document timestamp signature to a PDF document
* through the Swisscom All-in Signing Service.
*
* The revocation information of the timestamp signature is added to the Document Security Store (DSS) afterwards to
* have LTV enabled.
*/
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Handler\CurlHandler;
use Http\Factory\Guzzle\RequestFactory;
use Http\Factory\Guzzle\StreamFactory;
use Mjelamanov\GuzzlePsr18\Client as Psr18Wrapper;
use setasign\SetaPDF\Signer\Module\SwisscomAIS\SignException;
use setasign\SetaPDF\Signer\Module\SwisscomAIS\TimestampModule;
date_default_timezone_set('Europe/Berlin');
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
// require the autoload class from Composer
require_once('../vendor/autoload.php');
if (!file_exists(__DIR__ . '/settings/settings-ts.php')) {
throw new RuntimeException('Missing settings/settings-ts.php!');
}
$settings = require(__DIR__ . '/settings/settings-ts.php');
$guzzleOptions = [
'handler' => new CurlHandler(),
'http_errors' => false,
'verify' => __DIR__ . '/ais-ca-ssl.crt',
'cert' => $settings['cert'],
'ssl_key' => $settings['privateKey']
];
$httpClient = new GuzzleClient($guzzleOptions);
// only required if you are using guzzle < 7
$httpClient = new Psr18Wrapper($httpClient);
// create an HTTP writer
$writer = new SetaPDF_Core_Writer_Http('Swisscom-Ts-Ltv.pdf');
$tempWriter = new SetaPDF_Core_Writer_TempFile();
// let's get the document
$document = SetaPDF_Core_Document::loadByFilename('files/tektown/Laboratory-Report.pdf', $tempWriter);
// now let's create a signer instance
$signer = new SetaPDF_Signer($document);
$signer->setAllowSignatureContentLengthChange(false);
$signer->setSignatureContentLength(17500);
$fieldName = $signer->getSignatureField()->getQualifiedName();
$signer->setSignatureFieldName($fieldName);
// set some signature properties
$signer->setLocation($_SERVER['SERVER_NAME']);
$signer->setContactInfo('+01 2345 67890123');
$signer->setReason('testing...');
// create a Swisscom AIS module instance
$module = new TimestampModule($settings['customerId'], $httpClient, new RequestFactory(), new StreamFactory());
// pass the timestamp module to the signer instance
$signer->setTimestampModule($module);
try {
// create the document timestamp
$signer->timestamp();
} catch (SignException $e) {
echo 'Error in SwisscomAIS: ' . $e->getMessage() . ' with code ' . $e->getCode() . '<br />';
/* Get the AIS Error details */
echo "<pre>";
var_dump($e->getResultMajor());
var_dump($e->getResultMinor());
echo "</pre>";
return;
}
// get a document instance of the temporary result
$document = SetaPDF_Core_Document::loadByFilename($tempWriter->getPath(), $writer);
// update the DSS with the revoke information of the last response
$module->updateDss($document, $fieldName);
// save and finish
$document->save()->finish();