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

要创建签名文件,请对PKCS#7分离签名。
清单文件,使用与签名关联的私钥
证书。将WWDR中间证书作为以下内容的一部分
签名。您可以从Apple网站下载此证书。
将通行证的顶层将签名写入文件签名
包。包括使用签署通行证的日期和时间
S / MIME签名时间属性。

我的理解:

要创建签名文件,请对清单文件进行PKCS#7分离签名

我将使用openssl_pkcs7_sign标志使用 PKCS7_DETACHED 函数。

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

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

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

我将在extracerts参数中包括WWDR证书的路径

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

我将包含一个带有键signing-time的数组,并为2015-05-03 10:40:00参数设置类似于headers的值。

我的代码:

private function createSignature($dir)
{
    $cert = '/etc/ssl/cert.pem';
    $key = '/etc/ssl/private/cert.key';
    $wwdr = '/location/of/apple/wwdr/cert.cer';
    $headers = [
        'signing-time' => (new DateTime())->format('o-m-d H:i:s'),
    ];

    return openssl_pkcs7_sign("$dir/manifest.json", "$dir/signature", $cert, $key, $headers, PKCS7_DETACHED, $wwdr);
}

其他问题:

openssl_pkcs7_sign函数的文档示例中,我注意到文件的某些位置以file://开头。为什么是这样?

最佳答案

  • https://developer.apple.com/account/ios/identifier/passTypeId上生成通行证类型ID
  • https://developer.apple.com/account/ios/certificate/create/上为该通行证类型ID创建证书
  • 下载证书并将其放入您的钥匙串
  • 在您的钥匙串中找到证书,然后将其导出为Certificates.p12,而无需输入密码
  • 打开终端,运行openssl pkcs12 -in Certificates.p12 -clcerts -nokeys -out pass_cert.pem -passin pass:以生成证书
  • 在终端中,运行openssl pkcs12 -in Certificates.p12 -nocerts -out pass_key.pem -passin pass: -passout pass:YourPassword生成密钥
  • https://www.apple.com/certificateauthority/下载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);
    }
    

    参考文献:
  • https://www.raywenderlich.com/20734/beginning-passbook-part-1
  • https://github.com/tschoffelen/PHP-PKPass/blob/master/PKPass.php
  • 关于php - 使用PHP为Apple Wallet通行证创建PKCS#7独立签名,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37010864/

    10-09 07:03
    查看更多