adobkin / libcapn

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

Problem with SSL #28

Open ivan-ushakov opened 8 years ago

ivan-ushakov commented 8 years ago

I faced with strange problem. As I understand current version of library uses TLS and it must work with APN servers without any problem. When I try to send several push notifications I'm always getting same behaviour: first notification was sent without any problem but next notification produce SSL error when read from socket.

Here is log with some additional output (I added error string from OpenSSL):

[INFO]: Connecting to gateway.sandbox.push.apple.com:2195...
[DEBUG]: Resolving server hostname...
[DEBUG]: Creating socket...
[DEBUG]: Socket successfully created
[INFO]: Trying to connect to x.x.x.x...
[INFO]: Connection has been established
[INFO]: Initializing SSL connection...
[INFO]: Certificate subject: UID=xxx, CN=VoIP Services: xxx, OU=xxx, O=xxx, C=US
[INFO]: Certificate issuer: C=US, O=Apple Inc., OU=Apple Worldwide Developer Relations, CN=Apple Worldwide Developer Relations Certification Authority
[INFO]: Certificate mode: PRODUCTION & SANDBOX (UNIVERSAL) (6)
[INFO]: Certificate expires at xxx
[INFO]: ssl: handshake started write:before/connect initialization:unknown
[INFO]: ssl: connect:before/connect initialization:(NONE)
[INFO]: ssl: connect:unknown state:(NONE)
[INFO]: ssl: connect:unknown state:AES256-SHA
[INFO]: ssl: handshake done write:SSL negotiation finished successfully:unknown
[INFO]: ssl: connect:SSL negotiation finished successfully
[INFO]: SSL connection has been established

[INFO]: Creating binary message from payload...
[INFO]: Binary message sucessfully created
[INFO]: Sending notification to 1 device(s)...
[INFO]: Sending notificaton to device with token xxx...
[DEBUG]: select() returned 1
[DEBUG]: Socket is ready for writing
[DEBUG]: 85 byte(s) has been written to a socket
[INFO]: Notification has been sent
[DEBUG]: select() returned 0

[INFO]: Creating binary message from payload...
[INFO]: Binary message sucessfully created
[INFO]: Sending notification to 1 device(s)...
[INFO]: Sending notificaton to device with token xxx...
[DEBUG]: select() returned 1
[DEBUG]: Socket is ready for writing
[DEBUG]: 85 byte(s) has been written to a socket
[INFO]: Notification has been sent
[DEBUG]: select() returned 1
[DEBUG]: Socket has data for read
[DEBUG]: Reading data from a socket...
[INFO]: ssl: alert read:SSL negotiation finished successfully
[ERROR]: Could not read from SSL socket: 1
[ERROR]: Could not read from SSL socket: 140145599305368:error:140943FC:SSL routines:ssl3_read_bytes:sslv3 alert bad record mac:s3_pkt.c:1472:SSL alert number 20
[ERROR]: Unable to read data from a socket: SSL_read failed (errno: 9016)
[ERROR]: Could not send notification: SSL_read failed (errno: 9016)

Looks like it uses SSLv3 instead of TLS but it is just my thoughts. Any idea why this happen?