iOS推送javaPNS源码解析四,证书管理类

来源:互联网 发布:linux mmap使用 编辑:程序博客网 时间:2024/05/22 13:47

证书管理类KeystoreManager

顾名思义该类用来管理推送证书的,主要作用是解析证书到适合的格式,比如InputStream流。

private static final String REVIEW_MESSAGE = ” Please review the procedure for generating a keystore for JavaPNS.”;验证证书错误提示语句

 static KeyStore loadKeystore(AppleServer server) throws KeystoreException { 通过服务器获取证书对象
        return loadKeystore(server, server.getKeystoreStream());
    }
    static KeyStore loadKeystore(AppleServer server, Object keystore) throws KeystoreException {
        return loadKeystore(server, keystore, false);通过服务器和证书对象获取证书对象
    }

上边两个方法的具体实现

public static KeyStore loadKeystore(AppleServer server, Object keystore, boolean verifyKeystore) throws KeystoreException {

//如果已经是keyStore,那么直接返回
        if (keystore instanceof KeyStore) {
            return (KeyStore) keystore;
        }

//锁定服务器,好处此服务器不会被其他线程篡改
        synchronized (server) {
            //将KeyStore转化为InputStream
            InputStream keystoreStream = streamKeystore(keystore);
            if (keystoreStream instanceof WrappedKeystore) {
                return ((WrappedKeystore) keystoreStream).getKeystore();
            }
            KeyStore keyStore;
            try {
                keyStore = KeyStore.getInstance(server.getKeystoreType());//根据服务器证书类型新建keyStore
                char[] password = KeystoreManager.getKeystorePasswordForSSL(server);
                keyStore.load(keystoreStream, password);//加载keyStore
            } catch (Exception e) {
                throw wrapKeystoreException(e);
            } finally {
                try {
                    keystoreStream.close();
                } catch (Exception e) {}
            }
            return keyStore;
        }
    }

static Object ensureReusableKeystore(AppleServer server, Object keystore) throws KeystoreException,该方法表示证书是否能够重复使用

public static void verifyKeystoreContent(AppleServer server, Object keystore) throws KeystoreException ,加载证书内容并校验是否为苹果服务器证书
public static void verifyKeystoreContent(KeyStore keystore) throws KeystoreException,解析证书信息,判断是否为苹果证书
static char[] getKeystorePasswordForSSL(AppleServer server)获取服务器中证书密码

static KeystoreException wrapKeystoreException(Exception e) 装饰keyStore异常信息。

static InputStream streamKeystore(Object keystore) throws InvalidKeystoreReferenceException,获取InputStream格式的证书格式

public static void validateKeystoreParameter(Object keystore) throws InvalidKeystoreReferenceException,校验传入的证书参数是否有效

原创粉丝点击