📄 rsasignsessionbean.java
字号:
return logsession; } //getLogSession /** * Retrieves the certificate chain for the signer. The returned certificate chain MUST have the * RootCA certificate in the last position. * * @param admin Information about the administrator or admin preforming the event. * @param caid is the issuerdn.hashCode() * @return The certificate chain, never null. * @ejb.permission unchecked="true" * @ejb.transaction type="Supports" * @ejb.interface-method view-type="both" */ public Collection getCertificateChain(Admin admin, int caid) { // get CA CADataLocal cadata = null; try { cadata = cadatahome.findByPrimaryKey(new Integer(caid)); } catch (javax.ejb.FinderException fe) { throw new EJBException(fe); } CA ca = null; try { ca = cadata.getCA(); } catch (java.io.UnsupportedEncodingException uee) { throw new EJBException(uee); } catch(IllegalKeyStoreException e){ throw new EJBException(e); } return ca.getCertificateChain(); } // getCertificateChain /** * Creates a signed PKCS7 message containing the whole certificate chain, including the * provided client certificate. * * @param admin Information about the administrator or admin preforming the event. * @param cert client certificate which we want encapsulated in a PKCS7 together with * certificate chain. * @return The DER-encoded PKCS7 message. * @throws CADoesntExistsException if the CA does not exist or is expired, or has an invalid cert * @throws SignRequestSignatureException if the certificate is not signed by the CA * @ejb.interface-method view-type="both" */ public byte[] createPKCS7(Admin admin, Certificate cert, boolean includeChain) throws CADoesntExistsException, SignRequestSignatureException { Integer caid = new Integer(CertTools.getIssuerDN((X509Certificate) cert).hashCode()); return createPKCS7(caid.intValue(), cert, includeChain); } // createPKCS7 /** * Creates a signed PKCS7 message containing the whole certificate chain of the specified CA. * * @param admin Information about the administrator or admin preforming the event. * @param caId CA for which we want a PKCS7 certificate chain. * @return The DER-encoded PKCS7 message. * @throws CADoesntExistsException if the CA does not exist or is expired, or has an invalid cert * @ejb.interface-method view-type="both" */ public byte[] createPKCS7(Admin admin, int caId, boolean includeChain) throws CADoesntExistsException { try { return createPKCS7(caId, null, includeChain); } catch (SignRequestSignatureException e) { String msg = intres.getLocalizedMessage("error.unknown"); error(msg, e); throw new EJBException(e); } } // createPKCS7 /** * Internal helper method * * @param admin Information about the administrator or admin preforming the event. * @param caId CA for which we want a PKCS7 certificate chain. * @param cert client certificate which we want ancapsulated in a PKCS7 together with * certificate chain, or null * @return The DER-encoded PKCS7 message. * @throws CADoesntExistsException if the CA does not exist or is expired, or has an invalid cert */ private byte[] createPKCS7(int caId, Certificate cert, boolean includeChain) throws CADoesntExistsException, SignRequestSignatureException { debug(">createPKCS7(" + caId + ", " + CertTools.getIssuerDN((X509Certificate) cert) + ")"); byte[] returnval = null; // get CA CADataLocal cadata = null; try { cadata = cadatahome.findByPrimaryKey(new Integer(caId)); } catch (javax.ejb.FinderException fe) { throw new CADoesntExistsException(fe); } CA ca = null; try { ca = cadata.getCA(); } catch (java.io.UnsupportedEncodingException uee) { throw new CADoesntExistsException(uee); } catch(IllegalKeyStoreException e){ throw new EJBException(e); } // Check that CA hasn't expired. X509Certificate cacert = (X509Certificate) ca.getCACertificate(); try { cacert.checkValidity(); } catch (CertificateExpiredException e) { // Signers Certificate has expired. cadata.setStatus(SecConst.CA_EXPIRED); ca.setStatus(SecConst.CA_EXPIRED); String msg = intres.getLocalizedMessage("signsession.caexpired", cadata.getSubjectDN()); throw new CADoesntExistsException(msg); } catch (CertificateNotYetValidException cve) { throw new CADoesntExistsException(cve); } returnval = ca.createPKCS7(cert, includeChain); debug("<createPKCS7()"); return returnval; } // createPKCS7 /** * Requests for a certificate to be created for the passed public key with default key usage * The method queries the user database for authorization of the user. * * @param admin Information about the administrator or admin preforming the event. * @param username unique username within the instance. * @param password password for the user. * @param pk the public key to be put in the created certificate. * @return The newly created certificate or null. * @throws ObjectNotFoundException if the user does not exist. * @throws AuthStatusException If the users status is incorrect. * @throws AuthLoginException If the password is incorrect. * @throws IllegalKeyException if the public key is of wrong type. * @ejb.permission unchecked="true" * @ejb.interface-method view-type="both" */ public Certificate createCertificate(Admin admin, String username, String password, PublicKey pk) throws ObjectNotFoundException, AuthStatusException, AuthLoginException, IllegalKeyException, CADoesntExistsException { // Default key usage is defined in certificate profiles return createCertificate(admin, username, password, pk, -1); } // createCertificate /** * Requests for a certificate to be created for the passed public key with the passed key * usage. The method queries the user database for authorization of the user. CAs are only * allowed to have certificateSign and CRLSign set. * * @param admin Information about the administrator or admin preforming the event. * @param username unique username within the instance. * @param password password for the user. * @param pk the public key to be put in the created certificate. * @param keyusage integer with mask describing desired key usage in format specified by * X509Certificate.getKeyUsage(). id-ce-keyUsage OBJECT IDENTIFIER ::= { id-ce 15 } * KeyUsage ::= BIT STRING { digitalSignature (0), nonRepudiation (1), * keyEncipherment (2), dataEncipherment (3), keyAgreement (4), * keyCertSign (5), cRLSign (6), encipherOnly (7), * decipherOnly (8) } * @return The newly created certificate or null. * @throws ObjectNotFoundException if the user does not exist. * @throws AuthStatusException If the users status is incorrect. * @throws AuthLoginException If the password is incorrect. * @throws IllegalKeyException if the public key is of wrong type. * @ejb.permission unchecked="true" * @ejb.interface-method view-type="both" */ public Certificate createCertificate(Admin admin, String username, String password, PublicKey pk, boolean[] keyusage) throws ObjectNotFoundException, AuthStatusException, AuthLoginException, IllegalKeyException, CADoesntExistsException { return createCertificate(admin, username, password, pk, CertTools.sunKeyUsageToBC(keyusage)); } /** * Requests for a certificate to be created for the passed public key with the passed key * usage. The method queries the user database for authorization of the user. CAs are only * allowed to have certificateSign and CRLSign set. * * @param admin Information about the administrator or admin preforming the event. * @param username unique username within the instance. * @param password password for the user. * @param pk the public key to be put in the created certificate. * @param keyusage integer with bit mask describing desired keys usage, overrides keyUsage from * CertificateProfiles if allowed. Bit mask is packed in in integer using constants * from CertificateData. -1 means use default keyUsage from CertificateProfile. ex. int * keyusage = CertificateData.digitalSignature | CertificateData.nonRepudiation; gives * digitalSignature and nonRepudiation. ex. int keyusage = CertificateData.keyCertSign * | CertificateData.cRLSign; gives keyCertSign and cRLSign * @return The newly created certificate or null. * @throws ObjectNotFoundException if the user does not exist. * @throws AuthStatusException If the users status is incorrect. * @throws AuthLoginException If the password is incorrect. * @throws IllegalKeyException if the public key is of wrong type. * @ejb.permission unchecked="true" * @ejb.interface-method view-type="both" */ public Certificate createCertificate(Admin admin, String username, String password, PublicKey pk, int keyusage) throws ObjectNotFoundException, AuthStatusException, AuthLoginException, IllegalKeyException, CADoesntExistsException { return createCertificate(admin, username, password, pk, keyusage, null, null, SecConst.PROFILE_NO_PROFILE, SecConst.CAID_USEUSERDEFINED); } /** * Requests for a certificate to be created for the passed public key with the passed key * usage. The method queries the user database for authorization of the user. CAs are only * allowed to have certificateSign and CRLSign set. * * @param admin Information about the administrator or admin preforming the event. * @param username unique username within the instance. * @param password password for the user. * @param pk the public key to be put in the created certificate. * @param keyusage integer with bit mask describing desired keys usage, overrides keyUsage from * CertificateProfiles if allowed. Bit mask is packed in in integer using constants * from CertificateData. -1 means use default keyUsage from CertificateProfile. ex. int * keyusage = CertificateData.digitalSignature | CertificateData.nonRepudiation; gives * digitalSignature and nonRepudiation. ex. int keyusage = CertificateData.keyCertSign * | CertificateData.cRLSign; gives keyCertSign and cRLSign * @param notAfter an optional validity to set in the created certificate, if the profile allows validity override, null if the profiles default validity should be used. * @return The newly created certificate or null. * @throws ObjectNotFoundException if the user does not exist. * @throws AuthStatusException If the users status is incorrect. * @throws AuthLoginException If the password is incorrect. * @throws IllegalKeyException if the public key is of wrong type. * @ejb.permission unchecked="true" * @ejb.interface-method view-type="both" */ public Certificate createCertificate(Admin admin, String username, String password, PublicKey pk, int keyusage, Date notBefore, Date notAfter) throws ObjectNotFoundException, AuthStatusException, AuthLoginException, IllegalKeyException, CADoesntExistsException { return createCertificate(admin, username, password, pk, keyusage, notBefore, notAfter, SecConst.PROFILE_NO_PROFILE, SecConst.CAID_USEUSERDEFINED); } /** * Requests for a certificate of the specified type to be created for the passed public key. * The method queries the user database for authorization of the user. * * @param admin Information about the administrator or admin preforming the event. * @param username unique username within the instance. * @param password password for the user. * @param certType integer type of certificate taken from CertificateData.CERT_TYPE_XXX. the * type CertificateData.CERT_TYPE_ENCRYPTION gives keyUsage keyEncipherment, * dataEncipherment. the type CertificateData.CERT_TYPE_SIGNATURE gives keyUsage * digitalSignature, non-repudiation. all other CERT_TYPES gives the default keyUsage * digitalSignature, keyEncipherment * @param pk the public key to be put in the created certificate. * @return The newly created certificate or null. * @throws ObjectNotFoundException if the user does not exist. * @throws AuthStatusException If the users status is incorrect.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -