1

每当我尝试将我的通行证添加到存折时,它都会失败,原因是:

清单签名未成功验证

我的签名代码如下:

$privKey = "certs/key.pem";
$keyPassword = "PASSWORD";
$wwdr = "certs/wwdr.pem";
$cert = file_get_contents("certs/certificate.pem");
$certData = openssl_x509_read($cert);

openssl_pkcs7_sign($path . "/" . "manifest.json", 
$path . "/" . "signature", 
$certData, 
array("file://" . $privKey, $keyPassword), 
array(), 
PKCS7_BINARY|PKCS7_NOATTR|PKCS7_DETACHED,
"certs/wwdr.pem");

谢谢!

4

1 回答 1

0

尝试以下操作,使用证书文件,而不是其内容并删除 PKSC7_NOATTR,因为从 iOS 6.1.1 开始,签名应该包含签名日期。

openssl_pkcs7_sign($path . "/manifest.json",
            $path . "/signature",
            'file://' . $fullPathTo . 'certs/certificate.pem',
            array('file://' . $fullPathTo . $privKey, $keyPassword),
            array(),
            PKCS7_BINARY|PKCS7_DETACHED,
            $fullPathTo . $wwdr);

openssl_pkcs7_sign创建一个电子邮件附件,因此您还需要提取签名部分,因为这就是 .pkpass 捆绑包所需的全部内容。

// Read the signature file
$email = file_get_contents($path . "/signature");

// Extract the signature using a regex
$pattern = "/.*?Content-Disposition: attachment; filename=\".*?\"(.*?)-----.*?/sm";
preg_match_all($pattern, $email, $signature);

// Base64 encode the part of result we need
$signature = base64_decode($signature[1][0]);

// Write contents to a new signature file
file_put_contents ($path . "/signature", $signature);

如果它仍然没有摄取,请检查您的证书是有效的 Pass Type ID 证书,并且您的私钥是您的证书的正确密钥。您甚至可能想要检查您的 PHP 日志以验证该openssl_pkcs7_sign命令是否正确执行。


更新

当我尝试将您的 .pkpass 包添加到 Passbook 时,我在设备控制台中收到以下错误。

<Warning>: Invalid data error reading pass pass.datafarms.peppermints/123456. Manifest JSON didn't parse: The operation couldn’t be completed. (Cocoa error 3840.)

您的签名文件看起来不错,错误在于计算 SHA1 哈希和构建的代码部分manifest.json

查看您的 .pkpass 包,您的清单以两种方式损坏:

  1. 它包含多个对象
  2. SHA1 值与文件内容不匹配

对于这个 .pkpass 包,您的 manifest.json 应该是:

{
    "strip.png" : "f95387c0843a51dac73f1b0a3181da9c99ba3dc4",
    "strip@2x.png" : "f325a97fc6bafbe53a5e8feb7b2c509a8ceb6b10",
    "logo@2x.png" : "7b7b025774128b95e50f2bcda55e608412e95a37",
    "icon@2x.png" : "68b61c27657a0018da71c7f73626c8a891da753c",
    "icon.png" : "6b15fa477ece83fdd4f544a2381444272a0e39a0",
    "logo.png" : "7cf1d842afde33c4b14978f330cf98d05c3e57f2",
    "pass.json" : "971417ec80638736cb3392d6d5db53d554f138a4",
}

但目前是:

