private DERSet getAuthenticatedAttributeSet(byte secondDigest[], Calendar signingTime, byte[] ocsp, Collection<byte[]> crlBytes, CryptoStandard sigtype) {
try {
ASN1EncodableVector attribute = new ASN1EncodableVector();
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(new ASN1ObjectIdentifier(SecurityIDs.ID_CONTENT_TYPE));
v.add(new DERSet(new ASN1ObjectIdentifier(SecurityIDs.ID_PKCS7_DATA)));
attribute.add(new DERSequence(v));
v = new ASN1EncodableVector();
v.add(new ASN1ObjectIdentifier(SecurityIDs.ID_SIGNING_TIME));
v.add(new DERSet(new DERUTCTime(signingTime.getTime())));
attribute.add(new DERSequence(v));
v = new ASN1EncodableVector();
v.add(new ASN1ObjectIdentifier(SecurityIDs.ID_MESSAGE_DIGEST));
v.add(new DERSet(new DEROctetString(secondDigest)));
attribute.add(new DERSequence(v));
boolean haveCrl = false;
if (crlBytes != null) {
for (byte[] bCrl : crlBytes) {
if (bCrl != null) {
haveCrl = true;
break;
}
}
}
if (ocsp != null || haveCrl) {
v = new ASN1EncodableVector();
v.add(new ASN1ObjectIdentifier(SecurityIDs.ID_ADBE_REVOCATION));
ASN1EncodableVector revocationV = new ASN1EncodableVector();
if (haveCrl) {
ASN1EncodableVector v2 = new ASN1EncodableVector();
for (byte[] bCrl : crlBytes) {
if (bCrl == null)
continue;
ASN1InputStream t = new ASN1InputStream(new ByteArrayInputStream(bCrl));
v2.add(t.readObject());
}
revocationV.add(new DERTaggedObject(true, 0, new DERSequence(v2)));
}
if (ocsp != null) {
DEROctetString doctet = new DEROctetString(ocsp);
ASN1EncodableVector vo1 = new ASN1EncodableVector();
ASN1EncodableVector v2 = new ASN1EncodableVector();
v2.add(OCSPObjectIdentifiers.id_pkix_ocsp_basic);
v2.add(doctet);
ASN1Enumerated den = new ASN1Enumerated(0);
ASN1EncodableVector v3 = new ASN1EncodableVector();
v3.add(den);
v3.add(new DERTaggedObject(true, 0, new DERSequence(v2)));
vo1.add(new DERSequence(v3));
revocationV.add(new DERTaggedObject(true, 1, new DERSequence(vo1)));
}
v.add(new DERSet(new DERSequence(revocationV)));
attribute.add(new DERSequence(v));
}
if (sigtype == CryptoStandard.CADES) {
v = new ASN1EncodableVector();
v.add(new ASN1ObjectIdentifier(SecurityIDs.ID_AA_SIGNING_CERTIFICATE_V2));
ASN1EncodableVector aaV2 = new ASN1EncodableVector();
AlgorithmIdentifier algoId = new AlgorithmIdentifier(new ASN1ObjectIdentifier(digestAlgorithmOid), null);
aaV2.add(algoId);
MessageDigest md = interfaceDigest.getMessageDigest(getHashAlgorithm());
byte[] dig = md.digest(signCert.getEncoded());
aaV2.add(new DEROctetString(dig));
v.add(new DERSet(new DERSequence(new DERSequence(new DERSequence(aaV2)))));
attribute.add(new DERSequence(v));
}
return new DERSet(attribute);
}
catch (Exception e) {
throw new ExceptionConverter(e);
}
}