use of xades4j.properties.data.GenericDOMData in project xades4j by luisgoncalves.
the class DefaultVerificationBindingsModule method configure.
@Override
protected void configure() {
bind(MessageDigestEngineProvider.class).to(DefaultMessageDigestProvider.class);
bind(TimeStampVerificationProvider.class).to(DefaultTimeStampVerificationProvider.class);
bind(SignaturePolicyDocumentProvider.class).toInstance(new SignaturePolicyDocumentProvider() {
@Override
public InputStream getSignaturePolicyDocumentStream(ObjectIdentifier sigPolicyId) {
return null;
}
});
// QualifyingPropertiesVerifier is not configurable but the individual
// verifiers may have dependencies.
bind(QualifyingPropertiesVerifier.class).to(QualifyingPropertiesVerifierImpl.class);
bind(QualifyingPropertyVerifiersMapper.class).to(QualifyingPropertyVerifiersMapperImpl.class);
// customGlobalStructureVerifiers.add(new CustomPropertiesDataObjsStructureVerifier()
// {
// @Override
// public void verifiy(DataGetter<PropertyDataObject> dataObjsGetter) throws PropertyDataStructureException
// {
// if (dataObjsGetter.getOfType(SigningCertificateData.class).isEmpty())
// throw new PropertyDataStructureException("property is required and isn't present", SigningCertificateProperty.PROP_NAME);
// }
// });
// QualifyingPropertyVerifiersMapperImpl relies on the injector to get
// the individual verifiers, so they need to be bound.
// - SignedSignatureProperties
bindBuiltInVerifier(SigningTimeData.class, SigningTimeVerifier.class);
bindBuiltInVerifier(SignerRoleData.class, SignerRoleVerifier.class);
bindBuiltInVerifier(SignatureProdPlaceData.class, SigProdPlaceVerifier.class);
bindBuiltInVerifier(SigningCertificateData.class, SigningCertificateVerifier.class);
bindBuiltInVerifier(SignaturePolicyData.class, SignaturePolicyVerifier.class);
// - SignedDataObjectProperties
bindBuiltInVerifier(CommitmentTypeData.class, CommitmentTypeVerifier.class);
bindBuiltInVerifier(DataObjectFormatData.class, DataObjFormatVerifier.class);
bindBuiltInVerifier(AllDataObjsTimeStampData.class, AllDataObjsTimeStampVerifier.class);
bindBuiltInVerifier(IndividualDataObjsTimeStampData.class, IndivDataObjsTimeStampVerifier.class);
// - UnsignedSignatureProperties
bindBuiltInVerifier(SignatureTimeStampData.class, SignatureTimeStampVerifier.class);
bindBuiltInVerifier(CompleteCertificateRefsData.class, CompleteCertRefsVerifier.class);
bindBuiltInVerifier(CompleteRevocationRefsData.class, CompleteRevocRefsVerifier.class);
MapBinder<QName, QualifyingPropertyVerifier> unkownElemsBinder = MapBinder.newMapBinder(binder(), QName.class, QualifyingPropertyVerifier.class);
unkownElemsBinder.addBinding(new QName(QualifyingProperty.XADES_XMLNS, CounterSignatureProperty.PROP_NAME)).to(CounterSignatureVerifier.class);
// Verification based on XML elements names.
bind(new TypeLiteral<QualifyingPropertyVerifier<GenericDOMData>>() {
}).to(GenericDOMDataVerifier.class);
// Ensure empty sets when no bindings are defined
Multibinder.newSetBinder(binder(), RawSignatureVerifier.class);
Multibinder.newSetBinder(binder(), CustomSignatureVerifier.class);
Multibinder.newSetBinder(binder(), CustomPropertiesDataObjsStructureVerifier.class);
}
use of xades4j.properties.data.GenericDOMData in project xades4j by luisgoncalves.
the class TestElemDOMVerifier method testVerify.
@Test
public void testVerify() throws Exception {
GenericDOMData propData = new GenericDOMData(testDocument.createElementNS("http://test.generic.dom", "Elem"));
QualifyingPropertyVerificationContext ctx = null;
GenericDOMDataVerifier instance = new GenericDOMDataVerifier(customElemVerifiers);
QualifyingProperty result = instance.verify(propData, ctx);
assertEquals(result.getName(), "Elem");
}
use of xades4j.properties.data.GenericDOMData in project xades4j by luisgoncalves.
the class FromXmlUnknownUnsignedDataObjPropsConv method convertFromObjectTree.
@Override
public void convertFromObjectTree(XmlUnsignedDataObjectPropertiesType xmlProps, QualifyingPropertiesDataCollector propertyDataCollector) throws PropertyUnmarshalException {
for (XmlAnyType xmlUnsignedDtaObjProp : xmlProps.getUnsignedDataObjectProperty()) {
// <xsd:complexType name="UnsignedDataObjectPropertiesType">
// <xsd:sequence>
// <xsd:element name="UnsignedDataObjectProperty" type="AnyType"
// maxOccurs="unbounded"/>
// </xsd:sequence>
// <xsd:attribute name="Id" type="xsd:ID" use="optional"/>
// </xsd:complexType>
//
// I assumed that there is only one "top" element inside UnsignedDataObjectProperty,
// which is the property element. The AnyType schema allows for multiple
// elements but since the UnsignedDataObjectProperty has to be present,
// it makes sense that it has only one child.
List<Element> propElemContent = CollectionUtils.filterByType(xmlUnsignedDtaObjProp.getContent(), Element.class);
if (!this.acceptUnknown)
throw new PropertyUnmarshalException("Unknown properties were found", "Unknown");
if (propElemContent.size() > 1)
throw new PropertyUnmarshalException("Multiple children elements in UnsignedDataObjectProperty", "Unknown");
propertyDataCollector.addGenericDOMData(new GenericDOMData(propElemContent.get(0)));
}
}
use of xades4j.properties.data.GenericDOMData in project xades4j by luisgoncalves.
the class DataGenCounterSig method generatePropertyData.
/*
* XAdES section 7.2.4.2:
* "The content of this property is a XMLDSIG or XAdES signature whose ds:SignedInfo
* MUST contain one ds:Reference element referencing the ds:SignatureValue element
* of the embedding and countersigned XAdES signature. The content of the ds:DigestValue
* in the aforementioned ds:Reference element of the countersignature MUST be the
* base-64 encoded digest of the complete (and canonicalized) ds:SignatureValue
* element (i.e. including the starting and closing tags) of the embedding and
* countersigned XAdES signature."
*/
/* The ds:Reference element described above can be obtained with the default
* XML-DSIG behaviour. We just need to reference the ds:SignatureValue element.
*/
@Override
public PropertyDataObject generatePropertyData(CounterSignatureProperty prop, PropertiesDataGenerationContext ctx) throws PropertyDataGenerationException {
// The element has to be in the document tree for the references to be
// resolved. UGLY WORKAROUND.
Element qPs = DOMHelper.getFirstDescendant(ctx.getTargetXmlSignature().getElement(), QualifyingProperty.XADES_XMLNS, QualifyingProperty.QUALIFYING_PROPS_TAG);
// Create the CounterSignature property element.
Element counterSigElem = ctx.createElementInSignatureDoc("CounterSignature", qPs.getPrefix(), QualifyingProperty.XADES_XMLNS);
qPs.appendChild(counterSigElem);
try {
// Rerence to the ds:SignatureValue element. This assumes that the
// QualifyingProperties are in the signature's document and that the
// SignatureValue element has an Id.
Element sigValueElem = DOMHelper.getFirstDescendant(ctx.getTargetXmlSignature().getElement(), Constants.SignatureSpecNS, Constants._TAG_SIGNATUREVALUE);
String sigValueId = sigValueElem.getAttribute(Constants._ATT_ID);
DataObjectReference sigValueRef = new DataObjectReference('#' + sigValueId).withType(CounterSignatureProperty.COUNTER_SIGNATURE_TYPE_URI);
XadesSigner counterSigner = prop.getCounterSigSigner();
if (null == counterSigner)
throw new PropertyDataGenerationException(prop, "signer not specified");
try {
SignedDataObjects objs = prop.getSignedDataObjectsForCounterSig();
if (null == objs)
objs = new SignedDataObjects();
objs.withSignedDataObject(sigValueRef);
counterSigner.sign(objs, counterSigElem);
} catch (XAdES4jException ex) {
throw new PropertyDataGenerationException(prop, "cannot apply counter signature", ex);
}
} finally {
qPs.removeChild(counterSigElem);
}
return new GenericDOMData(counterSigElem);
}
use of xades4j.properties.data.GenericDOMData in project xades4j by luisgoncalves.
the class TestElemDOMVerifier method testVerifyNoVerifier.
@Test(expected = InvalidPropertyException.class)
public void testVerifyNoVerifier() throws Exception {
GenericDOMData propData = new GenericDOMData(testDocument.createElementNS("http://test.generic.dom", "Elem"));
QualifyingPropertyVerificationContext ctx = null;
GenericDOMDataVerifier instance = new GenericDOMDataVerifier(new HashMap<QName, QualifyingPropertyVerifier>(0));
instance.verify(propData, ctx);
}
Aggregations