// Fetch the certificate and at the same time check that the user is authorized to it.
try {
rabean.loadCertificates(certsn, issuerdn);
CertificateView certview = rabean.getCertificate(0);
Certificate cert = certview.getCertificate();
byte[] enccert = cert.getEncoded();
// We must remove cache headers for IE
ServletUtils.removeCacheHeaders(res);
if (command.equalsIgnoreCase(COMMAND_NSCERT)) {
res.setContentType("application/x-x509-ca-cert");
res.setContentLength(enccert.length);
res.getOutputStream().write(enccert);
log.debug("Sent CA cert to NS client, len="+enccert.length+".");
} else if (command.equalsIgnoreCase(COMMAND_IECERT)) {
res.setHeader("Content-disposition", "attachment; filename=" + certview.getUsername() + ".crt");
res.setContentType("application/octet-stream");
res.setContentLength(enccert.length);
res.getOutputStream().write(enccert);
log.debug("Sent CA cert to IE client, len="+enccert.length+".");
} else if (command.equalsIgnoreCase(COMMAND_CERT)) {
byte[] b64cert = Base64.encode(enccert);
String out = RequestHelper.BEGIN_CERTIFICATE_WITH_NL;
out += new String(b64cert);
out += RequestHelper.END_CERTIFICATE_WITH_NL;
res.setHeader("Content-disposition", "attachment; filename=" + certview.getUsername() + ".pem");
res.setContentType("application/octet-stream");
res.setContentLength(out.length());
res.getOutputStream().write(out.getBytes());
log.debug("Sent CA cert to client, len="+out.length()+".");
} else {