登录
首页 >  Golang >  Go问答

Heroku 丢失 GeoTrust Global CA 根证书

来源:stackoverflow

时间:2024-03-04 11:36:18 321浏览 收藏

各位小伙伴们,大家好呀!看看今天我又给各位带来了什么文章?本文标题《Heroku 丢失 GeoTrust Global CA 根证书》,很明显是关于Golang的文章哈哈哈,其中内容主要会涉及到等等,如果能帮到你,觉得很不错的话,欢迎各位多多点评和分享!

问题内容

Heroku 不知何故丢失了其 GeoTrust Global CA 根证书,这是在 Apple 服务器上使用推送通知所必需的。我在这里找到了证书,但我不确定如何将其安装在我的 Heroku 应用程序中。我尝试通过应用程序的设置将其添加为 SSL 证书,但它说我需要私钥 - 我在哪里可以获得根证书?或者我应该将其添加到其他地方吗?

我应该指定我的应用程序是 golang 应用程序。


解决方案


我重新定义了 sideshow/apns2 客户端工厂函数,将 geotrust ca 包含在 rootca 中,并且我在 heroku 上的应用程序可以访问苹果的 apns 服务器。

const (
    GeoTrustCACert = ""
)

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,
    }

}

好了,本文到此结束,带大家了解了《Heroku 丢失 GeoTrust Global CA 根证书》,希望本文对你有所帮助!关注golang学习网公众号,给大家分享更多Golang知识!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>