use of xades4j.properties.DataObjectDesc in project xades4j by luisgoncalves.
the class DefaultProductionBindingsModule method configure.
@Override
protected void configure() {
// Defaults for configurable components.
bind(SignaturePropertiesProvider.class).to(DefaultSignaturePropertiesProvider.class);
bind(DataObjectPropertiesProvider.class).toInstance(new DataObjectPropertiesProvider() {
@Override
public void provideProperties(DataObjectDesc dataObj) {
// By default no properties are specified for a data object.
}
});
bind(AlgorithmsProviderEx.class).to(DefaultAlgorithmsProviderEx.class);
// Will wrap the AlgorithmsProviderEx in use
bind(AlgorithmsProvider.class).to(AlgorithmsProvider_ExToDeprecated_Adapter.class);
bind(BasicSignatureOptionsProvider.class).to(DefaultBasicSignatureOptionsProvider.class);
bind(MessageDigestEngineProvider.class).to(DefaultMessageDigestProvider.class);
bind(TimeStampTokenProvider.class).to(HttpTimeStampTokenProvider.class);
// Backwards compatibility
bind(TSAHttpData.class).toInstance(new TSAHttpData("http://tss.accv.es:8318/tsa"));
// PropertiesDataObjectsGenerator is not configurable but the individual
// generators may have dependencies.
bind(PropertiesDataObjectsGenerator.class).to(PropertiesDataObjectsGeneratorImpl.class);
bind(PropertyDataGeneratorsMapper.class).to(PropertyDataGeneratorsMapperImpl.class);
// Ensure empty set when no bindings are defined
Multibinder.newSetBinder(binder(), CustomPropertiesDataObjsStructureVerifier.class);
// PropertyDataGeneratorsMapperImpl relies on the injector to get
// the individual generators, so they need to be bound.
// - SignedSignatureProperties
bind(new TypeLiteral<PropertyDataObjectGenerator<SigningTimeProperty>>() {
}).to(DataGenSigningTime.class);
bind(new TypeLiteral<PropertyDataObjectGenerator<SignerRoleProperty>>() {
}).to(DataGenSignerRole.class);
bind(new TypeLiteral<PropertyDataObjectGenerator<SigningCertificateProperty>>() {
}).to(DataGenSigningCertificate.class);
bind(new TypeLiteral<PropertyDataObjectGenerator<SignatureProductionPlaceProperty>>() {
}).to(DataGenSigProdPlace.class);
bind(new TypeLiteral<PropertyDataObjectGenerator<SignaturePolicyIdentifierProperty>>() {
}).to(DataGenSigPolicy.class);
bind(new TypeLiteral<PropertyDataObjectGenerator<SignaturePolicyImpliedProperty>>() {
}).to(DataGenSigPolicyImplied.class);
// - SignedDataObjectProperties
bind(new TypeLiteral<PropertyDataObjectGenerator<DataObjectFormatProperty>>() {
}).to(DataGenDataObjFormat.class);
bind(new TypeLiteral<PropertyDataObjectGenerator<CommitmentTypeProperty>>() {
}).to(DataGenCommitmentType.class);
bind(new TypeLiteral<PropertyDataObjectGenerator<AllDataObjsCommitmentTypeProperty>>() {
}).to(DataGenCommitmentTypeAllDataObjs.class);
bind(new TypeLiteral<PropertyDataObjectGenerator<IndividualDataObjsTimeStampProperty>>() {
}).to(DataGenIndivDataObjsTimeStamp.class);
bind(new TypeLiteral<PropertyDataObjectGenerator<AllDataObjsTimeStampProperty>>() {
}).to(DataGenAllDataObjsTimeStamp.class);
// - UnsignedSignatureProperties
bind(new TypeLiteral<PropertyDataObjectGenerator<CounterSignatureProperty>>() {
}).to(DataGenCounterSig.class);
bind(new TypeLiteral<PropertyDataObjectGenerator<SignatureTimeStampProperty>>() {
}).to(DataGenSigTimeStamp.class);
bind(new TypeLiteral<PropertyDataObjectGenerator<CompleteCertificateRefsProperty>>() {
}).to(DataGenCompleteCertRefs.class);
bind(new TypeLiteral<PropertyDataObjectGenerator<CompleteRevocationRefsProperty>>() {
}).to(DataGenCompleteRevocRefs.class);
bind(new TypeLiteral<PropertyDataObjectGenerator<SigAndRefsTimeStampProperty>>() {
}).to(DataGenSigAndRefsTimeStamp.class);
bind(new TypeLiteral<PropertyDataObjectGenerator<CertificateValuesProperty>>() {
}).to(DataGenCertificateValues.class);
bind(new TypeLiteral<PropertyDataObjectGenerator<RevocationValuesProperty>>() {
}).to(DataGenRevocationValues.class);
bind(new TypeLiteral<PropertyDataObjectGenerator<ArchiveTimeStampProperty>>() {
}).to(DataGenArchiveTimeStamp.class);
}
use of xades4j.properties.DataObjectDesc in project xades4j by luisgoncalves.
the class Enveloped method sign.
/**
* Creates an enveloped signature over an element. The element must have an
* Id or be the document root if it doesn't. In the last case an empty (URI="")
* reference is used.
*
* @param elementToSign the element that will be signed and will be the signature's parent
*
* @throws XAdES4jException see {@link XadesSigner#sign(xades4j.production.SignedDataObjects, org.w3c.dom.Node)}
* @throws IllegalArgumentException if {@code elementToSign} doesn't have an Id and isn't the document root
*/
public void sign(Element elementToSign) throws XAdES4jException {
String refUri;
if (elementToSign.hasAttribute("Id"))
refUri = '#' + elementToSign.getAttribute("Id");
else {
if (elementToSign.getParentNode().getNodeType() != Node.DOCUMENT_NODE)
throw new IllegalArgumentException("Element without Id must be the document root");
refUri = "";
}
DataObjectDesc dataObjRef = new DataObjectReference(refUri).withTransform(new EnvelopedSignatureTransform());
signer.sign(new SignedDataObjects(dataObjRef), elementToSign);
}
use of xades4j.properties.DataObjectDesc in project xades4j by luisgoncalves.
the class QualifyingPropertiesProcessor method getQualifyingProperties.
QualifyingProperties getQualifyingProperties(SignedDataObjects dataObjs, Collection<SignedSignatureProperty> formatSpecificSignedSigProps, Collection<UnsignedSignatureProperty> formatSpecificUnsignedSigProps) {
/* **** Signature properties **** */
// Collect the signature properties from the provider.
SignaturePropertiesCollectorImpl signaturePropsCollector = new SignaturePropertiesCollectorImpl();
sigPropsProvider.provideProperties(signaturePropsCollector);
Collection<SignedSignatureProperty> collectedSignedSigProps = signaturePropsCollector.getSignedSigProps();
Collection<SignedSignatureProperty> signedSigProps = new ArrayList<SignedSignatureProperty>(collectedSignedSigProps.size() + formatSpecificSignedSigProps.size());
signedSigProps.addAll(collectedSignedSigProps);
signedSigProps.addAll(formatSpecificSignedSigProps);
Collection<UnsignedSignatureProperty> collectedUnsignedSigProps = signaturePropsCollector.getUnsignedSigProps();
Collection<UnsignedSignatureProperty> unsignedSigProps = new ArrayList<UnsignedSignatureProperty>(collectedUnsignedSigProps.size() + formatSpecificUnsignedSigProps.size());
unsignedSigProps.addAll(collectedUnsignedSigProps);
unsignedSigProps.addAll(formatSpecificUnsignedSigProps);
/* **** Data objects properties **** */
Collection<DataObjectDesc> dataObjsInfo = dataObjs.getDataObjectsDescs();
// The containers for all the specified signed data object properties. Since
// some properties can be applied to multiple data objects, we need to rule
// out repeated references (a Set is used).
Set<SignedDataObjectProperty> signedDataObjProps = new HashSet<SignedDataObjectProperty>(dataObjsInfo.size());
Set<UnsignedDataObjectProperty> unsignedDataObjProps = new HashSet<UnsignedDataObjectProperty>(0);
// Add the global data object properties.
signedDataObjProps.addAll(dataObjs.getSignedDataObjsProperties());
unsignedDataObjProps.addAll(dataObjs.getUnsignedDataObjsProperties());
// Add the properties specified for each data object.
for (DataObjectDesc dataObjInfo : dataObjsInfo) {
// If no properties were specified allow the provider to add them.
if (!dataObjInfo.hasProperties())
this.dataObjPropsProvider.provideProperties(dataObjInfo);
signedDataObjProps.addAll(dataObjInfo.getSignedDataObjProps());
unsignedDataObjProps.addAll(dataObjInfo.getUnsignedDataObjProps());
}
return new QualifyingProperties(new SignedProperties(signedSigProps, signedDataObjProps), new UnsignedProperties(unsignedSigProps, unsignedDataObjProps));
}
use of xades4j.properties.DataObjectDesc in project xades4j by luisgoncalves.
the class DataGenIndivDataObjsTimeStamp method createPropDataObj.
@Override
protected BaseXAdESTimeStampData createPropDataObj(IndividualDataObjsTimeStampProperty prop, Algorithm c14n, TimeStampTokenRes tsTknRes, PropertiesDataGenerationContext ctx) {
Collection<DataObjectDesc> targetDataObjs = prop.getTargetDataObjects();
Map<DataObjectDesc, Reference> refsMaps = ctx.getReferencesMappings();
List<String> includes = new ArrayList<String>(targetDataObjs.size());
for (DataObjectDesc dataObj : targetDataObjs) {
Reference r = refsMaps.get(dataObj);
includes.add('#' + r.getId());
}
prop.setTime(tsTknRes.timeStampTime);
return new IndividualDataObjsTimeStampData(c14n, includes, tsTknRes.encodedTimeStampToken);
}
use of xades4j.properties.DataObjectDesc in project xades4j by luisgoncalves.
the class OtherSignerTests method testSignAndAppendAsFirstChild.
@Test
public void testSignAndAppendAsFirstChild() throws Exception {
System.out.println("signAndAppendAsFirstChild");
Document doc = getTestDocument();
Element root = doc.getDocumentElement();
XadesSigner signer = new XadesBesSigningProfile(keyingProviderMy).newSigner();
DataObjectDesc obj1 = new DataObjectReference('#' + root.getAttribute("Id")).withTransform(new EnvelopedSignatureTransform());
SignedDataObjects dataObjs = new SignedDataObjects(obj1);
signer.sign(dataObjs, root, SignatureAppendingStrategies.AsFirstChild);
Element firstChild = (Element) doc.getDocumentElement().getFirstChild();
assertEquals(Constants._TAG_SIGNATURE, firstChild.getLocalName());
assertEquals(Constants.SignatureSpecNS, firstChild.getNamespaceURI());
}
Aggregations