1 13 14 package org.ejbca.ui.web.protocol; 15 16 import java.io.IOException ; 17 import java.security.GeneralSecurityException ; 18 19 import org.apache.log4j.Logger; 20 import org.ejbca.core.ejb.ca.sign.ISignSessionLocal; 21 import org.ejbca.core.model.ca.AuthLoginException; 22 import org.ejbca.core.model.ca.AuthStatusException; 23 import org.ejbca.core.model.ca.IllegalKeyException; 24 import org.ejbca.core.model.ca.SignRequestException; 25 import org.ejbca.core.model.ca.SignRequestSignatureException; 26 import org.ejbca.core.model.ca.caadmin.CADoesntExistsException; 27 import org.ejbca.core.model.log.Admin; 28 import org.ejbca.core.model.ra.NotFoundException; 29 import org.ejbca.core.protocol.IResponseMessage; 30 import org.ejbca.core.protocol.ScepRequestMessage; 31 32 33 38 public class ScepPkiOpHelper { 39 private static Logger log = Logger.getLogger(ScepPkiOpHelper.class); 40 private ScepRequestMessage reqmsg = null; 41 private Admin admin = null; 42 private ISignSessionLocal signsession = null; 43 44 50 public ScepPkiOpHelper(Admin admin, ISignSessionLocal signsession) { 51 log.debug(">ScepPkiOpHelper"); 52 this.admin = admin; 53 this.signsession = signsession; 54 log.debug("<ScepPkiOpHelper"); 55 } 56 57 64 public byte[] scepCertRequest(byte[] msg, boolean includeCACert) 65 throws NotFoundException, AuthLoginException, 66 SignRequestException, AuthStatusException, IllegalKeyException, 67 SignRequestSignatureException, CADoesntExistsException { 68 byte[] ret = null; 69 log.debug(">getRequestMessage(" + msg.length + " bytes)"); 70 71 try { 72 reqmsg = new ScepRequestMessage(msg, includeCACert); 73 74 if (reqmsg.getErrorNo() != 0) { 75 log.error("Error '" + reqmsg.getErrorNo() + "' receiving Scep request message."); 76 return null; 77 } 78 if (reqmsg.getMessageType() == ScepRequestMessage.SCEP_TYPE_PKCSREQ) { 79 IResponseMessage resp = signsession.createCertificate(admin, reqmsg, -1, 81 Class.forName(org.ejbca.core.protocol.ScepResponseMessage.class.getName())); 82 if (resp != null) { 83 ret = resp.getResponseMessage(); 84 } 85 } 86 if (reqmsg.getMessageType() == ScepRequestMessage.SCEP_TYPE_GETCRL) { 87 IResponseMessage resp = signsession.getCRL(admin, reqmsg, 90 Class.forName(org.ejbca.core.protocol.ScepResponseMessage.class.getName())); 91 if (resp != null) { 92 ret = resp.getResponseMessage(); 93 } 94 } 95 } catch (IOException e) { 96 log.error("Error receiving ScepMessage: ", e); 97 } catch (GeneralSecurityException e) { 98 log.error("Error receiving ScepMessage: ", e); 99 } catch (ClassNotFoundException e) { 100 log.error("Error createing response message template: ", e); 101 } 102 103 log.debug("<getRequestMessage():" + ((ret == null) ? 0 : ret.length)); 104 105 return ret; 106 } 107 } 108 | Popular Tags |