timehop / apns

A Go package to interface with the Apple Push Notification Service
https://godoc.org/github.com/timehop/apns
MIT License
185 stars 47 forks source link

Failed to parse certificate PEM data #45

Closed ynnadkrap closed 9 years ago

ynnadkrap commented 9 years ago

Excuse my ignorance.. I'm new to the iOS world.

I'm getting the error: "crypto/tls: failed to parse certificate PEM data" from this code:

    c, err := apns.NewClient(apns.SandboxGateway, CERT_PEM, KEY_PEM)
    if err != nil {
        println("ERROR!!!!: ", err.Error())
    }

    p := apns.NewPayload()
    p.APS.Alert.Body = content
    badge := 1
    p.APS.Badge = &badge
    p.APS.Sound = "bingbong.aiff"

    m := apns.NewNotification()
    m.Payload = p
    m.DeviceToken = author.PnId
    m.Priority = apns.PriorityImmediate

    c.Send(m)

where CERT_PEM ("devcert.pem") and KEY_PEM ("devkey.pem") are the filenames. The code above is being called from a directory below the files:

    project/
        folder/
            sendAPN.go
        devcert.pem
        devkey.pem

I created the CERT_PEM by using this command:

     openssl x509 -in aps_development.cer -inform der -out devcert.pem

and I created KEY_PEM using this command:

     openssl pkcs12 -nocerts -out devkey.pem -in key.p12

I successfully tested these by using this command:

     openssl s_client -connect gateway.sandbox.push.apple.com:2195 
     -cert devcert.pem -key devkey.pem

What am I doing wrong here? Thanks a bunch for the library.

freeeve commented 9 years ago

Looks like you figured it out (now it's closed). I was also confused by this. The NewClient() constructor takes the actual PEM data in a string, rather than the filename. There's another constructor NewClientWithFiles() that does take the filenames: https://godoc.org/github.com/timehop/apns#NewClientWithFiles

nathany commented 9 years ago

I'm thinking of reducing the number of NewClient* functions and providing more examples. https://github.com/timehop/apns/issues/45