if ((reqBytes != null) && (reqBytes.length>0)) {
log.debug("Received NS request: "+new String(reqBytes));
byte[] certs = helper.nsCertRequest(signSession, reqBytes, username, password);
RequestHelper.sendNewCertToNSClient(certs, response);
} else {
throw new SignRequestException("No request bytes received.");
}
} else if ( getParameter("iidPkcs10") != null && !getParameter("iidPkcs10").equals("")) {
// NetID iid?
byte[] reqBytes = getParameter("iidPkcs10").getBytes();
if ((reqBytes != null) && (reqBytes.length>0)) {
log.debug("Received iidPkcs10 request: "+new String(reqBytes));
byte[] b64cert=helper.pkcs10CertRequest(signSession, reqBytes, username, password, RequestHelper.ENCODED_CERTIFICATE, false);
response.setContentType("text/html");
RequestHelper.sendNewCertToIidClient(b64cert, request, response.getOutputStream(), servletContext, servletConfig.getInitParameter("responseIidTemplate"),classid);
} else {
throw new SignRequestException("No request bytes received.");
}
} else if ( (getParameter("pkcs10") != null) || (getParameter("PKCS10") != null) ) {
// if not firefox, check if it's IE
byte[] reqBytes = getParameter("pkcs10").getBytes();
if (reqBytes == null) {
reqBytes=getParameter("PKCS10").getBytes();
}
if ((reqBytes != null) && (reqBytes.length>0)) {
log.debug("Received IE request: "+new String(reqBytes));
byte[] b64cert=helper.pkcs10CertRequest(signSession, reqBytes, username, password, RequestHelper.ENCODED_PKCS7);
debug.ieCertFix(b64cert);
RequestHelper.sendNewCertToIEClient(b64cert, response.getOutputStream(), servletContext, servletConfig.getInitParameter("responseTemplate"),classid);
} else {
throw new SignRequestException("No request bytes received.");
}
} else if ( ((getParameter("pkcs10req") != null) || (getParameter("pkcs10file") != null)) && resulttype != 0) {
byte[] reqBytes = null;
String pkcs10req = getParameter("pkcs10req");
if (StringUtils.isEmpty(pkcs10req)) {
// did we upload a file instead?
log.debug("No pasted request received, checking for uploaded file.");
pkcs10req = getParameter("pkcs10file");
if (StringUtils.isNotEmpty(pkcs10req)) {
// The uploaded file has been converted to a base64 encoded string
reqBytes = Base64.decode(pkcs10req.getBytes());
}
} else {
reqBytes=pkcs10req.getBytes(); // The pasted request
}
if ((reqBytes != null) && (reqBytes.length>0)) {
pkcs10Req(response, username, password, resulttype, signSession, helper, reqBytes);
} else {
throw new SignRequestException("No request bytes received.");
}
} else if ( ((getParameter("cvcreq") != null) || (getParameter("cvcreqfile") != null)) && resulttype != 0) {
// It's a CVC certificate request (EAC ePassports)
byte[] reqBytes = null;
String req = getParameter("cvcreq");
if (StringUtils.isEmpty(req)) {
// did we upload a file instead?
log.debug("No pasted request received, checking for uploaded file.");
req = getParameter("cvcreqfile");
if (StringUtils.isNotEmpty(req)) {
// The uploaded file has been converted to a base64 encoded string
reqBytes = Base64.decode(req.getBytes());
}
} else {
reqBytes=req.getBytes(); // The pasted request
}
if ((reqBytes != null) && (reqBytes.length>0)) {
log.debug("Received CVC request: "+new String(reqBytes));
byte[] b64cert=helper.cvcCertRequest(signSession, reqBytes, username, password);
CVCertificate cvccert = (CVCertificate) CertificateParser.parseCVCObject(Base64.decode(b64cert));
String filename = "";
CAReferenceField carf = cvccert.getCertificateBody().getAuthorityReference();
if (carf != null) {
String car = carf.getConcatenated();
filename += car;
}
HolderReferenceField chrf = cvccert.getCertificateBody().getHolderReference();
if (chrf != null) {
String chr = chrf.getConcatenated();
if (filename.length() > 0) {
filename += "_";
}
filename +=chr;
}
if (filename.length() == 0) {
filename = username;
}
log.debug("Filename: "+filename);
if(resulttype == RequestHelper.BINARY_CERTIFICATE) {
RequestHelper.sendBinaryBytes(Base64.decode(b64cert), response, "application/octet-stream", filename+".cvcert");
}
if(resulttype == RequestHelper.ENCODED_CERTIFICATE) {
RequestHelper.sendNewB64File(b64cert, response, filename+".pem", RequestHelper.BEGIN_CERTIFICATE_WITH_NL, RequestHelper.END_CERTIFICATE_WITH_NL);
}
} else {
throw new SignRequestException("No request bytes received.");
}
}
}
} catch (ObjectNotFoundException oe) {
iErrorMessage = intres.getLocalizedMessage("certreq.nosuchusername");