对我来说,这是一个全新的概念,所以我在黑暗中拍摄。
要创建签名文件,请对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://
开头。为什么是这样? 最佳答案
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
生成密钥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);
}
参考文献:
关于php - 使用PHP为Apple Wallet通行证创建PKCS#7独立签名,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37010864/