Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erlang/OTP 18? #164

Closed
cwmaguire opened this issue Apr 19, 2017 · 13 comments
Closed

Erlang/OTP 18? #164

cwmaguire opened this issue Apr 19, 2017 · 13 comments

Comments

@cwmaguire
Copy link

apn4serl compiles under Erlang/OTP 18.2 with a minor changes (as of 25ad9d2). Is there anything else (e.g. ssl) that specifically requires Erlang/OTP 19+? I've got everything coded up for Erlang/OTP 18.2 (large project, hard to upgrade) but I can't connect to the APNS server: I just keep getting a timeout. Before I go any further I'd like to know if our Erlang version is maybe the issue. (I can connect with openssl s_client, but not with apns4erl).

@ferigis
Copy link
Member

ferigis commented Apr 19, 2017

Hi @cwmaguire, I didn't test apns4erl with Erlang 18. If you did the hack and it compiles well I would think your issue could be related with openssl since it needs TLS 1.2+. Even if you connected with s_client, did you try to send something to APNs? Did you get a response from it?

@cwmaguire
Copy link
Author

We have openssl 1.0.2j. I tried doing "GET https://www.howsmyssl.com/a/check HTTP/1.1" and it reported that GET was using TLS 1.2. I haven't tried sending anything with SSL yet. I'll look up how to do that and see if I can successfully send something. Thanks for the tip.

@cwmaguire
Copy link
Author

Okay, I can send a push with curl using a certificate and I get BadDeviceToken, so that's a start!

I'll dig through the SSL traces and see what I can come up with. Thanks for the help.

@cwmaguire
Copy link
Author

I picked up these SSL options from here and I was able to connect.
{honor_cipher_order, false},
{versions, ['tlsv1.2']},
{alpn_preferred_protocols, [<<"h2">>]}

@monkeyfdude
Copy link

monkeyfdude commented May 3, 2017

@cwmaguire where did you these options? I am getting this error #118

Please help me resolve this.

@cwmaguire
Copy link
Author

@monkeyfdude

where did you these options?

I added these options to the TransportOpts list in apns_connection:open_gun_connection/1.

  TransportOpts = case type(Connection) of
  cert ->
    Certfile = certfile(Connection),
    Keyfile = keyfile(Connection),
    [{certfile,Certfile},
     {keyfile,Keyfile},
     {honor_cipher_order, false},
     {versions, ['tlsv1.2']},
     {alpn_preferred_protocols, [<<"h2">>]}];

@cwmaguire
Copy link
Author

@monkeyfdude Note that we're using the new APNS HTTP/2 API. I see from #118 that you're accessing the "legacy" binary SSL API at gateway.sandbox.push.apple.com whereas I'm using api.development.push.apple.com:443 which is the HTTP/2 API.

@ferigis
Copy link
Member

ferigis commented May 5, 2017

Hi @monkeyfdude, since you are trying to update your apns4erl to v2, I recommend you to make some tests first. I mean, download the apns4erl code and play with the console until you achieve push something to APNS and forwarding the messages to your devices. Once you achieve this that implies your certificate and headers are correct, then you can to try to update the library in your ejabberd server.

@monkeyfdude
Copy link

monkeyfdude commented May 5, 2017

I get timeout with following changes:

openssl s_client -connect api.development.push.apple.com:443 
CONNECTED(00000003)
erl -pa _build/default/lib/*/ebin -config test/test.config
Erlang/OTP 18 [erts-7.2.1]
1> apns:start().
ok
2> apns:connect(cert, my_first_connection).
...
{error,timeout}
3> 

Code changes:

  TransportOpts = case type(Connection) of
    cert ->
      Certfile = certfile(Connection),
      Keyfile = keyfile(Connection),
      [{certfile,Certfile},
      {keyfile,Keyfile},
      {honor_cipher_order, false},
      {versions, ['tlsv1.2']},
      {alpn_preferred_protocols, [<<"h2">>]}];
    token ->
      []
  end,

test.config:

[
 {
   apns,
   [ {apple_host,       "api.development.push.apple.com"}
   , {apple_port,       443}
   , {certfile,         "/etc/ejabberd/certs/apns-dev-cert.pem"}
   , {keyfile,          "/etc/ejabberd/certs/apns-dev-key-noenc.pem"}
   , {token_keyfile,    "priv/APNsAuthKey_KEYID12345.p8"}
   , {timeout,          10000}

   %% APNs Headers

   , {apns_id,          undefined}
   , {apns_expiration,  0}
   , {apns_priority,    10}
   , {apns_topic,       "com.example.myapp"}
   , {apns_collapse_id, undefined}

   %% Feedback
   , {feedback_host,    "feedback.push.apple.com"}
   , {feedback_port,    2195}
   ]
 },
 {sasl, [{sasl_error_logger, false}]}
].

@ferigis
Copy link
Member

ferigis commented May 5, 2017

you have to change the data regarding your app. This is not correct

, {apns_id,          undefined}
   , {apns_expiration,  0}
   , {apns_priority,    10}
   , {apns_topic,       "com.example.myapp"}
   , {apns_collapse_id, undefined}

I guess you don't have the app "com.example.myapp" registered in Apple

@ferigis
Copy link
Member

ferigis commented May 5, 2017

did you try to push something without apns4erl? are you sure your certs and http2 headers are correct?

@monkeyfdude
Copy link

monkeyfdude commented May 5, 2017

@ferigis You may be right. Let me investigate.

Please keep an eye on this issue. I will keep updating as I investigate.

@monkeyfdude
Copy link

monkeyfdude commented May 5, 2017

I was able to connect & send atleast 1 notification successfully. Thanks for all your help.

I have other issues. I am opening a new issue #169

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants