1 13 14 package org.ejbca.core.protocol; 15 16 import java.security.PrivateKey ; 17 import java.security.cert.Certificate ; 18 import java.security.cert.X509Certificate ; 19 import java.util.Random ; 20 21 import org.apache.log4j.Logger; 22 import org.ejbca.util.Base64; 23 24 25 26 31 public class RequestMessageUtils { 32 41 static final long serialVersionUID = 3597275157018205138L; 42 43 private static final Logger log = Logger.getLogger(RequestMessageUtils.class); 44 45 public static IResponseMessage createResponseMessage(Class responseClass, IRequestMessage req, Certificate cert, PrivateKey signPriv, PrivateKey encPriv, String provider){ 46 IResponseMessage ret = null; 47 try { 49 ret = (IResponseMessage) responseClass.newInstance(); 50 } catch (InstantiationException e) { 51 log.error("Error creating response message", e); 53 return null; 54 } catch (IllegalAccessException e) { 55 log.error("Error creating response message", e); 56 return null; 57 } 58 if (ret.requireSignKeyInfo()) { 59 ret.setSignKeyInfo((X509Certificate ) cert, signPriv, provider); 60 } 61 if (ret.requireEncKeyInfo()) { 62 ret.setEncKeyInfo((X509Certificate ) cert, encPriv, provider); 63 } 64 if (req.getSenderNonce() != null) { 65 ret.setRecipientNonce(req.getSenderNonce()); 66 } 67 if (req.getTransactionId() != null) { 68 ret.setTransactionId(req.getTransactionId()); 69 } 70 byte[] senderNonce = new byte[16]; 72 Random randomSource = new Random (); 73 randomSource.nextBytes(senderNonce); 74 ret.setSenderNonce(new String (Base64.encode(senderNonce))); 75 if (req.getRequestKeyInfo() != null) { 77 ret.setRecipientKeyInfo(req.getRequestKeyInfo()); 78 } 79 ret.setPreferredDigestAlg(req.getPreferredDigestAlg()); 81 ret.setIncludeCACert(req.includeCACert()); 83 ret.setRequestType(req.getRequestType()); 85 ret.setRequestId(req.getRequestId()); 86 ret.setProtectionParamsFromRequest(req); 88 return ret; 89 } 90 91 92 } 93 | Popular Tags |