使用PHP为Apple钱包通行证创建PKCS#7分离签名

使用PHP为Apple钱包通行证创建PKCS#7分离签名,php,ios,ssl,sign,pkcs#7,Php,Ios,Ssl,Sign,Pkcs#7,这对我来说是一个全新的概念,所以我在黑暗中拍摄 要创建签名文件,请对文件进行PKCS#7分离签名 清单文件,使用与签名关联的私钥 证明书将WWDR中间证书作为 签名。您可以从苹果的网站下载此证书。 将签名写入pass顶层的文件签名 包裹包括使用 S/MIME签名时间属性 我的理解是: 要创建签名文件,请对清单文件进行PKCS#7分离签名 我将使用标志PKCS7\u DETACHED使用该函数 使用与签名证书关联的私钥 我将使用sslcert.pem文件的位置作为signcert参数,使用cert

这对我来说是一个全新的概念,所以我在黑暗中拍摄

要创建签名文件,请对文件进行PKCS#7分离签名 清单文件,使用与签名关联的私钥 证明书将WWDR中间证书作为 签名。您可以从苹果的网站下载此证书。 将签名写入pass顶层的文件签名 包裹包括使用 S/MIME签名时间属性

我的理解是: 要创建签名文件,请对清单文件进行PKCS#7分离签名

我将使用标志
PKCS7\u DETACHED
使用该函数

使用与签名证书关联的私钥

我将使用ssl
cert.pem
文件的位置作为
signcert
参数,使用
cert.key
文件的位置作为
privkey
参数

包括WWDR中间证书作为签名的一部分

我将在
extracters
参数中包含WWDR证书的路径

包括使用S/MIME签名时间属性对通行证进行签名的日期和时间

我将包含一个数组,其中包含一个键
签名时间
,并为
标题
参数指定类似于
2015-05-03 10:40:00的值

我的代码: 其他问题: 我注意到在
openssl\u pkcs7\u sign
函数的文档示例中,文件的某些位置以
file://
作为前缀。为什么会这样

  • 在以下位置生成传递类型ID:
  • 在中为该通行证类型ID创建证书
  • 下载证书并将其放入密钥链中
  • 在密钥链中找到证书并将其导出为
    证书。p12
    无密码
  • 打开终端,运行
    openssl pkcs12-in Certificates.p12-clcerts-nokeys-out pass\u cert.pem-passin pass:
    生成证书
  • 在终端中,运行openssl pkcs12-In Certificates.p12-nocerts-out pass\u key.pem-passin pass:-passout pass:yourspassword来生成密钥
  • 从下载WWDR证书并将其放入密钥链中
  • 将WWDR证书从密钥链导出为
    WWDR.pem
  • 创建分离签名的函数:

    public function createSignature()
    {
        $cert = "file://location/of/pass_cert.pem";
        $key = "file://location/of/pass_key.pem";
        $wwdr = "/location/of/wwdr.pem";
    
        openssl_pkcs7_sign("/location/of/manifest.json", "/location/of/signature",
            $cert, [$key, 'YourPassword'], [], PKCS7_BINARY | PKCS7_DETACHED, $wwdr);
    
        // convert pem to der
        $signature = file_get_contents("/location/of/signature");
        $begin = 'filename="smime.p7s"';
        $end = '------';
        $signature = substr($signature, strpos($signature, $begin) + strlen($begin));
        $signature = substr($signature, 0, strpos($signature, $end));
        $signature = trim($signature);
        $signature = base64_decode($signature);
    
        file_put_contents("/location/of/signature", $signature);
    }
    
    参考资料:

    public function createSignature()
    {
        $cert = "file://location/of/pass_cert.pem";
        $key = "file://location/of/pass_key.pem";
        $wwdr = "/location/of/wwdr.pem";
    
        openssl_pkcs7_sign("/location/of/manifest.json", "/location/of/signature",
            $cert, [$key, 'YourPassword'], [], PKCS7_BINARY | PKCS7_DETACHED, $wwdr);
    
        // convert pem to der
        $signature = file_get_contents("/location/of/signature");
        $begin = 'filename="smime.p7s"';
        $end = '------';
        $signature = substr($signature, strpos($signature, $begin) + strlen($begin));
        $signature = substr($signature, 0, strpos($signature, $end));
        $signature = trim($signature);
        $signature = base64_decode($signature);
    
        file_put_contents("/location/of/signature", $signature);
    }