Java Code Examples for org.bouncycastle.asn1.cms.AttributeTable#get()

The following examples show how to use org.bouncycastle.asn1.cms.AttributeTable#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CMSOCSPSource.java    From dss with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void collectRevocationRefs(AttributeTable unsignedAttributes, ASN1ObjectIdentifier revocationReferencesAttribute, RevocationRefOrigin origin) {
	final Attribute attribute = unsignedAttributes.get(revocationReferencesAttribute);
	if (attribute == null) {
		return;
	}
	final ASN1Set attrValues = attribute.getAttrValues();
	if (attrValues.size() <= 0) {
		return;
	}

	final ASN1Encodable attrValue = attrValues.getObjectAt(0);
	final ASN1Sequence completeRevocationRefs = (ASN1Sequence) attrValue;
	for (int i = 0; i < completeRevocationRefs.size(); i++) {

		final CrlOcspRef otherCertId = CrlOcspRef.getInstance(completeRevocationRefs.getObjectAt(i));
		final OcspListID ocspListID = otherCertId.getOcspids();
		if (ocspListID != null) {
			for (final OcspResponsesID ocspResponsesID : ocspListID.getOcspResponses()) {
				final OCSPRef ocspRef = new OCSPRef(ocspResponsesID);
				addRevocationReference(ocspRef, origin);
			}
		}
	}
}
 
Example 2
Source File: CMSCertificateSource.java    From dss with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void extractCertificateValues() {
	AttributeTable unsignedAttributes = currentSignerInformation.getUnsignedAttributes();
	if (unsignedAttributes != null) {
		Attribute attribute = unsignedAttributes.get(id_aa_ets_certValues);
		if (attribute != null) {
			final ASN1Sequence seq = (ASN1Sequence) attribute.getAttrValues().getObjectAt(0);
			for (int ii = 0; ii < seq.size(); ii++) {
				try {
					final Certificate cs = Certificate.getInstance(seq.getObjectAt(ii));
					addCertificate(DSSUtils.loadCertificate(cs.getEncoded()), CertificateOrigin.CERTIFICATE_VALUES);
				} catch (Exception e) {
					LOG.warn("Unable to parse encapsulated certificate : {}", e.getMessage());
				}
			}
		}
	}
}
 
Example 3
Source File: CMSCertificateSource.java    From dss with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void extractCertificateRefsFromUnsignedAttribute(ASN1ObjectIdentifier attributeOid, CertificateRefOrigin origin) {
	AttributeTable unsignedAttributes = currentSignerInformation.getUnsignedAttributes();
	if (unsignedAttributes != null) {
		Attribute attribute = unsignedAttributes.get(attributeOid);
		if (attribute != null) {
			final ASN1Sequence seq = (ASN1Sequence) attribute.getAttrValues().getObjectAt(0);
			for (int ii = 0; ii < seq.size(); ii++) {
				try {
					OtherCertID otherCertId = OtherCertID.getInstance(seq.getObjectAt(ii));
					CertificateRef certRef = DSSASN1Utils.getCertificateRef(otherCertId);
					certRef.setOrigin(origin);
					addCertificateRef(certRef, origin);
				} catch (Exception e) {
					LOG.warn("Unable to parse encapsulated OtherCertID : {}", e.getMessage());
				}
			}
		}
	}
}
 
Example 4
Source File: CAdESTimeStampSigner.java    From signer with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public List<Timestamp> checkTimeStampOnSignature(byte[] signature) {
	try {
		Security.addProvider(new BouncyCastleProvider());
		List<Timestamp> listOfTimeStamp = new ArrayList<Timestamp>();
		CMSSignedData cmsSignedData = new CMSSignedData(signature);
		SignerInformationStore signers = cmsSignedData.getSignerInfos();
		Iterator<?> it = signers.getSigners().iterator();
		while (it.hasNext()) {
			SignerInformation signer = (SignerInformation) it.next();
			AttributeTable unsignedAttributes = signer
					.getUnsignedAttributes();
			Attribute attributeTimeStamp = unsignedAttributes
					.get(new ASN1ObjectIdentifier(
							PKCSObjectIdentifiers.id_aa_signatureTimeStampToken
									.getId()));
			if (attributeTimeStamp != null) {
				TimeStampOperator timeStampOperator = new TimeStampOperator();
				byte[] varTimeStamp = attributeTimeStamp.getAttrValues()
						.getObjectAt(0).toASN1Primitive().getEncoded();
				TimeStampToken timeStampToken = new TimeStampToken(
						new CMSSignedData(varTimeStamp));
				Timestamp timeStampSigner = new Timestamp(timeStampToken);
				timeStampOperator.validate(signer.getSignature(),
						varTimeStamp, null);
				listOfTimeStamp.add(timeStampSigner);
			}
		}
		return listOfTimeStamp;
	} catch (CertificateCoreException | IOException | TSPException
			| CMSException e) {
		throw new SignerException(e);
	}		
}
 
Example 5
Source File: CAdESSignature.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Attribute getSignedAttribute(ASN1ObjectIdentifier oid) {
	final AttributeTable signedAttributes = signerInformation.getSignedAttributes();
	if (signedAttributes == null) {
		return null;
	}
	return signedAttributes.get(oid);
}
 
Example 6
Source File: CMSUtils.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns an unsigned attribute by its given {@code oid}
 * @param signerInformation {@link SignerInformation} to get attribute from
 * @param oid {@link ASN1ObjectIdentifier} of the target attribute
 * @return {@link Attribute}
 */
