use of com.github.zhenwei.core.asn1.DERSet in project OpenPDF by LibrePDF.
the class PdfPKCS7 method getAuthenticatedAttributeSet.
private DERSet getAuthenticatedAttributeSet(byte[] secondDigest, Calendar signingTime, byte[] ocsp) {
try {
ASN1EncodableVector attribute = new ASN1EncodableVector();
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(new ASN1ObjectIdentifier(ID_CONTENT_TYPE));
v.add(new DERSet(new ASN1ObjectIdentifier(ID_PKCS7_DATA)));
attribute.add(new DERSequence(v));
v = new ASN1EncodableVector();
v.add(new ASN1ObjectIdentifier(ID_SIGNING_TIME));
v.add(new DERSet(new DERUTCTime(signingTime.getTime())));
attribute.add(new DERSequence(v));
v = new ASN1EncodableVector();
v.add(new ASN1ObjectIdentifier(ID_MESSAGE_DIGEST));
v.add(new DERSet(new DEROctetString(secondDigest)));
attribute.add(new DERSequence(v));
if (ocsp != null) {
v = new ASN1EncodableVector();
v.add(new ASN1ObjectIdentifier(ID_ADBE_REVOCATION));
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));
v.add(new DERSet(new DERSequence(new DERTaggedObject(true, 1, new DERSequence(vo1)))));
attribute.add(new DERSequence(v));
} else if (!crls.isEmpty()) {
v = new ASN1EncodableVector();
v.add(new ASN1ObjectIdentifier(ID_ADBE_REVOCATION));
ASN1EncodableVector v2 = new ASN1EncodableVector();
for (Object crl : crls) {
ASN1InputStream t = new ASN1InputStream(new ByteArrayInputStream(((X509CRL) crl).getEncoded()));
v2.add(t.readObject());
}
v.add(new DERSet(new DERSequence(new DERTaggedObject(true, 0, new DERSequence(v2)))));
attribute.add(new DERSequence(v));
}
return new DERSet(attribute);
} catch (Exception e) {
throw new ExceptionConverter(e);
}
}
use of com.github.zhenwei.core.asn1.DERSet in project signer by demoiselle.
the class PolicyIssuerName method parse.
@Override
public void parse(ASN1Primitive primitive) {
if (primitive instanceof DLSequence) {
DLSequence sequence = (DLSequence) primitive;
ASN1Encodable asn1Encodable = sequence.getObjectAt(0);
if (asn1Encodable instanceof DERTaggedObject) {
DERTaggedObject derTaggedObject = (DERTaggedObject) asn1Encodable;
ASN1Primitive object = derTaggedObject.getObject();
if (object instanceof DEROctetString) {
OctetString octetString = new OctetString();
octetString.parse(object);
this.issuerName = octetString.getValueUTF8();
} else if (object instanceof DERSequence) {
DERSequence sequence2 = (DERSequence) object;
for (int i = 0; i < sequence2.size(); i++) {
ASN1Encodable obj = sequence2.getObjectAt(i);
if (obj instanceof DERSet) {
DERSet set = (DERSet) obj;
ASN1Encodable object2 = set.getObjectAt(0);
if (object2 instanceof DERSequence) {
DERSequence sequence3 = (DERSequence) object2;
ObjectIdentifier objectIdendifier = new ObjectIdentifier();
objectIdendifier.parse(sequence3.getObjectAt(0).toASN1Primitive());
String name = null;
ASN1Encodable object3 = sequence3.getObjectAt(1);
if (object3 instanceof DERPrintableString) {
name = ((DERPrintableString) object3).getString();
} else if (object3 instanceof DERUTF8String) {
name = ((DERUTF8String) object3).getString();
} else {
System.out.println(policyMessagesBundle.getString("error.not.recognized.object", object3.getClass(), object3.toString()));
}
if (this.issuerNames == null) {
this.issuerNames = new HashMap<ObjectIdentifier, String>();
}
this.issuerNames.put(objectIdendifier, name);
}
}
}
}
}
}
}
use of com.github.zhenwei.core.asn1.DERSet in project signer by demoiselle.
the class IdSigningPolicy method getValue.
/**
* org.bouncycastle.asn1.ASN1ObjectIdentifier sigPolicyId
* org.bouncycastle.asn1.esf.OtherHashAlgAndValue sigPolicyHash
* List<org.bouncycastle.asn1.esf.SigPolicyQualifierInfo> sigPolicyQualifierInfos
*/
@Override
public Attribute getValue() {
// Atributo 1
ASN1ObjectIdentifier sigPolicyId = new ASN1ObjectIdentifier(signaturePolicy.getSignPolicyInfo().getSignPolicyIdentifier().getValue());
// Atributo 2
OtherHashAlgAndValue sigPolicyHash = new OtherHashAlgAndValue(new AlgorithmIdentifier(new ASN1ObjectIdentifier(signaturePolicy.getSignPolicyHashAlg().getAlgorithm().getValue())), signaturePolicy.getSignPolicyHash().getDerOctetString());
// Atributo 3
List<SigPolicyQualifierInfo> sigPolicyQualifierInfos = new ArrayList<SigPolicyQualifierInfo>();
ASN1ObjectIdentifier sigPolicyQualifierId = new ASN1ObjectIdentifier("1.2.840.113549.1.9.16.5.1");
DERIA5String sigQualifier = new DERIA5String(signaturePolicy.getSignPolicyURI());
SigPolicyQualifierInfo bcSigPolicyQualifierInfo = new SigPolicyQualifierInfo(sigPolicyQualifierId, sigQualifier);
sigPolicyQualifierInfos.add(bcSigPolicyQualifierInfo);
SigPolicyQualifiers sigPolicyQualifiers = new SigPolicyQualifiers(sigPolicyQualifierInfos.toArray(new SigPolicyQualifierInfo[] {}));
SignaturePolicyId signaturePolicyId = new SignaturePolicyId(sigPolicyId, sigPolicyHash, sigPolicyQualifiers);
return new Attribute(identifier, new DERSet(signaturePolicyId));
}
use of com.github.zhenwei.core.asn1.DERSet in project signer by demoiselle.
the class MessageDigest method getValue.
@Override
public Attribute getValue() {
try {
if (this.hash == null) {
java.security.MessageDigest md = java.security.MessageDigest.getInstance(signaturePolicy.getSignPolicyHashAlg().getAlgorithm().getValue());
this.hash = md.digest(content);
}
return new Attribute(identifier, new DERSet(new DEROctetString(this.hash)));
} catch (NoSuchAlgorithmException ex) {
logger.info(ex.getMessage());
return null;
}
}
use of com.github.zhenwei.core.asn1.DERSet in project signer by demoiselle.
the class DemoiselleSignedAttributeTableGenerator method createStandardAttributeTable.
/**
* Create a standard attribute table from the passed in parameters - this will
* normally include contentType, signingTime, and messageDigest. If the constructor
* using an AttributeTable was used, entries in it for contentType, signingTime, and
* messageDigest will override the generated ones.
*
* @param parameters source parameters for table generation.
* @return a filled in Hashtable of attributes.
*/
protected Hashtable createStandardAttributeTable(Map parameters) {
Hashtable std = copyHashTable(table);
if (!std.containsKey(CMSAttributes.contentType)) {
ASN1ObjectIdentifier contentType = ASN1ObjectIdentifier.getInstance(parameters.get(CMSAttributeTableGenerator.CONTENT_TYPE));
// contentType will be null if we're trying to generate a counter signature.
if (contentType != null) {
Attribute attr = new Attribute(CMSAttributes.contentType, new DERSet(contentType));
std.put(attr.getAttrType(), attr);
}
}
if (!std.containsKey(CMSAttributes.messageDigest)) {
byte[] messageDigest = (byte[]) parameters.get(CMSAttributeTableGenerator.DIGEST);
Attribute attr = new Attribute(CMSAttributes.messageDigest, new DERSet(new DEROctetString(messageDigest)));
std.put(attr.getAttrType(), attr);
}
return std;
}
Aggregations