跪了,導出ios推送證書

百度一下,會有很多ios推送證書的方法

比如這套:

1、證書轉成pem

openssl x509 -in aps_developer.cer -inform der  -out PushChatCert.pem

2、私鑰Push.p12文件轉換成.pem文件

openssl pkcs12 -nocerts -out PushChatKey.pem -in Push.p12

3、私鑰與證書整合到一個.pem文件

cat PushChatCert.pem PushChatKey.pem > ck.pem

4、測試


openssl s_client -connect gateway.sandbox.push.apple.com:2195  -cert PushChatCert.pem -key PushChatKey.pem

但是怎麼都拿到的證書怎麼都搞不通。。

後來

openssl pkcs12 -clcerts -nokeys -nodes -out apns-dev-key4.pem -in push_dis.p12

 openssl pkcs12 -nocerts  -nodes -out apns-dev-key5.pem -in push_dis.p12

openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert apns-dev-key4.pem -key apns-dev-key5.pem

居然通了


我只是不小心看了一下文件內容,因爲發現好像用錯命令了,然後發現一個裏面是cert,一個裏面是key

然後就試了試。。媽蛋,通了


誰能告訴我,究竟是咋回事兒= =

蛋碎了。。

一共給來四個文件,dev.cer,dev.key,dis.cer,dis.key,都是p12文件,都這樣生成了一下。。然後,有4個key了可以用的東西了。。

localkeyID全是不一樣的= =



轉個別人的東西

Erlang代碼  收藏代碼
  1. %%%-------------------------------------------------------------------                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
  2. %%% @doc  
  3. %%%  
  4. %%% @end  
  5. %%% Created : 31 Aug 2012 langxianzhe@163.com   
  6. %%%-------------------------------------------------------------------  
  7.   
  8. -module(test_apns).  
  9. -record(apns_connection, {apple_host        = "gateway.sandbox.push.apple.com"      :: string(),  
  10.                           apple_port        = 2195                                  :: integer(),  
  11.                           cert_file         = "priv/cert.pem"                       :: string(),  
  12.                           key_file          = undefined                             :: undefined | string(),  
  13.                           timeout           = 30000                                 :: integer(),  
  14.                           error_fun         = fun(X,Y) -> erlang:display({X,Y}) end :: fun((binary(), apns:status()) -> stop | _),  
  15.                           feedback_host     = "feedback.sandbox.push.apple.com"     :: string(),  
  16.                           feedback_port     = 2196                                  :: integer(),  
  17.                           feedback_fun      = fun erlang:display/1                  :: fun((string()) -> _),  
  18.                           feedback_timeout  = 30*60*1000                            :: pos_integer()  
  19.                           }).  
  20. -record(apns_msg, {id = apns:message_id()       :: binary(),  
  21.                    expiry = apns:expiry(86400)  :: non_neg_integer(), %% default = 1 day  
  22.                    device_token                 :: string(),  
  23.                    alert = none                 :: none | apns:alert(),  
  24.                    badge = none                 :: none | integer(),  
  25.                    sound = none                 :: none | string(),  
  26.                    extra = []                   :: [apns_mochijson2:json_property()]}).  
  27. -record(loc_alert, {body    = none  :: none | string(),  
  28.                     action  = none  :: none | string(),  
  29.                     key     = ""    :: string(),  
  30.                     args    = []    :: [string()],  
  31.                     image   = none  :: none | string()}).  
  32.   
  33.   
  34.          push_token/1]).  
  35. get_pid() ->  
  36.     {ok, Pid} = apns:connect(),  
  37.     Pid.  
  38. delete_pid(ConnId) ->  
  39.     apns:disconnect(ConnId).  
  40.   
  41. push_by_pid(ConnId, Token1) ->  
  42.      Alert1 = #apns_msg{device_token = Token1,  
  43.                        badge = 9,  
  44.                        sound = "bingbong.aiff",  
  45.                        %extra = [{"jump","yes"}],  
  46.                        extra = [{jump, yes}],  
  47.                        alert = #loc_alert{body="hello1"  
  48.                                         }},  
  49.     io:format("In ~p:appns_packet ~p Alert1 = ~p ~n", [?MODULE, ?LINE, Alert1]),  
  50.     apns:send_message(ConnId, Alert1).  
  51.   
  52.   
  53. -spec push(DeviceToken :: string(), Alert :: tuple()) -> ok.  
  54. push(DeviceToken, Alert)->  
  55.     Conn = apns:connect(),  
  56.     case Conn of  
  57.         {ok,ConnId} ->  
  58.             Res = apns:send_message(ConnId, DeviceToken, Alert),  
  59.             Res1 = apns:send_message(ConnId, DeviceToken, Alert),  
  60.             case Res of  
  61.                 ok ->  
  62.                     ok;  
  63.                 Err ->  
  64.                     Err  
  65.             end,  
  66.             apns:disconnect(ConnId);  
  67.         Err ->  
  68.             Err  
  69.     end.  
  1 #!/bin/sh
  2 
  3 #Usage:
  4 #test_certs {cert_file} {private_key_file}
  5 #Example:
  6 #test_certs aps_developer_indetity.cer aps_developer_identity.p12
  7 mkdir -p ./temp                                                             
  8 openssl pkcs12 -in "$2" -out ./temp/key-enc.pem
  9 openssl rsa -in ./temp/key-enc.pem -out ./temp/key.pem
 10 openssl x509 -inform der -in "$1" -out ./temp/cert.pem
 11 cat ./temp/cert.pem ./temp/key.pem > ./cert.pem

發佈了75 篇原創文章 · 獲贊 2 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章