Extract bundle-id from certificate
macteo opened this issue · 4 comments
I've noticed that you can extract the bundle-id from the certificate and put it into the Headers as Topic (it seems to be required), so you can avoid asking for it.
cert, err := certificate.Load(filename, passphrase)
if err != nil {
log.Fatal(err)
}
commonName := cert.Leaf.Subject.CommonName
bundle := strings.Replace(commonName, "Apple Push Services: ", "", 1)
headers := &push.Headers{
Topic: bundle,
}
That's a great tip. Thanks Matteo!
What do you think of adding a field to push.Service for the Topic and a NewService constructor function to extract it? I'd probably remove Topic from push.Headers when updating PushBytes to use service.Topic instead. The API can still change until we call it 1.0.
I haven't needed to specify a Topic yet. The Apple docs say it's required for certificates with multiple topics. It would be good to do some testing to see if a change like this would end up specifying a header unnecessarily in some cases.
I used buford for a single app and using a single SSL certificate for both production and development and if I don't specify the topic it refuses to work, so I tried to extract it from the certificate itself as in my certificate there's only one. I really don't know how you can create a certificate with more than one bundle-id, but if that's the case, the suggested method can fail. The NewService constructor function to extract the bundle-id seems a good fit as API.
I don't quite understand this whole Topic thing. Nor why you needed to specify it whereas I didn't.
The library certificate.Load
depends on will fail if multiple certificates are present in the .p12 (golang/go#14015), so that's not a concern. If Topic is the CommonName, I also don't see how there could be more than one.
Me too.