php 警告:stream_socket_client():无法设置私钥文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26890378/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:05:51  来源:igfitidea点击:

warning: stream_socket_client(): unable to set private key file

phpiosssl

提问by kumar

unable to get this getting these errors when running PHP in terminal as php simplepush.php

在终端中将 PHP 作为 php simplepush.php 运行时无法得到这些错误

Warning: stream_socket_client(): Unable to set private key file `/users/accenture/Desktop/newAPNS/ck.pem' in /users/accenture/Desktop/newAPNS/simplepush.php on line 22

Warning: stream_socket_client(): failed to create an SSL handle in /users/accenture/Desktop/newAPNS/simplepush.php on line 22

Warning: stream_socket_client(): Failed to enable crypto in /users/accenture/Desktop/newAPNS/simplepush.php on line 22

Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /users/accenture/Desktop/newAPNS/simplepush.php on line 22

Failed to connect: 0 

I created all certificates and pem file by using raywenderlich article, http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1#comments

我使用 raywenderlich 文章创建了所有证书和 pem 文件,http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1#comments

回答by kumar

Problem is pem file wasn't correct, I created pem file using http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1. Creation of p12 file and with p12 creating pem file are not working for me. Correct process to create p12 and with p12 creating pem file as bellow

问题是 pem 文件不正确,我使用http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1创建了 pem 文件。创建 p12 文件和使用 p12 创建 pem 文件对我不起作用。创建 p12 和 p12 创建 pem 文件的正确过程如下

Once you have the certificate from Apple for your application, export your key and the apple certificate as p12 files. Here is a quick walkthrough on how to do this:

获得 Apple 为您的应用程序提供的证书后,将您的密钥和 Apple 证书导出为 p12 文件。以下是有关如何执行此操作的快速演练:

  1. Click the disclosure arrow next to your certificate in Keychain Access and select the certificate and the key.
  2. Right click and choose Export 2 items….
  3. Choose the p12 format from the drop down and name it cert.p12.
  1. 在 Keychain Access 中单击您的证书旁边的披露箭头,然后选择证书和密钥。
  2. 右键单击并选择导出 2 个项目...。
  3. 从下拉列表中选择 p12 格式并将其命名为 cert.p12。

Now convert the p12 file to a pem file:

现在将 p12 文件转换为 pem 文件:

$ openssl pkcs12 -in cert.p12 -out apple_push_notification_production.pem -nodes -clcerts

This is working for me, now I am getting a push notification.

这对我有用,现在我收到推送通知。

回答by Starchand

Converting the key file to pem recommend in http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1was causing problems for me.

将密钥文件转换为http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1中推荐的 pem给我带来了问题。

Running

跑步

openssl pkcs12 -in keyname.p12 -out keyname.pem -nodes -clcerts

instead of the

而不是

openssl pkcs12 -nocerts -out keyname.pem -in keyname.p12

solved my issues.

解决了我的问题。

回答by Rashid

I have followed a youtubetutorial which is nearly same as raywenderlich article. I've just forgot to add PEM pass phrase. After adding it, as described here, it worked:

我遵循了一个与 raywenderlich 文章几乎相同的youtube教程。我刚刚忘记添加 PEM 密码。添加后,如here所述,它起作用了:

stream_context_set_option($ctx, 'ssl', 'passphrase', 'MyPassPhrase');