CMSSignedData csd = new CMSSignedData(scepmsg);
SignerInformationStore infoStore = csd.getSignerInfos();
Collection signers = infoStore.getSigners();
Iterator iter = signers.iterator();
if (iter.hasNext()) {
SignerInformation si = (SignerInformation)iter.next();
preferredDigestAlg = si.getDigestAlgOID();
log.debug("Set "+ preferredDigestAlg+" as preferred digest algorithm for SCEP");
}
} catch (CMSException e) {
// ignore, use default digest algo
log.error("CMSException trying to get preferred digest algorithm: ", e);
}
// Parse and verify the entegrity of the PKIOperation message PKCS#7
/* If this would have been done using the newer CMS it would have made me so much happier... */
ASN1Sequence seq = (ASN1Sequence) new ASN1InputStream(new ByteArrayInputStream(scepmsg)).readObject();
ContentInfo ci = new ContentInfo(seq);
String ctoid = ci.getContentType().getId();
if (ctoid.equals(CMSObjectIdentifiers.signedData.getId())) {
// This is SignedData so it is a pkcsCertReqSigned,
// pkcsGetCertInitialSigned, pkcsGetCertSigned, pkcsGetCRLSigned
// (could also be pkcsRepSigned or certOnly, but we don't receive them on the server side
// Try to find out what kind of message this is
sd = new SignedData((ASN1Sequence) ci.getContent());
// Get self signed cert to identify the senders public key
ASN1Set certs = sd.getCertificates();
if (certs.size() > 0) {
// There should be only one...
DEREncodable dercert = certs.getObjectAt(0);
if (dercert != null) {
// Requestors self-signed certificate is requestKeyInfo
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
DEROutputStream dOut = new DEROutputStream(bOut);
dOut.writeObject(dercert);
if (bOut.size() > 0) {
requestKeyInfo = bOut.toByteArray();
//Create Certificate used for debugging
try {
signercert = CertTools.getCertfromByteArray(requestKeyInfo);
if (log.isDebugEnabled()) {
log.debug("requestKeyInfo is SubjectDN: " + CertTools.getSubjectDN(signercert) +
", Serial=" + CertTools.getSerialNumberAsString(signercert) +
"; IssuerDN: "+ CertTools.getIssuerDN(signercert).toString());
}
} catch (CertificateException e) {
log.error("Error parsing requestKeyInfo : ", e);
}
}
}
}
Enumeration sis = sd.getSignerInfos().getObjects();
if (sis.hasMoreElements()) {
SignerInfo si = new SignerInfo((ASN1Sequence) sis.nextElement());
Enumeration attr = si.getAuthenticatedAttributes().getObjects();
while (attr.hasMoreElements()) {
Attribute a = new Attribute((ASN1Sequence) attr.nextElement());
log.debug("Found attribute: " + a.getAttrType().getId());