adobkin / libcapn

A simple C Library for interact with the Apple Push Notification Service (APNs)
MIT License
100 stars 37 forks source link

Unable to establish connection #44

Open AlanMaxwell opened 5 years ago

AlanMaxwell commented 5 years ago

Hello. I tried to use performed example on Ubuntu and Mac OS, but every time I get the same error:

======> Connecting to gateway.sandbox.push.apple.com:2195... ======> Resolving server hostname... ======> Creating socket... ======> Socket successfully created ======> Trying to connect to x.x.x.x... ======> Could not to connect to: Operation now in progress (errno: 36) ======> Trying to connect to x.x.x.x... ======> Could not to connect to: Operation already in progress (errno: 37) ======> Trying to connect to x.x.x.x... ======> Could not to connect to: Operation already in progress (errno: 37) ======> Trying to connect to x.x.x.x... ======> Could not to connect to: Operation already in progress (errno: 37) ======> Trying to connect to x.x.x.x... ======> Could not to connect to: Operation already in progress (errno: 37) ======> Trying to connect to x.x.x.x... ======> Could not to connect to: Operation already in progress (errno: 37) ======> Trying to connect to x.x.x.x... ======> Could not to connect to: Operation already in progress (errno: 37) ======> Trying to connect to x.x.x.x... ======> Could not to connect to: Operation already in progress (errno: 37) ======> Unable to establish connection ======> Connection closing... ======> Connection closed Could not connect to Apple Push Notification Service: unable to establish connection (errno: 9013)

Instead of x.x.x.x are various IPs.

I tried two ways: -p12 file -cert and key .pem files

Tried to use apn-pusher and got the same result.

I tested certificates with the other push-messaging applications and they are working.

What should I do to make it work?

bouzikas commented 4 years ago

Same here. Any workaround?

AlanMaxwell commented 4 years ago

Same here. Any workaround?

Yes. I just decided to use other libraries. Now to send a push notification I send http request via "boost asio" functionality to Firebase service. That for "background push" and "push notification". For sending a VoIP push I configured nghttp2 library and send http2 requests.

bouzikas commented 4 years ago

Funny thing but I found where the problem is. For some reason, if you comment out lines 607 & 608 (610 & 611 for windows) in apn.c: int sock_flags = fcntl(ctx->sock, F_GETFL, 0); fcntl(ctx->sock, F_SETFL, sock_flags | O_NONBLOCK); you got the connection right but there is another issue still (unrelated to flags).

======> Connecting to api.sandbox.push.apple.com:2197... ======> Resolving server hostname... ======> Creating socket... ======> Socket successfully created ======> Trying to connect to x.x.x.x... ======> Connection has been established ======> Initializing SSL connection... ======> Certificate subject: UID=com.XXXXXXXXX, CN=Apple Push Services: com.XXXXXX, OU=XXXXXX, O=XXXXXX., C=US ======> Certificate issuer: C=US, O=Apple Inc., OU=Apple Worldwide Developer Relations, CN=Apple Worldwide Developer Relations Certification Authority ======> Certificate mode: PRODUCTION & SANDBOX (UNIVERSAL) (6) ======> Certificate expires at 2021-08-06 16:04:12 ======> ssl: handshake started write:before SSL initialization:unknown ======> ssl: connect:before SSL initialization:(NONE) ======> ssl: connect:SSLv3/TLS write client hello:(NONE) ======> ssl: alert read:SSLv3/TLS write client hello ======> ssl: connect:error ======> Could not initialize SSL connection: SSL_connect() failed: error:00000001:lib(0):func(0):reason(1), Undefined error: 0 (errno: 0):

Is anyone has the same issue?