-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdemo-batch-ts.php
More file actions
90 lines (77 loc) · 2.86 KB
/
Copy pathdemo-batch-ts.php
File metadata and controls
90 lines (77 loc) · 2.86 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
87
88
89
<?php
/* This demo shows you how to do add timestamp signatures in a batch process through the Swisscom All-in Signing Service.
*
* The revocation information of the timestamp signatures are 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\BatchTimestampModule;
use setasign\SetaPDF\Signer\Module\SwisscomAIS\SignException;
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 a re-usable array of filenames (in/out)
$files = [
[
'in' => 'files/tektown/Laboratory-Report.pdf',
'out' => 'output/tektown-timestamped.pdf',
'tmp' => new SetaPDF_Core_Writer_TempFile()
],
[
'in' => 'files/lenstown/Laboratory-Report.pdf',
'out' => 'output/lenstown-timestamped.pdf',
'tmp' => new SetaPDF_Core_Writer_TempFile()
],
[
'in' => 'files/etown/Laboratory-Report.pdf',
'out' => 'output/etown-timestamped.pdf',
'tmp' => new SetaPDF_Core_Writer_TempFile()
],
[
'in' => 'files/camtown/Laboratory-Report.pdf',
'out' => 'output/camtown-timestamped.pdf',
'tmp' => new SetaPDF_Core_Writer_TempFile()
],
];
// initiate a batch instance
$batch = new BatchTimestampModule($settings['customerId'], $httpClient, new RequestFactory(), new StreamFactory());
$batch->setSignatureContentLength(17500);
try {
// timestamp the documents and add the revoke information to the DSS of the documents
$batch->timestamp($files, true);
} 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>";
die();
}
?>
Timestamped documents:<br />
<ul>
<?php foreach ($files AS $file): ?>
<li><a href="<?php echo $file['out'];?>" download target="_blank"><?php echo basename($file['out']);?></a></li>
<?php endforeach; ?>
</ul>