【问题标题】:Creating a PKCS #7 detached signature for Apple Wallet passes using PHP使用 PHP 为 Apple Wallet 通行证创建 PKCS #7 分离签名
【发布时间】:2016-05-03 17:42:22
【问题描述】:

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

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

我的理解:

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

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

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

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

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

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

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

我将包含一个数组,其键为 signing-time2015-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:// 为前缀。这是为什么呢?

【问题讨论】:

    标签: php ios ssl sign pkcs#7


    【解决方案1】:
    1. https://developer.apple.com/account/ios/identifier/passTypeId 生成通行证类型 ID
    2. https://developer.apple.com/account/ios/certificate/create/ 为该通行证类型 ID 创建证书
    3. 下载证书并将其放入您的钥匙串中
    4. 在您的钥匙串中找到证书并将其导出为Certificates.p12,无需密码
    5. 打开终端,运行openssl pkcs12 -in Certificates.p12 -clcerts -nokeys -out pass_cert.pem -passin pass:生成证书
    6. 在终端运行openssl pkcs12 -in Certificates.p12 -nocerts -out pass_key.pem -passin pass: -passout pass:YourPassword生成密钥
    7. https://www.apple.com/certificateauthority/ 下载 WWDR 证书并将其放入您的钥匙串中
    8. 将 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);
    }
    

    参考资料:

    【讨论】:

    • 这仍然对您有用吗?我可以创建 .pkpass 文件,但我的 iphone 无法打开它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-12
    • 2019-03-17
    相关资源
    最近更新 更多