1 13 14 package org.ejbca.core.ejb.ca.sign; 15 16 import java.io.IOException ; 17 import java.io.UnsupportedEncodingException ; 18 import java.math.BigInteger ; 19 import java.security.InvalidKeyException ; 20 import java.security.NoSuchAlgorithmException ; 21 import java.security.NoSuchProviderException ; 22 import java.security.PublicKey ; 23 import java.security.SecureRandom ; 24 import java.security.cert.CRLException ; 25 import java.security.cert.Certificate ; 26 import java.security.cert.CertificateExpiredException ; 27 import java.security.cert.CertificateNotYetValidException ; 28 import java.security.cert.X509CRL ; 29 import java.security.cert.X509Certificate ; 30 import java.util.Arrays ; 31 import java.util.Collection ; 32 import java.util.Date ; 33 import java.util.Iterator ; 34 import java.util.Vector ; 35 36 import javax.ejb.CreateException ; 37 import javax.ejb.EJBException ; 38 import javax.ejb.ObjectNotFoundException ; 39 40 import org.ejbca.core.ejb.BaseSessionBean; 41 import org.ejbca.core.ejb.ca.auth.IAuthenticationSessionLocal; 42 import org.ejbca.core.ejb.ca.auth.IAuthenticationSessionLocalHome; 43 import org.ejbca.core.ejb.ca.caadmin.CADataLocal; 44 import org.ejbca.core.ejb.ca.caadmin.CADataLocalHome; 45 import org.ejbca.core.ejb.ca.publisher.IPublisherSessionLocal; 46 import org.ejbca.core.ejb.ca.publisher.IPublisherSessionLocalHome; 47 import org.ejbca.core.ejb.ca.store.CertificateDataBean; 48 import org.ejbca.core.ejb.ca.store.ICertificateStoreSessionLocal; 49 import org.ejbca.core.ejb.ca.store.ICertificateStoreSessionLocalHome; 50 import org.ejbca.core.ejb.log.ILogSessionLocal; 51 import org.ejbca.core.ejb.log.ILogSessionLocalHome; 52 import org.ejbca.core.model.InternalResources; 53 import org.ejbca.core.model.SecConst; 54 import org.ejbca.core.model.ca.AuthLoginException; 55 import org.ejbca.core.model.ca.AuthStatusException; 56 import org.ejbca.core.model.ca.IllegalKeyException; 57 import org.ejbca.core.model.ca.SignRequestException; 58 import org.ejbca.core.model.ca.SignRequestSignatureException; 59 import org.ejbca.core.model.ca.caadmin.CA; 60 import org.ejbca.core.model.ca.caadmin.CADoesntExistsException; 61 import org.ejbca.core.model.ca.caadmin.IllegalKeyStoreException; 62 import org.ejbca.core.model.ca.caadmin.extendedcaservices.ExtendedCAServiceNotActiveException; 63 import org.ejbca.core.model.ca.caadmin.extendedcaservices.ExtendedCAServiceRequest; 64 import org.ejbca.core.model.ca.caadmin.extendedcaservices.ExtendedCAServiceRequestException; 65 import org.ejbca.core.model.ca.caadmin.extendedcaservices.ExtendedCAServiceResponse; 66 import org.ejbca.core.model.ca.caadmin.extendedcaservices.IllegalExtendedCAServiceRequestException; 67 import org.ejbca.core.model.ca.catoken.CAToken; 68 import org.ejbca.core.model.ca.catoken.CATokenOfflineException; 69 import org.ejbca.core.model.ca.certificateprofiles.CertificateProfile; 70 import org.ejbca.core.model.ca.crl.RevokedCertInfo; 71 import org.ejbca.core.model.log.Admin; 72 import org.ejbca.core.model.log.LogEntry; 73 import org.ejbca.core.model.ra.NotFoundException; 74 import org.ejbca.core.model.ra.UserDataVO; 75 import org.ejbca.core.protocol.FailInfo; 76 import org.ejbca.core.protocol.IRequestMessage; 77 import org.ejbca.core.protocol.IResponseMessage; 78 import org.ejbca.core.protocol.ResponseStatus; 79 import org.ejbca.util.CertTools; 80 import org.ejbca.util.KeyTools; 81 82 162 public class RSASignSessionBean extends BaseSessionBean { 163 164 165 168 private CADataLocalHome cadatahome; 169 170 173 private ICertificateStoreSessionLocalHome storeHome = null; 174 175 176 private IAuthenticationSessionLocalHome authHome = null; 177 178 179 private IPublisherSessionLocalHome publishHome = null; 180 181 184 private ILogSessionLocal logsession; 185 186 187 private static final InternalResources intres = InternalResources.getInstance(); 188 189 192 SecureRandom randomSource = null; 193 194 200 public void ejbCreate() throws CreateException { 201 debug(">ejbCreate()"); 202 203 try { 204 CertTools.installBCProvider(); 206 207 storeHome = (ICertificateStoreSessionLocalHome) getLocator().getLocalHome(ICertificateStoreSessionLocalHome.COMP_NAME); 209 authHome = (IAuthenticationSessionLocalHome) getLocator().getLocalHome(IAuthenticationSessionLocalHome.COMP_NAME); 210 211 cadatahome = (CADataLocalHome) getLocator().getLocalHome(CADataLocalHome.COMP_NAME); 212 213 publishHome = (IPublisherSessionLocalHome) getLocator().getLocalHome(IPublisherSessionLocalHome.COMP_NAME); 214 215 String randomAlgorithm = getLocator().getString("java:comp/env/randomAlgorithm"); 217 randomSource = SecureRandom.getInstance(randomAlgorithm); 218 SernoGenerator.setAlgorithm(randomAlgorithm); 219 220 221 } catch (Exception e) { 222 debug("Caught exception in ejbCreate(): ", e); 223 throw new EJBException (e); 224 } 225 226 debug("<ejbCreate()"); 227 } 228 229 230 233 private ILogSessionLocal getLogSession() { 234 if (logsession == null) { 235 try { 236 ILogSessionLocalHome logsessionhome = (ILogSessionLocalHome) getLocator().getLocalHome(ILogSessionLocalHome.COMP_NAME); 237 logsession = logsessionhome.create(); 238 } catch (Exception e) { 239 throw new EJBException (e); 240 } 241 } 242 return logsession; 243 } 245 246 257 public Collection getCertificateChain(Admin admin, int caid) { 258 CADataLocal cadata = null; 260 try { 261 cadata = cadatahome.findByPrimaryKey(new Integer (caid)); 262 } catch (javax.ejb.FinderException fe) { 263 throw new EJBException (fe); 264 } 265 266 CA ca = null; 267 try { 268 ca = cadata.getCA(); 269 } catch (java.io.UnsupportedEncodingException uee) { 270 throw new EJBException (uee); 271 } catch(IllegalKeyStoreException e){ 272 throw new EJBException (e); 273 } 274 275 return ca.getCertificateChain(); 276 } 278 279 291 public byte[] createPKCS7(Admin admin, Certificate cert, boolean includeChain) throws CADoesntExistsException, SignRequestSignatureException { 292 Integer caid = new Integer (CertTools.getIssuerDN((X509Certificate ) cert).hashCode()); 293 return createPKCS7(caid.intValue(), cert, includeChain); 294 } 296 305 public byte[] createPKCS7(Admin admin, int caId, boolean includeChain) throws CADoesntExistsException { 306 try { 307 return createPKCS7(caId, null, includeChain); 308 } catch (SignRequestSignatureException e) { 309 String msg = intres.getLocalizedMessage("error.unknown"); 310 error(msg, e); 311 throw new EJBException (e); 312 } 313 } 315 325 private byte[] createPKCS7(int caId, Certificate cert, boolean includeChain) throws CADoesntExistsException, SignRequestSignatureException { 326 debug(">createPKCS7(" + caId + ", " + CertTools.getIssuerDN((X509Certificate ) cert) + ")"); 327 byte[] returnval = null; 328 CADataLocal cadata = null; 330 try { 331 cadata = cadatahome.findByPrimaryKey(new Integer (caId)); 332 } catch (javax.ejb.FinderException fe) { 333 throw new CADoesntExistsException(fe); 334 } 335 336 CA ca = null; 337 try { 338 ca = cadata.getCA(); 339 } catch (java.io.UnsupportedEncodingException uee) { 340 throw new CADoesntExistsException(uee); 341 } catch(IllegalKeyStoreException e){ 342 throw new EJBException (e); 343 } 344 345 X509Certificate cacert = (X509Certificate ) ca.getCACertificate(); 347 try { 348 cacert.checkValidity(); 349 } catch (CertificateExpiredException e) { 350 cadata.setStatus(SecConst.CA_EXPIRED); 352 ca.setStatus(SecConst.CA_EXPIRED); 353 String msg = intres.getLocalizedMessage("signsession.caexpired", cadata.getSubjectDN()); 354 throw new CADoesntExistsException(msg); 355 } catch (CertificateNotYetValidException cve) { 356 throw new CADoesntExistsException(cve); 357 } 358 359 returnval = ca.createPKCS7(cert, includeChain); 360 debug("<createPKCS7()"); 361 return returnval; 362 } 364 380 public Certificate createCertificate(Admin admin, String username, String password, PublicKey pk) throws ObjectNotFoundException , AuthStatusException, AuthLoginException, IllegalKeyException, CADoesntExistsException { 381 return createCertificate(admin, username, password, pk, -1); 383 } 385 408 public Certificate createCertificate(Admin admin, String username, String password, PublicKey pk, boolean[] keyusage) throws ObjectNotFoundException , AuthStatusException, AuthLoginException, IllegalKeyException, CADoesntExistsException { 409 return createCertificate(admin, username, password, pk, CertTools.sunKeyUsageToBC(keyusage)); 410 } 411 412 435 public Certificate createCertificate(Admin admin, String username, String password, PublicKey pk, int keyusage) throws ObjectNotFoundException , AuthStatusException, AuthLoginException, IllegalKeyException, CADoesntExistsException { 436 return createCertificate(admin, username, password, pk, keyusage, null, null, SecConst.PROFILE_NO_PROFILE, SecConst.CAID_USEUSERDEFINED); 437 } 438 439 463 public Certificate createCertificate(Admin admin, String username, String password, PublicKey pk, int keyusage, Date notBefore, Date notAfter) throws ObjectNotFoundException , AuthStatusException, AuthLoginException, IllegalKeyException, CADoesntExistsException { 464 return createCertificate(admin, username, password, pk, keyusage, notBefore, notAfter, SecConst.PROFILE_NO_PROFILE, SecConst.CAID_USEUSERDEFINED); 465 } 466 467 488 public Certificate createCertificate(Admin admin, String username, String password, int certType, PublicKey pk) throws ObjectNotFoundException , AuthStatusException, AuthLoginException, IllegalKeyException, CADoesntExistsException { 489 debug(">createCertificate(pk, certType)"); 490 boolean[] keyusage = new boolean[9]; 492 Arrays.fill(keyusage, false); 493 switch (certType) { 494 case CertificateDataBean.CERT_TYPE_ENCRYPTION: 495 keyusage[2] = true; 497 keyusage[3] = true; 499 break; 500 case CertificateDataBean.CERT_TYPE_SIGNATURE: 501 keyusage[0] = true; 503 keyusage[1] = true; 505 break; 506 default: 507 keyusage[0] = true; 509 keyusage[2] = true; 511 break; 512 } 513 514 Certificate ret = createCertificate(admin, username, password, pk, keyusage); 515 debug("<createCertificate(pk, certType)"); 516 return ret; 517 } 519 541 public Certificate createCertificate(Admin admin, String username, String password, Certificate incert) throws ObjectNotFoundException , AuthStatusException, AuthLoginException, IllegalKeyException, SignRequestSignatureException, CADoesntExistsException { 542 debug(">createCertificate(cert)"); 543 X509Certificate cert = (X509Certificate ) incert; 544 try { 545 X509Certificate bccert = CertTools.getCertfromByteArray(incert.getEncoded()); 547 bccert.verify(cert.getPublicKey()); 548 } catch (Exception e) { 549 log.debug("Exception verify POPO: ", e); 550 String msg = intres.getLocalizedMessage("signsession.popverificationfailed"); 551 throw new SignRequestSignatureException(msg); 552 } 553 Certificate ret = createCertificate(admin, username, password, cert.getPublicKey(), cert.getKeyUsage()); 554 debug("<createCertificate(cert)"); 555 return ret; 556 } 558 580 public IResponseMessage createCertificate(Admin admin, IRequestMessage req, Class responseClass) throws NotFoundException , AuthStatusException, AuthLoginException, IllegalKeyException, CADoesntExistsException, SignRequestException, SignRequestSignatureException { 581 return createCertificate(admin, req, -1, responseClass); 582 } 583 584 616 public Certificate createCertificate(Admin admin, String username, String password, PublicKey pk, int keyusage, int certificateprofileid, int caid) throws ObjectNotFoundException , AuthStatusException, AuthLoginException, IllegalKeyException, CADoesntExistsException { 617 return createCertificate(admin, username, password, pk, keyusage, null, null, certificateprofileid, caid); 618 } 619 620 653 public IResponseMessage createCertificate(Admin admin, IRequestMessage req, int keyUsage, Class responseClass) throws AuthStatusException, AuthLoginException, IllegalKeyException, CADoesntExistsException, SignRequestException, SignRequestSignatureException, NotFoundException { 654 debug(">createCertificate(IRequestMessage)"); 655 CADataLocal cadata = null; 657 UserDataVO data = null; 658 IResponseMessage ret = null; 659 try { 660 cadata = getCAFromRequest(admin, req); 661 CA ca = cadata.getCA(); 662 CAToken catoken = ca.getCAToken(); 663 664 if (req.requireKeyInfo()) { 666 req.setKeyInfo((X509Certificate )ca.getCACertificate(), catoken.getPrivateKey(SecConst.CAKEYPURPOSE_CERTSIGN), catoken.getProvider()); 668 } 669 if (req.verify() == false) { 671 String msg = intres.getLocalizedMessage("signsession.popverificationfailed"); 672 getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date (), req.getUsername(), null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, msg); 673 throw new SignRequestSignatureException(msg); 674 } 675 676 if (req.getUsername() == null) { 677 String msg = intres.getLocalizedMessage("signsession.nouserinrequest", req.getRequestDN()); 678 getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date (), req.getUsername(), null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, msg); 679 throw new SignRequestException(msg); 680 } else if (req.getPassword() == null) { 683 String msg = intres.getLocalizedMessage("signsession.nopasswordinrequest"); 684 getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date (), req.getUsername(), null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, msg); 685 throw new SignRequestException(msg); 686 } else { 687 ResponseStatus status = ResponseStatus.SUCCESS; 688 FailInfo failInfo = null; 689 String failText = null; 690 Certificate cert = null; 691 try { 692 data = authUser(admin, req.getUsername(), req.getPassword()); 694 PublicKey reqpk = req.getRequestPublicKey(); 695 if (reqpk == null) { 696 getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date (), req.getUsername(), null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, intres.getLocalizedMessage("signsession.nokeyinrequest")); 697 throw new InvalidKeyException ("Key is null!"); 698 } 699 if (data.getCAId() != ca.getCAId()) { 701 failText = intres.getLocalizedMessage("signsession.wrongauthority", new Integer (ca.getCAId()), new Integer (data.getCAId())); 702 status = ResponseStatus.FAILURE; 703 failInfo = FailInfo.WRONG_AUTHORITY; 704 getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date (), req.getUsername(), null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, failText); 705 } 706 707 if (status.equals(ResponseStatus.SUCCESS)) { 708 Date notBefore = req.getRequestValidityNotBefore(); Date notAfter = req.getRequestValidityNotAfter(); cert = createCertificate(admin, data, ca, reqpk, keyUsage, notBefore, notAfter); 711 } 712 } catch (ObjectNotFoundException oe) { 713 log.error("User not found: ", oe); 715 failText = intres.getLocalizedMessage("signsession.nosuchuser", req.getUsername()); 716 status = ResponseStatus.FAILURE; 717 failInfo = FailInfo.INCORRECT_DATA; 718 getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date (), req.getUsername(), null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, failText); 719 } 720 721 ret = req.createResponseMessage(responseClass, req, ca.getCACertificate(), catoken.getPrivateKey(SecConst.CAKEYPURPOSE_CERTSIGN), catoken.getPrivateKey(SecConst.CAKEYPURPOSE_KEYENCRYPT), catoken.getProvider()); 723 724 if ( (cert == null) && (status == ResponseStatus.SUCCESS) ) { 725 status = ResponseStatus.FAILURE; 726 failInfo = FailInfo.BAD_REQUEST; 727 } else { 728 ret.setCertificate(cert); 729 } 730 ret.setStatus(status); 731 if (failInfo != null) { 732 ret.setFailInfo(failInfo); 733 ret.setFailText(failText); 734 } 735 } 736 ret.create(); 737 if (ca.getFinishUser() == true) { 739 finishUser(admin, req.getUsername(), req.getPassword()); 740 } 741 } catch (NotFoundException oe) { 742 throw oe; 743 } catch (AuthStatusException se) { 744 throw se; 745 } catch (AuthLoginException le) { 746 throw le; 747 } catch (IllegalKeyException ke) { 748 log.error("Key is of unknown type: ", ke); 749 throw ke; 750 } catch (IllegalKeyStoreException e) { 751 throw new IllegalKeyException(e); 752 } catch (UnsupportedEncodingException e) { 753 throw new CADoesntExistsException(e); 754 } catch (NoSuchProviderException e) { 755 log.error("NoSuchProvider provider: ", e); 756 } catch (InvalidKeyException e) { 757 log.error("Invalid key in request: ", e); 758 } catch (NoSuchAlgorithmException e) { 759 log.error("No such algorithm: ", e); 760 } catch (IOException e) { 761 log.error("Cannot create response message: ", e); 762 } catch (CATokenOfflineException ctoe) { 763 String msg = intres.getLocalizedMessage("error.catokenoffline", cadata.getSubjectDN()); 764 log.error(msg, ctoe); 765 getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date (), null, null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, msg, ctoe); 766 throw new CADoesntExistsException(msg); 767 } 768 debug("<createCertificate(IRequestMessage)"); 769 return ret; 770 } 771 772 795 public IResponseMessage createRequestFailedResponse(Admin admin, IRequestMessage req, Class responseClass) throws AuthLoginException, AuthStatusException, IllegalKeyException, CADoesntExistsException, SignRequestSignatureException, SignRequestException { 796 debug(">createRequestFailedResponse(IRequestMessage)"); 797 IResponseMessage ret = null; 798 CADataLocal cadata = null; 799 try { 800 cadata = getCAFromRequest(admin, req); 801 CA ca = cadata.getCA(); 802 CAToken catoken = ca.getCAToken(); 803 804 if (req.requireKeyInfo()) { 806 req.setKeyInfo((X509Certificate )ca.getCACertificate(), catoken.getPrivateKey(SecConst.CAKEYPURPOSE_CERTSIGN), catoken.getProvider()); 808 } 809 if (req.verify() == false) { 811 String msg = intres.getLocalizedMessage("signsession.popverificationfailed"); 812 getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date (), req.getUsername(), null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, intres.getLocalizedMessage("signsession.popverificationfailed")); 813 throw new SignRequestSignatureException(msg); 814 } 815 816 ret = req.createResponseMessage(responseClass, req, ca.getCACertificate(), catoken.getPrivateKey(SecConst.CAKEYPURPOSE_CERTSIGN), catoken.getPrivateKey(SecConst.CAKEYPURPOSE_KEYENCRYPT), catoken.getProvider()); 818 819 ret.setStatus(ResponseStatus.FAILURE); 820 ret.setFailInfo(FailInfo.BAD_REQUEST); 821 ret.create(); 822 } catch (AuthStatusException se) { 823 throw se; 824 } catch (AuthLoginException le) { 825 throw le; 826 } catch (IllegalKeyStoreException e) { 827 throw new IllegalKeyException(e); 828 } catch (NotFoundException e) { 829 throw new CADoesntExistsException(e); 831 } catch (UnsupportedEncodingException e) { 832 throw new CADoesntExistsException(e); 833 } catch (NoSuchProviderException e) { 834 log.error("NoSuchProvider provider: ", e); 835 } catch (InvalidKeyException e) { 836 log.error("Invalid key in request: ", e); 837 } catch (NoSuchAlgorithmException e) { 838 log.error("No such algorithm: ", e); 839 } catch (IOException e) { 840 log.error("Cannot create response message: ", e); 841 } catch (CATokenOfflineException ctoe) { 842 String msg = intres.getLocalizedMessage("error.catokenoffline", cadata.getSubjectDN()); 843 log.error(msg, ctoe); 844 getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date (), null, null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, msg, ctoe); 845 throw new CADoesntExistsException(msg); 846 } 847 debug("<createRequestFailedResponse(IRequestMessage)"); 848 return ret; 849 } 850 851 872 public IRequestMessage decryptAndVerifyRequest(Admin admin, IRequestMessage req) throws ObjectNotFoundException , AuthStatusException, AuthLoginException, IllegalKeyException, CADoesntExistsException, SignRequestException, SignRequestSignatureException { 873 debug(">decryptAndVerifyRequest(IRequestMessage)"); 874 CADataLocal cadata = null; 876 877 try { 878 cadata = getCAFromRequest(admin, req); 879 CA ca = cadata.getCA(); 880 CAToken catoken = ca.getCAToken(); 881 882 if (req.requireKeyInfo()) { 884 req.setKeyInfo((X509Certificate )ca.getCACertificate(), catoken.getPrivateKey(SecConst.CAKEYPURPOSE_CERTSIGN), catoken.getProvider()); 886 } 887 if (req.verify() == false) { 889 String msg = intres.getLocalizedMessage("signsession.popverificationfailed"); 890 getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date (), req.getUsername(), null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, msg); 891 throw new SignRequestSignatureException(msg); 892 } 893 894 } catch (AuthStatusException se) { 895 throw se; 896 } catch (AuthLoginException le) { 897 throw le; 898 } catch (IllegalKeyStoreException e) { 899 throw new IllegalKeyException(e); 900 } catch (UnsupportedEncodingException e) { 901 throw new CADoesntExistsException(e); 902 } catch (NoSuchProviderException e) { 903 log.error("NoSuchProvider provider: ", e); 904 } catch (InvalidKeyException e) { 905 log.error("Invalid key in request: ", e); 906 } catch (NoSuchAlgorithmException e) { 907 log.error("No such algorithm: ", e); 908 } catch (CATokenOfflineException ctoe) { 909 String msg = intres.getLocalizedMessage("error.catokenoffline", cadata.getSubjectDN()); 910 log.error(msg, ctoe); 911 getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date (), null, null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, msg, ctoe); 912 throw new CADoesntExistsException(msg); 913 } 914 debug("<decryptAndVerifyRequest(IRequestMessage)"); 915 return req; 916 } 917 918 932 public IResponseMessage getCRL(Admin admin, IRequestMessage req, Class responseClass) throws AuthStatusException, AuthLoginException, IllegalKeyException, CADoesntExistsException, SignRequestException, SignRequestSignatureException, UnsupportedEncodingException { 933 debug(">getCRL(IRequestMessage)"); 934 IResponseMessage ret = null; 935 ICertificateStoreSessionLocal certificateStore = null; 936 try { 937 certificateStore = storeHome.create(); 938 } catch (CreateException e) { 939 error("Can not create certificate store session: ", e); 940 throw new EJBException (e); 941 } 942 CADataLocal cadata = getCAFromRequest(admin, req); 944 try { 945 CA ca = cadata.getCA(); 946 CAToken catoken = ca.getCAToken(); 947 948 if (ca.getStatus() != SecConst.CA_ACTIVE) { 949 String msg = intres.getLocalizedMessage("signsession.canotactive", cadata.getSubjectDN()); 950 getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date (), null, null, LogEntry.EVENT_ERROR_GETLASTCRL, msg); 951 throw new EJBException (msg); 952 } 953 954 X509Certificate cacert = (X509Certificate ) ca.getCACertificate(); 956 try { 957 cacert.checkValidity(); 958 } catch (CertificateExpiredException cee) { 959 cadata.setStatus(SecConst.CA_EXPIRED); 961 ca.setStatus(SecConst.CA_EXPIRED); 962 String msg = intres.getLocalizedMessage("signsession.caexpired", cadata.getSubjectDN()); 963 getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date (), null, null, LogEntry.EVENT_ERROR_GETLASTCRL, msg, cee); 964 throw new CADoesntExistsException(msg); 965 } catch (CertificateNotYetValidException cve) { 966 throw new CADoesntExistsException(cve); 967 } 968 969 if (req.requireKeyInfo()) { 971 req.setKeyInfo((X509Certificate )ca.getCACertificate(), catoken.getPrivateKey(SecConst.CAKEYPURPOSE_CERTSIGN), catoken.getProvider()); 973 } 974 ret = req.createResponseMessage(responseClass, req, ca.getCACertificate(), catoken.getPrivateKey(SecConst.CAKEYPURPOSE_CERTSIGN), catoken.getPrivateKey(SecConst.CAKEYPURPOSE_KEYENCRYPT), catoken.getProvider()); 976 977 byte[] crl = certificateStore.getLastCRL(admin, ca.getSubjectDN()); 980 if (crl != null) { 981 ret.setCrl(CertTools.getCRLfromByteArray(crl)); 982 ret.setStatus(ResponseStatus.SUCCESS); 983 } else { 984 ret.setStatus(ResponseStatus.FAILURE); 985 ret.setFailInfo(FailInfo.BAD_REQUEST); 986 } 987 ret.create(); 988 } catch (NotFoundException e) { 991 throw new CADoesntExistsException(e); 993 } catch (IllegalKeyStoreException e) { 994 throw new IllegalKeyException(e); 995 } catch (UnsupportedEncodingException e) { 996 throw new CADoesntExistsException(e); 997 } catch (NoSuchProviderException e) { 998 log.error("NoSuchProvider provider: ", e); 999 } catch (InvalidKeyException e) { 1000 log.error("Invalid key in request: ", e); 1001 } catch (NoSuchAlgorithmException e) { 1002 log.error("No such algorithm: ", e); 1003 } catch (CRLException e) { 1004 log.error("Cannot create response message: ", e); 1005 } catch (IOException e) { 1006 log.error("Cannot create response message: ", e); 1007 } catch (CATokenOfflineException ctoe) { 1008 String msg = intres.getLocalizedMessage("error.catokenoffline", cadata.getSubjectDN()); 1009 log.error(msg, ctoe); 1010 getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date (), null, null, LogEntry.EVENT_ERROR_GETLASTCRL, msg, ctoe); 1011 throw new CADoesntExistsException(msg); 1012 } 1013 debug("<getCRL(IRequestMessage)"); 1014 return ret; 1015 } 1016 1017 1021 private CADataLocal getCAFromRequest(Admin admin, IRequestMessage req) throws AuthStatusException, AuthLoginException, CADoesntExistsException, UnsupportedEncodingException { 1022 CADataLocal cadata = null; 1023 UserDataVO data = null; 1024 try { 1025 if (req.getIssuerDN() != null) { 1027 String dn = req.getIssuerDN(); 1028 debug("Got an issuerDN: "+dn); 1029 BigInteger serno = req.getSerialNo(); 1032 if (serno != null) { 1033 debug("Got a serialNumber: "+serno.toString(16)); 1034 ICertificateStoreSessionLocal certificateStore = storeHome.create(); 1035 X509Certificate cert = (X509Certificate )certificateStore.findCertificateByIssuerAndSerno(admin, dn, serno); 1036 if (cert != null) { 1037 dn = cert.getSubjectDN().getName(); 1038 } 1039 } 1040 debug("Using DN: "+dn); 1041 cadata = cadatahome.findByPrimaryKey(new Integer (dn.hashCode())); 1042 debug("Using CA (from issuerDN) with id: " + cadata.getCaId() + " and DN: " + cadata.getSubjectDN()); 1043 } else if (req.getUsername() != null) { 1044 String username = req.getUsername(); 1046 String password = req.getPassword(); 1047 data = authUser(admin, username, password); 1048 cadata = cadatahome.findByPrimaryKey(new Integer (data.getCAId())); 1049 debug("Using CA (from username) with id: " + cadata.getCaId() + " and DN: " + cadata.getSubjectDN()); 1050 } else { 1051 throw new CADoesntExistsException(); 1052 } 1053 } catch (javax.ejb.FinderException fe) { 1054 String msg = intres.getLocalizedMessage("signsession.canotfoundissuerusername", req.getIssuerDN(), req.getUsername()); 1055 error(msg); 1056 getLogSession().log(admin, -1, LogEntry.MODULE_CA, new java.util.Date (), req.getUsername(), null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, msg, fe); 1057 throw new CADoesntExistsException(fe); 1058 } catch (CreateException ce) { 1059 String msg = intres.getLocalizedMessage("signsession.canotfoundissuerusername", req.getIssuerDN(), req.getUsername()); 1061 error(msg, ce); 1062 getLogSession().log(admin, -1, LogEntry.MODULE_CA, new java.util.Date (), req.getUsername(), null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, msg, ce); 1063 throw new EJBException (ce); 1064 } 1065 1066 CA ca = null; 1067 try { 1068 ca = cadata.getCA(); 1069 1070 if (ca.getStatus() != SecConst.CA_ACTIVE) { 1071 String msg = intres.getLocalizedMessage("signsession.canotactive", cadata.getSubjectDN()); 1072 getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date (), null, null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, msg); 1073 throw new EJBException (msg); 1074 } 1075 1076 X509Certificate cacert = (X509Certificate ) ca.getCACertificate(); 1078 cacert.checkValidity(); 1079 } catch (CertificateExpiredException cee) { 1080 cadata.setStatus(SecConst.CA_EXPIRED); 1082 ca.setStatus(SecConst.CA_EXPIRED); 1083 String msg = intres.getLocalizedMessage("signsession.caexpired", cadata.getSubjectDN()); 1084 getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date (), null, null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, msg, cee); 1085 throw new CADoesntExistsException(msg); 1086 } catch (CertificateNotYetValidException cve) { 1087 throw new CADoesntExistsException(cve); 1088 } catch (IllegalKeyStoreException e) { 1089 throw new EJBException (e); 1090 } 1091 1092 return cadata; 1093 } 1094 1095 1105 public byte[] createCRL(Admin admin, int caid, Vector certs) throws CATokenOfflineException { 1106 debug(">createCRL()"); 1107 byte[] crlBytes; 1108 CADataLocal cadata = null; 1109 try { 1110 try { 1112 cadata = cadatahome.findByPrimaryKey(new Integer (caid)); 1113 } catch (javax.ejb.FinderException fe) { 1114 String msg = intres.getLocalizedMessage("signsession.canotfoundcaid", new Integer (caid)); 1115 getLogSession().log(admin, caid, LogEntry.MODULE_CA, new java.util.Date (), null, null, LogEntry.EVENT_ERROR_CREATECRL, msg, fe); 1116 throw new EJBException (fe); 1117 } 1118 1119 CA ca = null; 1120 try { 1121 ca = cadata.getCA(); 1122 } catch (java.io.UnsupportedEncodingException uee) { 1123 throw new EJBException (uee); 1124 } 1125 if (ca.getStatus() != SecConst.CA_ACTIVE) { 1126 String msg = intres.getLocalizedMessage("signsession.canotactive", cadata.getSubjectDN()); 1127 getLogSession().log(admin, caid, LogEntry.MODULE_CA, new java.util.Date (), null, null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, msg); 1128 throw new CATokenOfflineException(msg); 1129 } 1130 1131 X509Certificate cacert = (X509Certificate ) ca.getCACertificate(); 1133 try { 1134 cacert.checkValidity(); 1135 } catch (CertificateExpiredException e) { 1136 cadata.setStatus(SecConst.CA_EXPIRED); 1138 ca.setStatus(SecConst.CA_EXPIRED); 1139 String msg = intres.getLocalizedMessage("signsession.caexpired", cadata.getSubjectDN()); 1140 getLogSession().log(admin, caid, LogEntry.MODULE_CA, new java.util.Date (), null, null, LogEntry.EVENT_ERROR_CREATECRL, msg, e); 1141 throw new EJBException (msg); 1142 } catch (CertificateNotYetValidException e) { 1143 throw new EJBException (e); 1144 } 1145 1146 ICertificateStoreSessionLocal certificateStore = storeHome.create(); 1147 int number = certificateStore.getLastCRLNumber(admin, ca.getSubjectDN()) + 1; 1149 X509CRL crl = null; 1150 crl = (X509CRL ) ca.generateCRL(certs, number); 1151 String msg = intres.getLocalizedMessage("signsession.createdcrl", new Integer (number), cadata.getName(), cadata.getSubjectDN()); 1152 getLogSession().log(admin, caid, LogEntry.MODULE_CA, new java.util.Date (), null, null, LogEntry.EVENT_INFO_CREATECRL, msg); 1153 1154 String fingerprint = CertTools.getFingerprintAsString(cacert); 1156 certificateStore.storeCRL(admin, crl.getEncoded(), fingerprint, number); 1157 IPublisherSessionLocal pub = publishHome.create(); 1159 pub.storeCRL(admin, ca.getCRLPublishers(), crl.getEncoded(), fingerprint, number); 1160 1161 crlBytes = crl.getEncoded(); 1162 } catch (CATokenOfflineException ctoe) { 1163 String cadn = null; 1164 if (cadata != null) { 1165 cadn = cadata.getSubjectDN(); 1166 } 1167 String msg = intres.getLocalizedMessage("error.catokenoffline", cadn); 1168 log.error(msg, ctoe); 1169 getLogSession().log(admin, caid, LogEntry.MODULE_CA, new java.util.Date (), null, null, LogEntry.EVENT_ERROR_CREATECRL, msg, ctoe); 1170 throw ctoe; 1171 } catch (Exception e) { 1172 getLogSession().log(admin, caid, LogEntry.MODULE_CA, new java.util.Date (), null, null, LogEntry.EVENT_ERROR_CREATECRL, intres.getLocalizedMessage("signsession.errorcreatecrl"), e); 1173 throw new EJBException (intres.getLocalizedMessage("signsession.errorcreatecrl"), e); 1174 } 1175 debug("<createCRL()"); 1176 return crlBytes; 1177 } 1179 1188 public void publishCACertificate(Admin admin, Collection certificatechain, Collection usedpublishers) { 1189 try { 1190 1191 ICertificateStoreSessionLocal certificateStore = storeHome.create(); 1192 1193 Iterator certificates = certificatechain.iterator(); 1194 while (certificates.hasNext()) { 1195 X509Certificate cert = (X509Certificate ) certificates.next(); 1196 String fingerprint = CertTools.getFingerprintAsString(cert); 1197 boolean isSelfSigned = CertTools.isSelfSigned(cert); 1199 int type = CertificateDataBean.CERTTYPE_ENDENTITY; 1200 if (cert.getBasicConstraints() > -1) { 1201 if (isSelfSigned) { 1203 type = CertificateDataBean.CERTTYPE_ROOTCA; 1204 } else { 1205 type = CertificateDataBean.CERTTYPE_SUBCA; 1206 } 1207 } else if (isSelfSigned) { 1208 type = CertificateDataBean.CERTTYPE_ROOTCA; 1210 } 1211 1212 String name = "SYSTEMCERT"; 1213 if (type != CertificateDataBean.CERTTYPE_ENDENTITY) { 1214 name = "SYSTEMCA"; 1215 } 1216 if (certificateStore.findCertificateByFingerprint(admin, fingerprint) == null) { 1218 certificateStore.storeCertificate(admin, cert, name, fingerprint, CertificateDataBean.CERT_ACTIVE, type); 1219 } 1220 IPublisherSessionLocal pub = publishHome.create(); 1222 if (usedpublishers != null) { 1223 pub.storeCertificate(admin, usedpublishers, cert, fingerprint, null, fingerprint, CertificateDataBean.CERT_ACTIVE, type, -1, RevokedCertInfo.NOT_REVOKED, null); 1224 } 1225 } 1226 } catch (javax.ejb.CreateException ce) { 1227 throw new EJBException (ce); 1228 } 1229 } 1230 1231 private UserDataVO authUser(Admin admin, String username, String password) throws ObjectNotFoundException , AuthStatusException, AuthLoginException { 1232 try { 1234 IAuthenticationSessionLocal authSession = authHome.create(); 1235 return authSession.authenticateUser(admin, username, password); 1236 } catch (CreateException e) { 1237 log.error(e); 1238 throw new EJBException (e); 1239 } 1240 1241 } 1243 private void finishUser(Admin admin, String username, String password) { 1244 try { 1246 IAuthenticationSessionLocal authSession = authHome.create(); 1247 authSession.finishUser(admin, username, password); 1248 } catch (CreateException e) { 1249 log.error(e); 1250 throw new EJBException (e); 1251 } catch (ObjectNotFoundException e) { 1252 String msg = intres.getLocalizedMessage("signsession.finishnouser", username); 1253 log.info(msg); 1254 } 1255 } 1257 1288 private Certificate createCertificate(Admin admin, String username, String password, PublicKey pk, int keyusage, Date notBefore, Date notAfter, int certificateprofileid, int caid) throws ObjectNotFoundException , AuthStatusException, AuthLoginException, IllegalKeyException, CADoesntExistsException { 1289 debug(">createCertificate(pk, ku, date)"); 1290 try { 1291 UserDataVO data = authUser(admin, username, password); 1293 debug("Authorized user " + username + " with DN='" + data.getDN() + "'." + " with CA=" + data.getCAId()); 1294 if (certificateprofileid != SecConst.PROFILE_NO_PROFILE) { 1295 debug("Overriding user certificate profile with :" + certificateprofileid); 1296 data.setCertificateProfileId(certificateprofileid); 1297 } 1298 1299 if (caid != SecConst.CAID_USEUSERDEFINED) { 1300 debug("Overriding user caid with :" + caid); 1301 data.setCAId(caid); 1302 } 1303 1304 1305 debug("type=" + data.getType()); 1306 CADataLocal cadata = null; 1308 try { 1309 cadata = cadatahome.findByPrimaryKey(new Integer (data.getCAId())); 1310 } catch (javax.ejb.FinderException fe) { 1311 String msg = intres.getLocalizedMessage("signsession.canotfoundcaid", new Integer (data.getCAId())); 1312 getLogSession().log(admin, data.getCAId(), LogEntry.MODULE_CA, new java.util.Date (), data.getUsername(), null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, msg, fe); 1313 throw new CADoesntExistsException(msg); 1314 } 1315 CA ca = null; 1316 try { 1317 ca = cadata.getCA(); 1318 } catch (java.io.UnsupportedEncodingException uee) { 1319 throw new EJBException (uee); 1320 } catch(IllegalKeyStoreException e){ 1321 throw new EJBException (e); 1322 } 1323 X509Certificate cacert = (X509Certificate ) ca.getCACertificate(); 1325 1326 if (ca.getStatus() != SecConst.CA_ACTIVE) { 1327 String msg = intres.getLocalizedMessage("signsession.canotactive", cadata.getSubjectDN()); 1328 getLogSession().log(admin, data.getCAId(), LogEntry.MODULE_CA, new java.util.Date (), null, null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, msg); 1329 throw new EJBException (msg); 1330 } 1331 1332 try { 1333 cacert.checkValidity(); 1334 } catch (CertificateExpiredException cee) { 1335 cadata.setStatus(SecConst.CA_EXPIRED); 1337 ca.setStatus(SecConst.CA_EXPIRED); 1338 String msg = intres.getLocalizedMessage("signsession.caexpired", cadata.getSubjectDN()); 1339 getLogSession().log(admin, data.getCAId(), LogEntry.MODULE_CA, new java.util.Date (), null, null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, msg, cee); 1340 throw new EJBException (msg); 1341 } catch (CertificateNotYetValidException cve) { 1342 throw new EJBException (cve); 1343 } 1344 1345 1346 Certificate cert = createCertificate(admin, data, ca, pk, keyusage, notBefore, notAfter); 1348 if (ca.getFinishUser() == true) { 1350 finishUser(admin, username, password); 1351 } 1352 debug("<createCertificate(pk, ku, date)"); 1353 return cert; 1354 } catch (ObjectNotFoundException oe) { 1355 throw oe; 1356 } catch (AuthStatusException se) { 1357 throw se; 1358 } catch (AuthLoginException le) { 1359 throw le; 1360 } catch (IllegalKeyException ke) { 1361 throw ke; 1362 } 1363 } 1365 1378 private Certificate createCertificate(Admin admin, UserDataVO data, CA ca, PublicKey pk, int keyusage, Date notBefore, Date notAfter) throws IllegalKeyException { 1379 debug(">createCertificate(pk, ku, notAfter)"); 1380 try { 1381 getLogSession().log(admin, data.getCAId(), LogEntry.MODULE_CA, new java.util.Date (), data.getUsername(), null, LogEntry.EVENT_INFO_REQUESTCERTIFICATE, intres.getLocalizedMessage("signsession.requestcert", data.getUsername(), new Integer (data.getCAId()), new Integer (data.getCertificateProfileId()))); 1382 if (data.getType() == SecConst.USER_INVALID) { 1384 String msg = intres.getLocalizedMessage("signsession.usertypeinvalid"); 1385 getLogSession().log(admin, data.getCAId(), LogEntry.MODULE_CA, new java.util.Date (), data.getUsername(), null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, msg); 1386 } else { 1387 ICertificateStoreSessionLocal certificateStore = storeHome.create(); 1388 int certProfileId = data.getCertificateProfileId(); 1390 CertificateProfile certProfile = certificateStore.getCertificateProfile(admin, certProfileId); 1391 if (certProfile == null) { 1393 certProfileId = SecConst.CERTPROFILE_FIXED_ENDUSER; 1394 certProfile = certificateStore.getCertificateProfile(admin, certProfileId); 1395 } 1396 1397 boolean caauthorized = false; 1399 Iterator iter = certProfile.getAvailableCAs().iterator(); 1400 while (iter.hasNext()) { 1401 int next = ((Integer ) iter.next()).intValue(); 1402 if (next == data.getCAId() || next == CertificateProfile.ANYCA) { 1403 caauthorized = true; 1404 } 1405 } 1406 1407 if (certProfile.getType() != CertificateProfile.TYPE_ENDENTITY) { 1409 String msg = intres.getLocalizedMessage("signsession.errorcertprofiletype", new Integer (certProfile.getType())); 1410 getLogSession().log(admin, data.getCAId(), LogEntry.MODULE_CA, new java.util.Date (), data.getUsername(), null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, msg); 1411 throw new EJBException (msg); 1412 } 1413 1414 if (!caauthorized) { 1415 String msg = intres.getLocalizedMessage("signsession.errorcertprofilenotauthorized", new Integer (data.getCAId()), new Integer (certProfile.getType())); 1416 getLogSession().log(admin, data.getCAId(), LogEntry.MODULE_CA, new java.util.Date (), data.getUsername(), null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, msg); 1417 throw new EJBException (msg); 1418 } 1419 1420 log.debug("Using certificate profile with id " + certProfileId); 1421 int keyLength = KeyTools.getKeyLength(pk); 1422 if (keyLength == -1) { 1423 String text = intres.getLocalizedMessage("signsession.unsupportedkeytype", pk.getClass().getName()); 1424 getLogSession().log(admin, data.getCAId(), LogEntry.MODULE_CA, new java.util.Date (), data.getUsername(), null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, text); 1425 throw new IllegalKeyException(text); 1426 } 1427 log.debug("Keylength = " + keyLength); 1428 if ((keyLength < (certProfile.getMinimumAvailableBitLength() - 1)) 1429 || (keyLength > (certProfile.getMaximumAvailableBitLength()))) { 1430 String text = intres.getLocalizedMessage("signsession.illegalkeylength", new Integer (keyLength)); 1431 getLogSession().log(admin, data.getCAId(), LogEntry.MODULE_CA, new java.util.Date (), data.getUsername(), null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, text); 1432 log.error(text); 1433 throw new IllegalKeyException(text); 1434 } 1435 1436 X509Certificate cert = (X509Certificate ) ca.generateCertificate(data, pk, keyusage, notBefore, notAfter, certProfile); 1437 1438 getLogSession().log(admin, data.getCAId(), LogEntry.MODULE_CA, new java.util.Date (), data.getUsername(), cert, LogEntry.EVENT_INFO_CREATECERTIFICATE, intres.getLocalizedMessage("signsession.certificateissued", data.getUsername())); 1439 if (log.isDebugEnabled()) { 1440 debug("Generated certificate with SerialNumber '" + cert.getSerialNumber().toString(16) + "' for user '" + data.getUsername() + "'."); 1441 debug(cert.toString()); 1442 } 1443 1444 String cafingerprint = null; 1446 Certificate cacert = ca.getCACertificate(); 1447 if (cacert instanceof X509Certificate ) { 1448 cafingerprint = CertTools.getFingerprintAsString((X509Certificate )cacert); 1449 } 1450 certificateStore.storeCertificate(admin, cert, data.getUsername(), cafingerprint, CertificateDataBean.CERT_ACTIVE, certProfile.getType()); 1451 certificateStore.addCertReqHistoryData(admin,cert,data); 1453 IPublisherSessionLocal pub = publishHome.create(); 1455 if (certProfile.getPublisherList() != null) 1456 pub.storeCertificate(admin, certProfile.getPublisherList(), cert, data.getUsername(), data.getPassword(), cafingerprint, CertificateDataBean.CERT_ACTIVE, certProfile.getType(), -1, RevokedCertInfo.NOT_REVOKED, data.getExtendedinformation()); 1457 1458 debug("<createCertificate(pk, ku, notAfter)"); 1459 return cert; 1460 } 1461 } catch (IllegalKeyException ke) { 1462 throw ke; 1463 } catch (CATokenOfflineException ctoe) { 1464 String msg = intres.getLocalizedMessage("error.catokenoffline", ca.getSubjectDN()); 1465 getLogSession().log(admin, ca.getCAId(), LogEntry.MODULE_CA, new java.util.Date (), null, null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, msg, ctoe); 1466 throw new EJBException (msg, ctoe); 1467 } catch (Exception e) { 1468 log.error(e); 1469 throw new EJBException (e); 1470 } 1471 debug("<createCertificate(pk, ku)"); 1472 log.error("Invalid user type for user " + data.getUsername()); 1473 throw new EJBException ("Invalid user type for user " + data.getUsername()); 1474 } 1476 1490 public ExtendedCAServiceResponse extendedService(Admin admin, int caid, ExtendedCAServiceRequest request) 1491 throws ExtendedCAServiceRequestException, IllegalExtendedCAServiceRequestException, ExtendedCAServiceNotActiveException, CADoesntExistsException { 1492 1493 CADataLocal cadata = null; 1495 ExtendedCAServiceResponse returnval = null; 1496 try { 1497 cadata = cadatahome.findByPrimaryKey(new Integer (caid)); 1498 if (log.isDebugEnabled()) { 1499 debug("Exteneded service with request class '"+request.getClass().getName()+"' called for CA '"+cadata.getName()+"'"); 1500 } 1501 returnval = cadata.getCA().extendedService(request); 1502 } catch (javax.ejb.FinderException fe) { 1503 throw new CADoesntExistsException(fe); 1504 } catch (UnsupportedEncodingException ue) { 1505 throw new EJBException (ue); 1506 } catch(IllegalKeyStoreException e){ 1507 throw new EJBException (e); 1508 } 1509 1510 1511 return returnval; 1512 1513 } 1514 1515 1516} | Popular Tags |