$customerId = ""; } // options for the SoapClient instance $clientOptions = array('stream_context' => stream_context_create(array('ssl' => array('verify_peer' => true, 'cafile' => __DIR__ . '/ais-ca-ssl.crt', 'peer_name' => 'ais.swisscom.com'))), 'local_cert' => $cert, 'passphrase' => $passphrase); // the signature field name $signatureFieldName = 'Signature'; // create a 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(32000); $signer->setSignatureFieldName($signatureFieldName); // set some signature properties $signer->setLocation($_SERVER['SERVER_NAME']); $signer->setContactInfo('+01 2345 67890123'); $signer->setReason('testing...'); // create an Swisscom AIS module instance $module = new SetaPDF_Signer_SwisscomAIS_Module($customerId, $clientOptions); // let's add PADES revoke information to the resulting signatures $module->setAddRevokeInformation('PADES'); // pass the timestamp module to the signer instance $signer->setTimestampModule($module); try { // create the document timestamp $signer->timestamp(); } catch (SetaPDF_Signer_SwisscomAIS_Exception $e) { echo 'Error in SwisscomAIS: ' . $e->getMessage() . ' with code ' . $e->getCode() . '<br />';
/** * Timestamps a collection of document instances. * * The document instances need to have writer instances setup properbly. * * @param SetaPDF_Core_Document[] $documents * @param bool $updateDss * @return bool * @throws SetaPDF_Core_Exception * @throws SetaPDF_Signer_Exception * @throws SetaPDF_Signer_Exception_ContentLength * @throws SetaPDF_Signer_SwisscomAIS_Exception */ public function timestamp(array $documents, $updateDss = false) { $digestMethod = $this->_getDigestMethod(); $data = array(); $no = 0; foreach ($documents as $document) { $signer = new SetaPDF_Signer($document); $signer->setSignatureContentLength($this->getSignatureContentLength()); $signer->setSignatureFieldName($this->getSignatureFieldName()); $tmpDocument = $signer->preTimestamp(new SetaPDF_Core_Writer_TempFile()); $data[$no] = array('document' => $document, 'signer' => $signer, 'tmpDocument' => $tmpDocument, 'digestValue' => $this->_getHash($tmpDocument->getHashFile())); $no++; } $req = array('SignRequest' => array('RequestID' => $this->_createRequestId(), 'Profile' => 'http://ais.swisscom.ch/1.0', 'OptionalInputs' => array('SignatureType' => 'urn:ietf:rfc:3161', 'ClaimedIdentity' => array('Name' => $this->_customerId), 'AdditionalProfile' => array('http://ais.swisscom.ch/1.0/profiles/batchprocessing', 'urn:oasis:names:tc:dss:1.0:profiles:timestamping')), 'InputDocuments' => array())); foreach ($data as $no => $documentData) { $req['SignRequest']['InputDocuments'][] = array('ID' => $no, 'DigestMethod' => array('Algorithm' => $digestMethod), 'DigestValue' => $documentData['digestValue']); } if ($this->_revokeInformation) { $req['SignRequest']['OptionalInputs']['AddRevocationInformation'] = array('Type' => $this->_revokeInformation); } $client = new SoapClient($this->_wsdl, array_merge($this->_clientOptions, array('trace' => true, 'encoding' => 'UTF-8', 'soap_version' => SOAP_1_1))); $this->_lastResult = $client->sign($req); $signResult = $this->_lastResult->SignResponse->Result; if ($signResult->ResultMajor !== 'urn:oasis:names:tc:dss:1.0:resultmajor:Success') { $exception = new SetaPDF_Signer_SwisscomAIS_Exception($signResult->ResultMessage->_); $exception->setRequest($req); $exception->setResult($this->_lastResult); throw $exception; } $timestamps = $this->_lastResult->SignResponse->SignatureObject->Other->SignatureObjects->ExtendedSignatureObject; if (!is_array($timestamps)) { $timestamps = array($timestamps); } foreach ($timestamps as $timestampData) { $timestamp = $timestampData->Timestamp->RFC3161TimeStampToken; $no = $timestampData->WhichDocument; $this->_signatures[$no] = $timestamp; $documentData = $data[$no]; /** * @var $signer SetaPDF_Signer */ $signer = $documentData['signer']; if (!$updateDss || !$this->_revokeInformation) { $signer->saveSignature($documentData['tmpDocument'], $timestamp); } else { $tempWriter = new SetaPDF_Core_Writer_TempFile(); $writer = $documentData['document']->getWriter(); $documentData['document']->setWriter($tempWriter); $signer->saveSignature($documentData['tmpDocument'], $timestamp); $document = SetaPDF_Core_Document::loadByFilename($tempWriter->getPath(), $writer); $this->updateDss($document, $this->getSignatureFieldName()); $document->save()->finish(); } } return true; }