use of xades4j.properties.data.PropertyDataObject in project xades4j by luisgoncalves.
the class PropertiesDataObjectsGeneratorImpl method doGenPropsData.
private <TProp extends QualifyingProperty> Collection<PropertyDataObject> doGenPropsData(Collection<TProp> props, PropertiesDataGenerationContext ctx) throws PropertyDataGenerationException, PropertyDataStructureException {
Collection<PropertyDataObject> propsData = new ArrayList<PropertyDataObject>(props.size());
for (TProp p : props) {
PropertyDataObjectGenerator<TProp> dataGen = this.propsDataGensMapper.getGenerator(p);
PropertyDataObject pData = dataGen.generatePropertyData(p, ctx);
if (null == pData)
throw new PropertyDataGeneratorErrorException((QualifyingProperty) p);
propsData.add(pData);
}
dataObjectsStructureVerifier.verifiyPropertiesDataStructure(propsData);
return propsData;
}
use of xades4j.properties.data.PropertyDataObject in project xades4j by luisgoncalves.
the class ToXmlBaseTimeStampConverter method convertIntoObjectTree.
@Override
public final void convertIntoObjectTree(PropertyDataObject propData, TXml xmlProps, Document doc) {
TData tsData = (TData) propData;
XmlXAdESTimeStampType xmlTimeStamp = new XmlXAdESTimeStampType();
// Canonicalization method
XmlCanonicalizationMethodType xmlCanon = new XmlCanonicalizationMethodType();
xmlTimeStamp.setCanonicalizationMethod(xmlCanon);
Algorithm c14n = tsData.getCanonicalizationAlgorithm();
xmlCanon.setAlgorithm(c14n.getUri());
try {
List<Node> c14nParams = this.algorithmsParametersMarshallingProvider.marshalParameters(c14n, doc);
if (c14nParams != null) {
xmlCanon.getContent().addAll(c14nParams);
}
} catch (UnsupportedAlgorithmException ex) {
// Do not throw any specific exception for now.
throw new IllegalArgumentException("Cannot marshall algorithm parameters", ex);
}
// Time-stamp tokens
List<byte[]> tsTokens = tsData.getTimeStampTokens();
List<Object> xmlTSTokens = xmlTimeStamp.getEncapsulatedTimeStampOrXMLTimeStamp();
for (byte[] tsToken : tsTokens) {
XmlEncapsulatedPKIDataType xmlTSTkn = new XmlEncapsulatedPKIDataType();
xmlTSTkn.setValue(tsToken);
xmlTSTokens.add(xmlTSTkn);
}
insertIntoObjectTree(xmlTimeStamp, xmlProps, tsData);
}
use of xades4j.properties.data.PropertyDataObject in project xades4j by luisgoncalves.
the class XadesVerifierImpl method verify.
@Override
public XAdESVerificationResult verify(Element signatureElem, SignatureSpecificVerificationOptions verificationOptions) throws XAdES4jException {
if (null == signatureElem) {
throw new NullPointerException("Signature node not specified");
}
if (null == verificationOptions) {
verificationOptions = SignatureSpecificVerificationOptions.empty;
}
/* Unmarshal the signature */
XMLSignature signature;
try {
signature = new XMLSignature(signatureElem, verificationOptions.getBaseUri(), this.secureValidation);
} catch (XMLSecurityException ex) {
throw new UnmarshalException("Bad XML signature", ex);
}
String signatureId = signature.getId();
if (null == signatureId) {
throw new UnmarshalException("XML signature doesn't have an Id");
}
ReferencesRes referencesRes = SignatureUtils.processReferences(signature);
/* Apply early verifiers */
RawSignatureVerifierContext rawCtx = new RawSignatureVerifierContext(signature);
for (RawSignatureVerifier rawSignatureVerifier : this.rawSigVerifiers) {
rawSignatureVerifier.verify(rawCtx);
}
/* Get and check the QualifyingProperties element */
Element qualifyingPropsElem = SignatureUtils.getQualifyingPropertiesElement(signature);
SignatureUtils.checkSignedPropertiesIncorporation(qualifyingPropsElem, referencesRes.signedPropsReference);
// Check the QualifyingProperties 'Target' attribute.
Node targetAttr = qualifyingPropsElem.getAttributeNodeNS(null, QualifyingProperty.TARGET_ATTR);
if (null == targetAttr) {
targetAttr = qualifyingPropsElem.getAttributeNodeNS(QualifyingProperty.XADES_XMLNS, QualifyingProperty.TARGET_ATTR);
if (null == targetAttr) {
throw new QualifyingPropertiesIncorporationException("QualifyingProperties Target attribute not present");
}
}
String targetValue = targetAttr.getNodeValue();
if (null == targetValue || !targetValue.startsWith("#") || !targetValue.substring(1).equals(signatureId)) {
throw new QualifyingPropertiesIncorporationException("QualifyingProperties target doesn't match the signature's Id");
}
/* Unmarshal the qualifying properties */
QualifPropsDataCollectorImpl propsDataCollector = new QualifPropsDataCollectorImpl();
qualifPropsUnmarshaller.unmarshalProperties(qualifyingPropsElem, propsDataCollector);
Collection<PropertyDataObject> qualifPropsData = propsDataCollector.getPropertiesData();
/* Certification path */
KeyInfoRes keyInfoRes = SignatureUtils.processKeyInfo(signature.getKeyInfo());
Date validationDate = getValidationDate(qualifPropsData, signature, verificationOptions);
ValidationData certValidationRes = this.certificateValidator.validate(keyInfoRes.certSelector, validationDate, keyInfoRes.keyInfoCerts);
if (null == certValidationRes || certValidationRes.getCerts().isEmpty()) {
throw new NullPointerException("Certificate validator returned null or empty data");
}
X509Certificate validationCert = certValidationRes.getCerts().get(0);
/* Signature verification */
// Core XML-DSIG verification.
doCoreVerification(signature, verificationOptions, validationCert);
// Create the properties verification context.
QualifyingPropertyVerificationContext qPropsCtx = new QualifyingPropertyVerificationContext(signature, new QualifyingPropertyVerificationContext.CertificationChainData(certValidationRes.getCerts(), certValidationRes.getCrls(), keyInfoRes.issuerSerial), /**/
new QualifyingPropertyVerificationContext.SignedObjectsData(referencesRes.dataObjsReferences, signature));
// Verify the properties. Data structure verification is included.
Collection<PropertyInfo> props = this.qualifyingPropertiesVerifier.verifyProperties(qualifPropsData, qPropsCtx);
XAdESVerificationResult res = new XAdESVerificationResult(XAdESFormChecker.checkForm(props), signature, certValidationRes, props, referencesRes.dataObjsReferences);
// Apply the custom signature verifiers.
for (CustomSignatureVerifier customVer : this.customSigVerifiers) {
customVer.verify(res, qPropsCtx);
}
return res;
}
use of xades4j.properties.data.PropertyDataObject in project xades4j by luisgoncalves.
the class QualifyingPropertiesVerifierImpl method verifyProperties.
@Override
public Collection<PropertyInfo> verifyProperties(Collection<PropertyDataObject> unmarshalledProperties, QualifyingPropertyVerificationContext ctx) throws PropertyDataStructureException, InvalidPropertyException, QualifyingPropertyVerifierNotAvailableException {
dataObjectsStructureVerifier.verifiyPropertiesDataStructure(unmarshalledProperties);
Collection<PropertyInfo> props = new ArrayList<PropertyInfo>(unmarshalledProperties.size());
for (PropertyDataObject propData : unmarshalledProperties) {
QualifyingPropertyVerifier<PropertyDataObject> propVerifier = this.propertyVerifiersMapper.getVerifier(propData);
QualifyingProperty p = propVerifier.verify(propData, ctx);
if (null == p)
throw new PropertyVerifierErrorException(propData.getClass().getName());
props.add(new PropertyInfo(propData, p));
}
return Collections.unmodifiableCollection(props);
}
use of xades4j.properties.data.PropertyDataObject in project xades4j by luisgoncalves.
the class ToXmlCommitmentTypeConverter method convertIntoObjectTree.
@Override
public void convertIntoObjectTree(PropertyDataObject propData, XmlSignedPropertiesType xmlProps, Document doc) {
CommitmentTypeData commitmentTypeData = (CommitmentTypeData) propData;
// Create the JAXB CommitmentTypeIndication and add it to SignedDataObjectProperties.
XmlCommitmentTypeIndicationType xmlCommitmentTypeProp = new XmlCommitmentTypeIndicationType();
xmlProps.getSignedDataObjectProperties().getCommitmentTypeIndication().add(xmlCommitmentTypeProp);
XmlIdentifierType xmlIdentifier = new XmlIdentifierType();
xmlIdentifier.setValue(commitmentTypeData.getUri());
XmlObjectIdentifierType xmlObjectId = new XmlObjectIdentifierType();
xmlObjectId.setDescription(commitmentTypeData.getDescription());
xmlObjectId.setIdentifier(xmlIdentifier);
xmlCommitmentTypeProp.setCommitmentTypeId(xmlObjectId);
Collection<String> refsUris = commitmentTypeData.getObjReferences();
if (null == refsUris) {
xmlCommitmentTypeProp.setAllSignedDataObjects();
} else {
xmlCommitmentTypeProp.getObjectReference().addAll(refsUris);
}
Collection qualifiers = commitmentTypeData.getQualifiers();
if (!qualifiers.isEmpty()) {
XmlCommitmentTypeQualifiersListType xmlQualifiers = new XmlCommitmentTypeQualifiersListType();
for (Object q : qualifiers) {
XmlAnyType xmlQualifier = new XmlAnyType();
xmlQualifier.getContent().add(q);
xmlQualifiers.getCommitmentTypeQualifier().add(xmlQualifier);
}
xmlCommitmentTypeProp.setCommitmentTypeQualifiers(xmlQualifiers);
}
}
Aggregations