public static Attribute getUnsignedAttribute(SignerInformation signerInformation, ASN1ObjectIdentifier oid) {
	final AttributeTable unsignedAttributes = signerInformation.getUnsignedAttributes();
	if (unsignedAttributes == null) {
		return null;
	}
	return unsignedAttributes.get(oid);
}
 
Example 7
Source File: CAdESLevelBaselineT.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @param cadesSignature
 */
private void assertExtendSignaturePossible(CAdESSignature cadesSignature) throws DSSException {
	final String exceptionMessage = "Cannot extend signature. The signedData is already extended with [%s].";
	if (SignatureLevel.CAdES_BASELINE_LTA.equals(cadesSignature.getDataFoundUpToLevel())) {
		throw new DSSException(String.format(exceptionMessage, "CAdES LTA"));
	}
	AttributeTable unsignedAttributes = CMSUtils.getUnsignedAttributes(cadesSignature.getSignerInformation());
	if (unsignedAttributes.get(PKCSObjectIdentifiers.id_aa_ets_escTimeStamp) != null) {
		throw new DSSException(String.format(exceptionMessage, PKCSObjectIdentifiers.id_aa_ets_escTimeStamp.getId()));
	}
}
 
Example 8
Source File: CMSCertificateSource.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void extractSigningCertificateReferences() {
	AttributeTable signedAttributes = currentSignerInformation.getSignedAttributes();
	if (signedAttributes != null && signedAttributes.size() > 0) {
		final Attribute signingCertificateAttributeV1 = signedAttributes.get(id_aa_signingCertificate);
		if (signingCertificateAttributeV1 != null) {
			extractSigningCertificateV1(signingCertificateAttributeV1);
		}
		final Attribute signingCertificateAttributeV2 = signedAttributes.get(id_aa_signingCertificateV2);
		if (signingCertificateAttributeV2 != null) {
			extractSigningCertificateV2(signingCertificateAttributeV2);
		}
	}
}
 
Example 9
Source File: DSSASN1Utils.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns ats-hash-index table, with a specified version present in from timestamp's unsigned properties
 * 
 * @param timestampUnsignedAttributes {@link AttributeTable} unsigned properties of the timestamp
 * @param atsHashIndexVersionIdentifier {@link ASN1ObjectIdentifier} identifier of ats-hash-index table to get
 * @return the content of SignedAttribute: ATS-hash-index unsigned attribute with a requested version if present
 */
public static ASN1Sequence getAtsHashIndexByVersion(AttributeTable timestampUnsignedAttributes, 
		ASN1ObjectIdentifier atsHashIndexVersionIdentifier) {
	if (timestampUnsignedAttributes != null && atsHashIndexVersionIdentifier != null) {
		final Attribute atsHashIndexAttribute = timestampUnsignedAttributes.get(atsHashIndexVersionIdentifier);
		if (atsHashIndexAttribute != null) {
			final ASN1Set attrValues = atsHashIndexAttribute.getAttrValues();
			if (attrValues != null && attrValues.size() == 1) {
				return (ASN1Sequence) attrValues.getObjectAt(0).toASN1Primitive();
			}
		}
	}
	return null;
}
 
Example 10
Source File: DSSASN1Utils.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns an Attribute values for a given {@code oid} found in the {@code unsignedAttributes}
 * @param unsignedAttributes {@link AttributeTable} of a signature
 * @param oid target {@link ASN1ObjectIdentifier}
 * @return {@link ASN1Set}
 */
public static ASN1Set getAsn1AttributeSet(AttributeTable unsignedAttributes, ASN1ObjectIdentifier oid) {
	final Attribute attribute = unsignedAttributes.get(oid);
	if (attribute == null) {
		return null;
	}
	return attribute.getAttrValues();
}
 
Example 11
Source File: ScepUtil.java    From xipki with Apache License 2.0 5 votes vote down vote up
public static ASN1Encodable getFirstAttrValue(AttributeTable attrs, ASN1ObjectIdentifier type) {
  Args.notNull(attrs, "attrs");
  Args.notNull(type, "type");
  Attribute attr = attrs.get(type);
  if (attr == null) {
    return null;
  }
  ASN1Set set = attr.getAttrValues();
  return (set.size() == 0) ? null : set.getObjectAt(0);
}
 
Example 12
Source File: CAdESSignature.java    From dss with GNU Lesser General Public License v2.1 4 votes vote down vote up
public boolean hasCProfile() {
	AttributeTable unsignedAttributes = CMSUtils.getUnsignedAttributes(signerInformation);
	return unsignedAttributes.get(id_aa_ets_certificateRefs) != null;
}
 
Example 13
Source File: CAdESSignature.java    From dss with GNU Lesser General Public License v2.1 4 votes vote down vote up
public boolean hasXProfile() {
	AttributeTable unsignedAttributes = CMSUtils.getUnsignedAttributes(signerInformation);
	return ((unsignedAttributes.get(id_aa_ets_certCRLTimestamp) != null) || (unsignedAttributes.get(id_aa_ets_escTimeStamp) != null));
}
 
Example 14
Source File: CAdESSignature.java    From dss with GNU Lesser General Public License v2.1 4 votes vote down vote up
public boolean hasAProfile() {
	AttributeTable unsignedAttributes = CMSUtils.getUnsignedAttributes(signerInformation);
	return unsignedAttributes.get(id_aa_ets_archiveTimestampV2) != null;
}