/** * 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; }
$clientId = ''; // The password $password = ''; $profile = 'Default'; $pin = ''; } // URL to the WSDL file $wsdl = 'https://services.sealsignportal.com/sealsign/ws/BrokerClient?wsdl'; // Options for the SoapClient instance $clientOptions = array('stream_context' => stream_context_create(array('ssl' => array('verify_peer' => true, 'cafile' => __DIR__ . '/cacert.pem', 'peer_name' => 'services.sealsignportal.com')))); // create a HTTP writer $writer = new SetaPDF_Core_Writer_Http('QuoVadis-Signed.pdf'); // let's get the document $document = SetaPDF_Core_Document::loadByFilename('files/Laboratory-Report.pdf', $writer); // now let's create a signer instance $signer = new SetaPDF_Signer($document); $signer->setAllowSignatureContentLengthChange(false); $signer->setSignatureContentLength(32750); // standard size by QuoVadis // set some signature properies $signer->setLocation($_SERVER['SERVER_NAME']); $signer->setContactInfo('+01 2345 67890123'); $signer->setReason('testing...'); // create an QuoVadis module instance $module = new SetaPDF_Signer_QuoVadis_Module($wsdl, $accountId, $password, $clientId, $pin, $profile, $clientOptions); // login to QuoVadis system $module->login(); // sign the document with the use of the module $signer->sign($module); // logout $module->logout();
$domain = ''; } // Timestamp configuration $tsUrl = ''; // e.g. http://zeitstempel.dfn.de $tsUsername = ''; $tsPassword = ''; // Options for the SoapClient instance $clientOptions = array('stream_context' => stream_context_create(array('ssl' => array('verify_peer' => true, 'cafile' => __DIR__ . '/cacert.pem', 'peer_name' => 'prime.cosigntrial.com')))); // create a HTTP writer $writer = new SetaPDF_Core_Writer_Http('CoSign-Signed.pdf'); // let's get the document $document = SetaPDF_Core_Document::loadByFilename('files/Laboratory-Report.pdf', $writer); // let's prepare the temporary file writer: SetaPDF_Core_Writer_TempFile::setTempDir(realpath('_tmp/')); // now let's create a signer instance $signer = new SetaPDF_Signer($document); $signer->setAllowSignatureContentLengthChange(false); $signer->setSignatureContentLength(12000); // set some signature properies $signer->setLocation($_SERVER['SERVER_NAME']); $signer->setContactInfo('+01 2345 67890123'); $signer->setReason('Testing CoSign Signature SOAP API'); // create an CoSign module instance $module = new SetaPDF_Signer_CoSign_Module($wsdl, $username, $password, $domain, $clientOptions); // add timestamp server data if ($tsUrl) { $module->setTimestampData($tsUrl, $tsUsername, $tsPassword); } // sign the document with the use of the module $signer->sign($module);