{
    "strip.png" : "156b528933284a0a58fc316897e1b7d202dfe3e8",
    "strip@2x.png" : "99f5dc1a0c5ed300193f87e42d8632f7251a3f26",
    "logo@2x.png" : "f36816f173aa9011186b80b140dfc49395d31051",
    "icon@2x.png" : "c10dd92e6c043c4bcf6214251d6fcb2a760cd9ad",
    "icon.png" : "d181ad4208e06afb63d5e6049a40521b458da19d",
    "logo.png" : "81c27284f77a447375ba39fb2f0005eeaccf28d8",
    "pass.json" : "e5960e9004d5fff241d77415413d609f47d7b2fb",
}{
    "strip.png" : "156b528933284a0a58fc316897e1b7d202dfe3e8",
    "strip@2x.png" : "99f5dc1a0c5ed300193f87e42d8632f7251a3f26",
    "logo@2x.png" : "f36816f173aa9011186b80b140dfc49395d31051",
    "icon@2x.png" : "c10dd92e6c043c4bcf6214251d6fcb2a760cd9ad",
    "icon.png" : "d181ad4208e06afb63d5e6049a40521b458da19d",
    "logo.png" : "81c27284f77a447375ba39fb2f0005eeaccf28d8",
    "pass.json" : "e5960e9004d5fff241d77415413d609f47d7b2fb",
}{
    "strip.png" : "156b528933284a0a58fc316897e1b7d202dfe3e8",
    "strip@2x.png" : "99f5dc1a0c5ed300193f87e42d8632f7251a3f26",
    "logo@2x.png" : "f36816f173aa9011186b80b140dfc49395d31051",
    "icon@2x.png" : "c10dd92e6c043c4bcf6214251d6fcb2a760cd9ad",
    "icon.png" : "d181ad4208e06afb63d5e6049a40521b458da19d",
    "logo.png" : "81c27284f77a447375ba39fb2f0005eeaccf28d8",
    "pass.json" : "e5960e9004d5fff241d77415413d609f47d7b2fb",
}{
    "strip.png" : "156b528933284a0a58fc316897e1b7d202dfe3e8",
    "strip@2x.png" : "99f5dc1a0c5ed300193f87e42d8632f7251a3f26",
    "logo@2x.png" : "f36816f173aa9011186b80b140dfc49395d31051",
    "icon@2x.png" : "c10dd92e6c043c4bcf6214251d6fcb2a760cd9ad",
    "icon.png" : "d181ad4208e06afb63d5e6049a40521b458da19d",
    "logo.png" : "81c27284f77a447375ba39fb2f0005eeaccf28d8",
    "pass.json" : "e5960e9004d5fff241d77415413d609f47d7b2fb",
}{
    "strip.png" : "156b528933284a0a58fc316897e1b7d202dfe3e8",
    "strip@2x.png" : "99f5dc1a0c5ed300193f87e42d8632f7251a3f26",
    "logo@2x.png" : "f36816f173aa9011186b80b140dfc49395d31051",
    "icon@2x.png" : "c10dd92e6c043c4bcf6214251d6fcb2a760cd9ad",
    "icon.png" : "d181ad4208e06afb63d5e6049a40521b458da19d",
    "logo.png" : "81c27284f77a447375ba39fb2f0005eeaccf28d8",
    "pass.json" : "e5960e9004d5fff241d77415413d609f47d7b2fb",
}{
    "strip.png" : "156b528933284a0a58fc316897e1b7d202dfe3e8",
    "strip@2x.png" : "99f5dc1a0c5ed300193f87e42d8632f7251a3f26",
    "logo@2x.png" : "f36816f173aa9011186b80b140dfc49395d31051",
    "icon@2x.png" : "c10dd92e6c043c4bcf6214251d6fcb2a760cd9ad",
    "icon.png" : "d181ad4208e06afb63d5e6049a40521b458da19d",
    "logo.png" : "81c27284f77a447375ba39fb2f0005eeaccf28d8",
    "pass.json" : "e5960e9004d5fff241d77415413d609f47d7b2fb",
}{
    "strip.png" : "156b528933284a0a58fc316897e1b7d202dfe3e8",
    "strip@2x.png" : "99f5dc1a0c5ed300193f87e42d8632f7251a3f26",
    "logo@2x.png" : "f36816f173aa9011186b80b140dfc49395d31051",
    "icon@2x.png" : "c10dd92e6c043c4bcf6214251d6fcb2a760cd9ad",
    "icon.png" : "d181ad4208e06afb63d5e6049a40521b458da19d",
    "logo.png" : "81c27284f77a447375ba39fb2f0005eeaccf28d8",
    "pass.json" : "e5960e9004d5fff241d77415413d609f47d7b2fb",
}{
    "strip.png" : "156b528933284a0a58fc316897e1b7d202dfe3e8",
    "strip@2x.png" : "99f5dc1a0c5ed300193f87e42d8632f7251a3f26",
    "logo@2x.png" : "f36816f173aa9011186b80b140dfc49395d31051",
    "icon@2x.png" : "c10dd92e6c043c4bcf6214251d6fcb2a760cd9ad",
    "icon.png" : "d181ad4208e06afb63d5e6049a40521b458da19d",
    "logo.png" : "81c27284f77a447375ba39fb2f0005eeaccf28d8",
    "pass.json" : "e5960e9004d5fff241d77415413d609f47d7b2fb",
}{
    "strip.png" : "156b528933284a0a58fc316897e1b7d202dfe3e8",
    "strip@2x.png" : "99f5dc1a0c5ed300193f87e42d8632f7251a3f26",
    "logo@2x.png" : "f36816f173aa9011186b80b140dfc49395d31051",
    "icon@2x.png" : "c10dd92e6c043c4bcf6214251d6fcb2a760cd9ad",
    "icon.png" : "d181ad4208e06afb63d5e6049a40521b458da19d",
    "logo.png" : "81c27284f77a447375ba39fb2f0005eeaccf28d8",
    "pass.json" : "e5960e9004d5fff241d77415413d609f47d7b2fb",
}{
    "strip.png" : "156b528933284a0a58fc316897e1b7d202dfe3e8",
    "strip@2x.png" : "99f5dc1a0c5ed300193f87e42d8632f7251a3f26",
    "logo@2x.png" : "f36816f173aa9011186b80b140dfc49395d31051",
    "icon@2x.png" : "c10dd92e6c043c4bcf6214251d6fcb2a760cd9ad",
    "icon.png" : "d181ad4208e06afb63d5e6049a40521b458da19d",
    "logo.png" : "81c27284f77a447375ba39fb2f0005eeaccf28d8",
    "pass.json" : "e5960e9004d5fff241d77415413d609f47d7b2fb",
}
于 2013-03-22T04:40:16.453 回答