本文介绍了iOS推送通知-JavaPNS-keystore.p12文件安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Apple的Push Notifications.我在这里使用本教程: http://www.ibm.com/developerworks /java/library/mo-ios-push/#ibm-pcon

I am trying to use Apple's Push Notifications. I am using this tutorial here:http://www.ibm.com/developerworks/java/library/mo-ios-push/#ibm-pcon

我正在尝试创建推送通知.示例代码在这里: http://code.google.com/p/javapns/wiki/PushNotificationBasic,看起来像这样:

I am on the part where I am trying to create the Push Notification. The sample code is here:http://code.google.com/p/javapns/wiki/PushNotificationBasic and looks like this:

import javapns.Push;

public class PushTest {

   public static void main(String[] args) {

            Push.alert("Hello World!", "keystore.p12", "keystore_password", false, "Your token");


   }
}

除了keystore.p12部分之外,我已经进行了所有设置.这是文档中有关密钥库的内容:

I have everything set up except for the keystore.p12 part. Here is what the documentation says about keystores:

对象密钥库:对密钥库文件或实际密钥库内容的引用.请参阅准备证书,以获取有关如何创建密钥库的更多信息.您可以将以下对象传递给此参数:

Object keystore: a reference to a keystore file, or the actual keystore content. See Preparing certificates for more information about how to create a keystore. You can pass the following objects to this parameter:

  • java.io.File:指向密钥库文件的直接指针
  • java.lang.String:本地密钥库文件的路径
  • java.io.InputStream:提供密钥库中字节的流
  • byte []:密钥库的实际字节
  • java.security.KeyStore:实际加载的密钥库

我不只是想在我的计算机上键入密钥库的路径(就像他们在这里使用Java-PNS向iPhone发送推送通知时收到错误消息?),因为我觉得那是不安全的.

I do not simply want to type in the path of the keystore on my computer (as they do here Getting error while sending Push Notification to iPhone using Java-PNS?) because I feel like that is unsafe.

我应该使用哪些对象?我倾向于使用java.security.KeyStore.

Which of the objects should I use? My inclination says to use a java.security.KeyStore.

最后一点,此代码需要托管在Amazon Web Service的Elastic Beanstalk上(如果重要的话).

As a final note, this code needs to be hosted on Amazon Web Service's Elastic Beanstalk (if that matters).

---------编辑1 ------------

我试图输入Richard J. Ross III的代码.但是在可以了解我的.p12文件设置是否正确之前,我首先需要解决关于JavaPNS(和我相信的文件结构)的问题.运行下面的代码给我这个错误:HTTP Status 404 - Servlet IosSendGameServlet is not available.当我注释掉所有JavaPNS语句时,出现以下错误:HTTP Status 500 - javax.servlet.ServletException: Parameter recievingAppleDeviceID not found.(因为我没有输入参数),这使我相信访问JavaPNS的方式存在问题.也许它在我的文件结构中的错误位置?它与servlet-api(在lib中)在同一位置.也许这是我上传到AWS Elastic Beanstalk服务器的方式有问题吗?

I have tried to put in Richard J. Ross III's code. But before it is possible to learn if my .p12 file setup is correct, I first need to get around an issue concerning JavaPNS (and file structure I believe). Running the code below gives me this error: HTTP Status 404 - Servlet IosSendGameServlet is not available. When I comment out all of the JavaPNS statements, I get this error: HTTP Status 500 - javax.servlet.ServletException: Parameter recievingAppleDeviceID not found. (because I don't put in the parameters) This leads me to believe that there is a problem with the way that JavaPNS is being accessed. Maybe it is in the wrong place in my file structure? It is in the same place as servlet-api (in lib). Perhaps this is a problem with the way I upload to the AWS Elastic Beanstalk server?

package com.google.android.gcm.demo.server;

import java.io.IOException;
import java.io.InputStream;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javapns.Push; //<--gets commented out to receive 500 error
import javapns.communication.exceptions.CommunicationException;//<--gets commented out to receive 500 error
import javapns.communication.exceptions.KeystoreException;//<--gets commented out to receive 500 error

public class IosSendGameServlet extends BaseServlet {

    @Override
    public void init(ServletConfig config) throws ServletException {
            super.init(config);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException,
                    ServletException {
            String recievingAppleDeviceId = getParameter(req,
                            "recievingAppleDeviceID");
            String sendingUser = getParameter(req, "sendingUser");
            InputStream keyStore = this.getClass().getResourceAsStream("/sasSandbox.p12");

            //everything below here gets commented out to receive 500 error
            try {
                    Push.alert("Game with " + sendingUser + ": It's your turn!", keyStore, "mypassword", false,
                                    recievingAppleDeviceId);
            } catch (CommunicationException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
            } catch (KeystoreException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
            }

    }
}

推荐答案

您应使用InputStream,并将.p12文件放在类路径中,并按以下方式使用:

You should use an InputStream, and have the .p12 file in your classpath, and use like this:

InputStream keyStore = this.getClass().getResourceAsStream("nameOfMyKeystore.p12");

这篇关于iOS推送通知-JavaPNS-keystore.p12文件安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 13:03