简体   繁体   English

我如何从苹果全球开发者证书和 .p12 文件中提取公钥和私钥?

[英]How would I extract the public and private keys from the apple world wide developer certificate and .p12 file?

So I am attempting to write functionality for passbook or, as they call it now, "Wallet."所以我正在尝试为存折编写功能,或者他们现在称之为“钱包”。 I wrote all the necessary code to to write the JSON, write the files in a temp directory, then calculate the checksum and put in back in the manifest.我编写了所有必要的代码来编写 JSON,将文件写入临时目录,然后计算校验和并放回清单中。 Now I am stuck at the part where I sign the Apple World Wide Developer Certificate with the .p12 of the of the passes.P12 file to get the desired .der file?现在我被困在我用pass.P12文件的.p12签署Apple全球开发人员证书以获得所需的.der文件的部分?

<cfset signer = new rsa_signer(fileRead(expandPath("test_code/public_key.txt")),fileRead(expandPath("test_code/private_key.pem")),"SHA512withRSA")>


<cffile action="READ" file="#xtemp_folder#\manifest.json" variable="xtext">
<cfset xsignature = signer.sign(xtext)>
<!---- write to file ----->
<cffile action="WRITE" file="#xtemp_folder#\signature.der" output="#xsignature#">

<!---- create zipped file for user downloading ----->
<cf_write_log log_key="#attributes.log_key#" data="<hr>create zip files from temp holding folder..">
<cfset xzip_filename = "h:\eshowtemp\#xtemp_folder_string#.pkpass">
<cfdirectory action="LIST" directory="#xtemp_folder#" name="files">
<cf_write_log log_key="#attributes.log_key#" data="files=#files.recordcount#">
<cfzip file="#xzip_filename#" source="#xtemp_folder#">

The above code is a snippet of my cold fusion program that ideally signs and prints out the desired .pkpass file.上面的代码是我的冷聚变程序的一个片段,它在理想情况下签名并打印出所需的 .pkpass 文件。 I have confirmed this program works with other provided public and private keys.我已经确认这个程序可以与其他提供的公钥和私钥一起使用。 Where I read the signer, I have tried exporting the world wide developer certificate into a .pem file.在我阅读签名者的地方,我尝试将全球开发人员证书导出到 .pem 文件中。 I then did the same with the .p12, exporting that into a pem file and plugged both of the pem files into the rsa_signer and no luck.然后我对 .p12 做了同样的事情,将它导出到一个 pem 文件中,并将两个 pem 文件插入到 rsa_signer 中,但没有运气。 So I'm stuck where to go from here.所以我被困在从这里去哪里。

Here's what I have noticed.这是我注意到的。 On the public and private keys that do work, they look something like this:在有效的公钥和私钥上,它们看起来像这样:

-----BEGIN PRIVATE KEY----- -----开始私钥-----

Encryption.....加密.....

-----END PRIVATE KEY----- -----结束私钥-----

-----BEGIN PUBLIC KEY----- -----开始公钥-----

Encryption... -----END PUBLIC KEY-----加密... -----END PUBLIC KEY-----

Compared to my 2 .pem files (Apple world wide developer cert + passes.p12 file)与我的 2 个 .pem 文件(Apple 全球开发者证书 + pass.p12 文件)相比

///Apple dev cert.pem ///苹果开发证书.pem

-----BEGIN CERTIFICATE----- -----开始认证-----

///Encryption ///加密

-----END CERTIFICATE----- -----结束证书-----

//pass.pem (converted from .p12) //pass.pem(从.p12转换而来)

Bag Attributes friendlyName: Pass Type ID: XXX localKeyID: XXX subject=/UID=XXX/CN=Pass Type ID: XXX/OU=XXX/O=XXXC=US issuer=/C=US/O=Apple Inc./OU=Apple Worldwide Developer Relations/CN=Apple Worldwide Developer Relations Certification Authority -----BEGIN CERTIFICATE----- Bag Attributes FriendlyName: Pass Type ID: XXX localKeyID: XXX subject=/UID=XXX/CN=Pass Type ID: XXX/OU=XXX/O=XXXC=US issuer=/C=US/O=Apple Inc./OU =Apple Worldwide Developer Relations/CN=Apple Worldwide Developer Relations Certification Authority -----BEGIN CERTIFICATE-----

XXXX -----END CERTIFICATE----- XXXX -----结束证书-----

Could this be why my coldfusion program does not like my pem files?这可能是我的 Coldfusion 程序不喜欢我的 pem 文件的原因吗? The .pem files say "Begin certificate" while the other pems say "Begin public/private key." .pem 文件说“开始证书”,而其他 pem 说“开始公钥/私钥”。

Any help would be much appreciated.任何帮助将非常感激。 Thanks!谢谢!

https://rietta.com/blog/2012/01/27/openssl-generating-rsa-key-from-command/ https://rietta.com/blog/2012/01/27/openssl-generating-rsa-key-from-command/

step to create signature file is (after getting manifest.json)创建签名文件的步骤是(在获取 manifest.json 之后)
1. load p12 file content (pass type id certification) -> $cert_info 1.加载p12文件内容(通过type id认证)-> $cert_info
2. decode $cert_info with password by using 2. 使用密码解码 $cert_info
openssl_pkcs12_read($cert_store, $cert_info, $password) -> $cert_info will keep all decoded info 3. get private key from $cert_info by using openssl_pkcs12_read($cert_store, $cert_info, $password) -> $cert_info 将保留所有解码信息 3. 通过使用从 $cert_info 获取私钥
$pkey = openssl_pkey_get_private($cert_info['pkey'], ""); $pkey = openssl_pkey_get_private($cert_info['pkey'], "");
and save $pkey into pem temp file并将 $pkey 保存到 pem 临时文件中
3.1 save cert info by using $cert = openssl_x509_read($cert_info['cert']); 3.1 使用 $cert = openssl_x509_read($cert_info['cert']); 保存证书信息;
4. use manifest.json, cert info ($cert), Apple World Wide Developer Certificate to make pkcs7 file (temp_signature) by using 4.使用manifest.json、cert info($cert)、Apple World Wide Developer Certificate制作pkcs7文件(temp_signature)
openssl_pkcs7_sign("./pass_file/manifest.json", "./pass_file/temp_signature", $cert, $pkey, array(), PKCS7_BINARY | PKCS7_DETACHED, "./AppleWWDRCA.pem") openssl_pkcs7_sign("./pass_file/manifest.json", "./pass_file/temp_signature", $cert, $pkey, array(), PKCS7_BINARY | PKCS7_DETACHED, "./AppleWWDRCA.pem")
5. load temp_signature file content and extract data after filename="smime.p7s" and before ------ (substr) and encode with base64_decode and save into 'signature' file 5.加载temp_signature文件内容并提取filename="smime.p7s"之后和------(substr)之前的数据并用base64_decode编码并保存到'signature'文件中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM