⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sceprequestmessage.java

📁 一个免费的CA,基于EJB平台的,老师叫我们测试,现把之共享出来让大家参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /**     * Returns the public key from the certificattion request.     *     * @return public key from certification request.     */    public PublicKey getRequestPublicKey() {        log.debug(">getRequestPublicKey()");        PublicKey ret = null;        try {            if (envData == null) {                init();                decrypt();            }            ret = super.getRequestPublicKey();        } catch (IOException e) {            log.error("PKCS7 not inited!");        } catch (GeneralSecurityException e) {            log.error("Error in PKCS7:", e);        } catch (CMSException e) {            log.error("Error in PKCS7:", e);        }        log.debug("<getRequestPublicKey()");        return ret;    }    /**     * Verifies signatures, popo etc on the request message. If verification fails the request     * should be considered invalid.     *     * @return True if verification was successful, false if it failed.     *     * @throws InvalidKeyException If the key used for verification is invalid.     * @throws NoSuchProviderException if there is an error with the Provider.     * @throws NoSuchAlgorithmException if the signature on the request is done with an unhandled     *         algorithm.     */    public boolean verify() {        log.debug(">verify()");        boolean ret = false;        try {            if (pkcs10 == null) {                init();                decrypt();            }            ret = super.verify();        } catch (IOException e) {            log.error("PKCS7 not inited!");        } catch (GeneralSecurityException e) {            log.error("Error in PKCS7:", e);        } catch (CMSException e) {            log.error("Error in PKCS7:", e);        }        log.debug("<verify()");        return ret;    }    /**     * Returns the challenge password from the certificattion request.     *     * @return challenge password from certification request.     */    public String getPassword() {        log.debug(">getPassword()");        String ret = null;        try {            if (pkcs10 == null) {                init();                decrypt();            }            ret = super.getPassword();        } catch (IOException e) {            log.error("PKCS7 not inited!");        } catch (GeneralSecurityException e) {            log.error("Error in PKCS7:", e);        } catch (CMSException e) {            log.error("Error in PKCS7:", e);        }        log.debug("<getPassword()");        return ret;    }    /**     * Returns the string representation of the CN field from the DN of the certification request,     * to be used as username.     *     * @return username, which is the CN field from the subject DN in certification request.     */    public String getUsername() {        log.debug(">getUsername()");        String ret = null;        try {            if (pkcs10 == null) {                init();                decrypt();            }            ret = super.getUsername();            if (ret == null) {                // For Cisco boxes they can sometimes send DN as SN instead of CN                String name = CertTools.getPartFromDN(getRequestDN(), "SN");                if (name == null) {                    log.error("No SN in DN: "+getRequestDN());                    return null;                }                // Special if the DN contains unstructuredAddress where it becomes:                 // SN=1728668 + 1.2.840.113549.1.9.2=pix.primekey.se                // We only want the SN and not the oid-part.                int index = name.indexOf(' ');                ret = name;                 if (index > 0) {                    ret = name.substring(0,index);                        } else {                    // Perhaps there is no space, only +                    index = name.indexOf('+');                    if (index > 0) {                        ret = name.substring(0, index);                    }            	                }            }        } catch (IOException e) {            log.error("PKCS7 not inited!");        } catch (GeneralSecurityException e) {            log.error("Error in PKCS7:", e);        } catch (CMSException e) {            log.error("Error in PKCS7:", e);        }        log.debug("<getUsername(): " + ret);        return ret;    }    /**     * Gets the issuer DN if contained in the request (the CA the request is targeted at).     *     * @return issuerDN of receiving CA or null.     */    public String getIssuerDN() {        log.debug(">getIssuerDN()");        String ret = null;        try {            if (envData == null) {                init();            }            ret = issuerDN;        } catch (IOException e) {            log.error("PKCS7 not inited!");        }        log.debug("<getIssuerDN(): " + ret);        return ret;    }    /**     * Gets the issuer DN if contained in the request (the CA the request is targeted at).     *     * @return issuerDN of receiving CA or null.     */    public BigInteger getSerialNo() {        log.debug(">getSerialNo()");        // Use another method to do the decryption etc...        getIssuerDN();        return serialNo;    }        /**     * Gets the issuer DN (of CA cert) from IssuerAndSerialNumber when this is a CRL request.     *     * @return issuerDN of CA issuing CRL.     */    public String getCRLIssuerDN() {        log.debug(">getCRLIssuerDN()");        String ret = null;        try {            if (issuerAndSerno == null) {                init();                decrypt();            }            ret = CertTools.stringToBCDNString(issuerAndSerno.getName().toString());        } catch (IOException e) {            log.error("PKCS7 not inited!");        } catch (GeneralSecurityException e) {            log.error("Error in PKCS7:", e);        } catch (CMSException e) {            log.error("Error in PKCS7:", e);        }        log.debug("<getCRLIssuerDN(): " + ret);        return ret;    }    /**     * Gets the number (of CA cert) from IssuerAndSerialNumber when this is a CRL request.     *     * @return serial number of CA certificate for CA issuing CRL.     */    public BigInteger getCRLSerialNo() {        log.debug(">getCRLSerialNo()");        BigInteger ret = null;        try {            if (issuerAndSerno == null) {                init();                decrypt();            }            ret = issuerAndSerno.getSerialNumber().getValue();        } catch (IOException e) {            log.error("PKCS7 not inited!");        } catch (GeneralSecurityException e) {            log.error("Error in PKCS7:", e);        } catch (CMSException e) {            log.error("Error in PKCS7:", e);        }        log.debug("<getCRLSerialNo(): " + ret);        return ret;    }    /**     * Returns the string representation of the subject DN from the certification request.     *     * @return subject DN from certification request.     */    public String getRequestDN() {        log.debug(">getRequestDN()");        String ret = null;        try {            if (pkcs10 == null) {                init();                decrypt();            }            ret = super.getRequestDN();        } catch (IOException e) {            log.error("PKCS7 not inited!");        } catch (GeneralSecurityException e) {            log.error("Error in PKCS7:", e);        } catch (CMSException e) {            log.error("Error in PKCS7:", e);        }        log.debug("<getRequestDN(): " + ret);        return ret;    }    /**     * indicates if this message needs recipients public and private key to verify, decrypt etc. If     * this returns true, setKeyInfo() should be called.     *     * @return True if public and private key is needed.     */    public boolean requireKeyInfo() {        return true;    }    /**     * Sets the public and private key needed to decrypt/verify the message. Must be set if     * requireKeyInfo() returns true.     *     * @param cert certificate containing the public key.     * @param key private key.     * @param provider the provider to use, if the private key is on a HSM you must use a special provider. If null is given, the default BC provider is used.     *     * @see #requireKeyInfo()     */    public void setKeyInfo(X509Certificate cert, PrivateKey key, String provider) {        // We don't need the public key         // this.cert = cert;        this.privateKey = key;        if (provider == null) {        	this.jceProvider = "BC";        } else {            this.jceProvider = provider;        	        }    }    /**     * Returns an error number after an error has occured processing the request     *     * @return class specific error number     */    public int getErrorNo() {        return error;    }    /**     * Returns an error message after an error has occured processing the request     *     * @return class specific error message     */    public String getErrorText() {        return errorText;    }    /**     * Returns a senderNonce if present in the request     *     * @return senderNonce as a string of base64 encoded bytes     */    public String getSenderNonce() {        return senderNonce;    }    /**     * Returns a transaction identifier if present in the request     *     * @return transaction id     */    public String getTransactionId() {        return transactionId;    }    /**     * Returns requesters key info, key id or similar     *     * @return request key info     */    public byte[] getRequestKeyInfo() {        return requestKeyInfo;    }    /** Returns the type of SCEP message it is     *      * @return value as defined by SCEP_TYPE_PKCSREQ, SCEP_TYPE_GETCRL, SCEP_TYPE_GETCERT       */    public int getMessageType() {        return messageType;    }    /** @see org.ejbca.core.protocol.IRequestMessage     */    public String getPreferredDigestAlg() {    	return preferredDigestAlg;    }        /**     * Method returning the certificate used to sign the SCEP_TYPE_PKCSREQ pkcs7 request.     *      * @return The certificate used for signing or null if it doesn't exist or not been initialized.     */    public X509Certificate getSignerCert(){    	return signercert;    }        //    // Private helper methods    ///*    private static boolean checkKeys(PublicKey pubK, PrivateKey privK) {        String in = "TheTopSecretTestString";        byte[] text = in.getBytes();        try {            Cipher cipher1 = Cipher.getInstance("RSA/ECB/PKCS1PADDING", "BC");            cipher1.init(Cipher.ENCRYPT_MODE, pubK);            byte[] textout = cipher1.doFinal(text);            Cipher cipher2 = Cipher.getInstance("RSA/ECB/PKCS1PADDING", "BC");            cipher2.init(Cipher.DECRYPT_MODE, privK);            byte[] out = cipher2.doFinal(textout);            log.debug("out=" + new String(out));            return in.equals(new String(out));        } catch (Exception e) {            return false;        }    } */    } // ScepRequestMessage

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -