8

我正在尝试通过 Google Cloud Message 服务器向 Android 设备发送推送通知。

我们用来执行此操作的 URL 是:

https://android.googleapis.com/gcm/send

在我们的企业应用程序中,我们不使用默认的 CA 权限,并且出于安全原因,我们在 SSLContext 属性加载的信任库文件中手动添加我们信任的每个实体。我想将 GCM 证书添加到我们的信任库。

我不知道如何从该 URL 获取证书。由于页面重定向到另一个非 SSL 页面,因此 Chrome/Firefox 导出方式似乎不起作用。

有人有解决方案吗?

4

3 回答 3

14

我已经能够通过以下 Java 代码保存证书:

public void testConnectionTo(String aURL) throws Exception {
        URL destinationURL = new URL(aURL);
        HttpsURLConnection conn = (HttpsURLConnection) destinationURL.openConnection();
        conn.connect();
        Certificate[] certs = conn.getServerCertificates();
        System.out.println("nb = " + certs.length);
        int i = 1;
        for (Certificate cert : certs) {
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("################################################################");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("Certificate is: " + cert);
            if(cert instanceof X509Certificate) {
                try {
                    ( (X509Certificate) cert).checkValidity();
                    System.out.println("Certificate is active for current date");
                    FileOutputStream os = new FileOutputStream("/home/sebastien/Bureau/myCert"+i);
                    i++;
                    os.write(cert.getEncoded());
                } catch(CertificateExpiredException cee) {
                    System.out.println("Certificate is expired");
                }
            } else {
                System.err.println("Unknown certificate type: " + cert);
            }
        }
    }

并将它们导入到信任库:

keytool -import -alias GoogleInternetAuthority -file myCert1 -keystore truststore
于 2012-09-21T10:48:45.013 回答
11

如果你有 openssl 你可以使用

openssl s_client -connect android.googleapis.com:443

s_client是“使用 SSL/TLS 连接到远程主机的通用 SSL/TLS 客户端”,除其他外,它打印出从远程服务器接收到的服务器证书。它不是 HTTP 客户端,因此它不知道遵循 301 重定向,它只会为您提供您连接的初始服务器的证书。

于 2012-09-21T10:12:02.150 回答
3

使用Portecle。您可以打开目标密钥库,然后使用Examine> Examine SSL/TLS Connection,输入android.googleapis.com443然后您就完成了!

于 2012-09-21T10:42:52.133 回答