PHP и протокол отметки времени

В PHP я должен подписать документ протоколом Timestamp через HTTP (RFC 3161), используя ARUBA в качестве CA.

Документация Арубы гласит:

Чтобы поставить отметку во времени, вы должны вызвать URL https://servizi.arubapec.it/tsa/ngrequest.php с методом POST. В теле POST вы должны вставить структуру TimeStampReq (RFC 3161), кодируемую в DER.

Как я могу сделать запрос, используя php?

1 ответ

Вы можете использовать функцию curl в php.

Хорошо, это часть моего отредактированного / модифицированного 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');
                }
            }
Другие вопросы по тегам