I redefined sideshow/apns2 client factory function to include GeoTrust CA in rootCAs and apple`s apns server became reachable to my app on Heroku.
const (
GeoTrustCACert = "<path to GeoTrust_Global_CA.pem>"
)
func newCertPool(certPath string) (*x509.CertPool, error) {
rootCAs, _ := x509.SystemCertPool()
if rootCAs == nil {
rootCAs = x509.NewCertPool()
}
certs, err := ioutil.ReadFile(certPath)
if err != nil {
return nil, errors.New("no certs appended, using system certs only")
}
if ok := rootCAs.AppendCertsFromPEM(certs); !ok {
log.Println("no certs appended, using systems only certs")
}
return rootCAs, nil
}
func NewApns2ClientWithGeoTrustCA(certificate tls.Certificate) *apns2.Client {
rootCas, err := newCertPool(GeoTrustCACert)
if err != nil {
return nil
}
tlsConfig := &tls.Config{
RootCAs: rootCas,
Certificates: []tls.Certificate{certificate},
}
if len(certificate.Certificate) > 0 {
tlsConfig.BuildNameToCertificate()
}
transport := &http2.Transport{
TLSClientConfig: tlsConfig,
DialTLS: apns2.DialTLS,
}
return &apns2.Client{
HTTPClient: &http.Client{
Transport: transport,
Timeout: apns2.HTTPClientTimeout,
},
Certificate: certificate,
Host: apns2.DefaultHost,
}
}