0

我的目标:我要制作证书并下载它。

我有以下情况

在大纲中:

请求 浏览器 ---> PHP 页面 ---> PHP Rest web 服务 ---> bash

响应 bash ---> PHP Rest web 服务 ---> PHP 页面 ---> 浏览器

详细说明:

  1. 从 php 页面调用的 REst Web 服务接下来会执行以下操作:
    • 在 bash 中制作证书并将其导出为 pfx 文件。
    • 从 bash 文件返回证书作为字节流。 hexdump -b $exportedcert
  2. 从 Web 服务返回的输出是字节(这只是它的一部分):

    0000000 060 202 024 071 002 001 003 060 202 023 377 006 011 052 206 110 0000010 206 367 015 001 007 001 240 202 023 360 004 202 023 354 060 202 0000020 023 350 060 202 016 237 006 011 052 206 110 206 367 015 001 007 0000030 006 240 202 016 220 060 202 016 214 002 001 000 060 202 016 205 0000040 006 011 052 206 110 206 367 015 001 007 001 060 034 006 012 052 0000050 206 110 206 367 015 001 014 001 006 060 016 004 010 276 147 122 0000060 363 175 042 303 050 002 002 010 000 200 202 016 130 212 124 302 0000070 271 370 201 316 300 134 133 246 211 062 276 045 241 020 101 155 0000080 057 103 205 232 164 203 265 376 057 067 274 361 057 274 367 110 0000090 251 107 205 130 306 035 267 377 316 223 242 347 363 234 341 052 .....

  3. 当我被堆叠时在这里!将其转换回二进制文件后,我必须下载此流。我已经尝试了很多代码,但我没有得到结果。

      function hex2bin($data) {
            //function URL: http://fiddyp.co.uk/code-to-reverse-a-bin2hex-function/
            //function author: Andy Bailey
            $len = strlen($data);
            for($i=0;$i<$len;$i+=2) {
                $newdata .= pack("C",hexdec(substr($data,$i,2)));
            }
            return $newdata;
        }  
    
      $api_url = "http://mydomain/certificates";
      try {
       // @url POST /client_cert
         $result = $pest->post('/client_cert', $data);
         $res=explode('"', $result);
         $hex = hex2bin($res[1]);
         header("Content-Description: File Transfer");
         header("Content-Disposition: attachment; filename=hex.crt");
         header("Content-Type: application/octet-stream ");
         header("Content-Transfer-Encoding: binary");*
    
         // Read the file from disk
        echo $hex;
    } catch (Pest_NotFound $e) {
        // 404
        echo "Certificate with Name = " . $certName_pfx . " doesn't exist!";
    }
    

将证书添加到浏览器时,证书已损坏或无效。

有什么建议么 ?
PS:我正在使用Restler & Pest库。

4

1 回答 1

0

我已经想通了。

首先,升级 php 以5.4.*使用 hex2bin 并注意hex2bin输入参数中没有任何空格。

其次,使用xxdwith 选项-p获得没有偏移的十六进制输出,然后从输出中删除空格。

那会很完美。

于 2013-06-24T09:18:56.927 回答