1

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

Aruba 的文档说:

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

如何使用 php 发出请求?

4

1 回答 1

1

您可以在 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');
                }
            }
于 2018-08-20T16:46:37.733 回答