PHP and timestamp protocol

1.5k Views Asked by At

In PHP i must sign a document with the Timestamp Protocol via HTTP (RFC 3161) using ARUBA as CA.

The Aruba's documentation says:

To time-stamp a datum you must call the url https://servizi.arubapec.it/tsa/ngrequest.php with a POST method. In the POST body you must insert the structure TimeStampReq (RFC 3161) encode in DER.

How can i make the request using the php?

1

There are 1 best solutions below

1
On

you can use curl function in php.

Ok, This is part of my edited/modified tcpdf.php.

                //Send request to TSA Server with Curl
            if(extension_loaded('curl')) {
                $hdaLog .= "\nCurl was already Loaded\nCurl is sending tsRequest to \"".$this->timestamp_url."\"";
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $this->timestamp_url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_USERAGENT, '1');
                curl_setopt($ch, CURLOPT_POSTFIELDS, $raw_data);

                $tsResponse = curl_exec($ch);
                if($tsResponse != false) {
                    $hdaLog .= "\ntsRequest is sent";
                } else {
                    hdaLog("$hdaLog\ncan't send tsRequest, Timestamp failed",'w');
                }
                //parse ts response
                $hexTs = bin2hex($tsResponse);
                $tsparse = asn1parse($hexTs);
                $tsparse0 = asn1parse($tsparse[0][1]);
                if(count($tsparse0 > 1)) { //Remove response status data, only take timeStampToken
                    $timeStamp = seq($tsparse0[1][1]);
                } else {
                    $timeStamp = seq($tsparse0[0][1]);
                }

                //Add timestamp to TCPDF Signature
                $timeStamp = seq("060B2A864886F70D010910020E".set($timeStamp));
                $pkcs7 = int($pa1[0][1]).seq($pa1[1][1]).seq($pa1[2][1]).explicit(0, $pa1[3][1]).seq($pa1[4][1]).oct($pa1[5][1]);
                $time = seq($pkcs7.explicit(1,$timeStamp));
                $aa=seq(int(1). set($p3[1][1]).seq($p3[2][1]).explicit(0, $p3[3][1]).set($time));
                $hdaSignature = seq("06092A864886F70D010702".explicit(0,($aa)))."0000";

                $signature = $hdaSignature;
                hdaLog("$hdaLog\nTimestamp Success");
            } else {
                $hdaLog .= "\nCurl was not loaded, trying to load it...";
                if(@dl('php_curl.dll')) {
                    $hdaLog .= "\nCurl successfully Loaded";
                } else {
                    hdaLog("$hdaLog\nCurl failed to load timestamping failed", 'w');
                }
            }