📄 rsasignsessionbean.java
字号:
} /** * Gets connection to log session bean */ private ILogSessionLocal getLogSession() { if (logsession == null) { try { ILogSessionLocalHome logsessionhome = (ILogSessionLocalHome) getLocator().getLocalHome(ILogSessionLocalHome.COMP_NAME); logsession = logsessionhome.create(); } catch (Exception e) { throw new EJBException(e); } } 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); } 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) { error("Unknown error, strange?", 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); } // 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); throw new CADoesntExistsException("Signing CA " + cadata.getSubjectDN() + " has expired"); } 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 { debug(">createCertificate(pk)"); // Default key usage is defined in certificate profiles debug("<createCertificate(pk)"); 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, SecConst.PROFILE_NO_PROFILE, SecConst.CAID_USEUSERDEFINED); } /** * Requests for a certificate to be created for the passed public key with the passed key * usage and using the given certificate profile. This method is primarily intended to be used when * issueing hardtokens having multiple certificates per user. * 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 certificateprofileid used to override the one set in userdata. * Should be set to SecConst.PROFILE_NO_PROFILE if the usedata certificateprofileid should be used * @param caid used to override the one set in userdata.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -