PHP 和时间戳协议


PHP and timestamp protocol

在PHP中,我必须使用ARUBA作为CA通过HTTP(RFC 3161)使用时间戳协议对文档进行签名。

阿鲁巴的文件说:

要为基准添加时间戳,必须调用 url https://servizi.arubapec.it/tsa/ngrequest.php 使用 POST 方法。在 POST 正文中,您必须插入结构 TimeStampReq (RFC 3161) 在 DER 中编码。

如何使用 php 发出请求?

你可以在php中使用curl函数。

好的,这是我编辑/修改的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');
                }
            }