Java

SSL 證書錯誤:certificate_unknown

  • July 24, 2020

我想創建推送通知伺服器,在伺服器中安裝 SSL 證書和 .p12 文件時,我們遇到以下錯誤:我想知道 ssl 證書有什麼問題,因為我收到了 certificate_unknown 錯誤。

main, RECV TLSv1 ALERT:  fatal, certificate_unknown
main, called closeSocket()
main, handling exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: certificate_unknown
Error pushing notification(s):
Invalid certificate chain (Received fatal alert: certificate_unknown)!  Verify that the keystore you provided was produced according to specs...
     at javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:359)
     at javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:301)
     at javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:258)
     at javapns.Push.payload(Push.java:122)
     at javapns.Push.alert(Push.java:36)
     at com.applicationname.pns.PushNotification.main(PushNotification.java:31)

//原始碼

   /**
    * 
    */
   package com.applicationname.pns;

   import org.json.JSONException;

   import javapns.Push;
   import javapns.devices.Device;
   import javapns.notification.Payload;
   import javapns.notification.PushNotificationManager;
   import javapns.notification.PushNotificationPayload;


   public class PushNotification
   {
       private static final String HOST = "gateway.sandbox.push.apple.com";
       private static final int PORT = 2195;
       private static final int BADGE = 66;
       private static String iPhoneId = "5696ee2fa44c61fd21a7987d2b1bcf57faa1603e63cb57ff204b158fb90d28a3";
       private static String certificate = "D:/./trunk/Development/JavaPNS/src/com/applicationname/pns/privateKey.p12";
       private static String passwd = "password@1234";

       /**
        * @param args
        */
       public static void main(String[] args)
       {
           Push.alert("Hello World!", certificate, passwd, false,iPhoneId);

           PushNotificationPayload payLoad = new PushNotificationPayload();

           try
           {
               payLoad.addAlert("Hello World!");
               payLoad.addBadge(10);
           }
           catch (JSONException e)
           {
               // TODO Auto-generated catch block
               e.printStackTrace();
           }

       }


}

將私鑰作為客戶端請求載入到 SSL 套接字是不常見的。我個人認為你應該載入公鑰。私鑰由伺服器端的 SSL 套接字載入。您需要私鑰的唯一原因是充當伺服器並接受來自另一端的連接,但您似乎沒有這樣做。

這可能解釋了“格式錯誤的證書”消息。

在參照:

private static String certificate = "D:/./trunk/Development/JavaPNS/src/com/applicationname/pns/privateKey.p12"

引用自:https://serverfault.com/questions/326216