use of xades4j.properties.SignaturePolicyIdentifierProperty 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.SignaturePolicyIdentifierProperty in project xades4j by luisgoncalves.
the class SignerEPESTest method testSignEPES.
@Test
public void testSignEPES() throws Exception {
System.out.printf("signEPES: %s", locationUrl);
System.out.println();
Document doc = getTestDocument();
Element elemToSign = doc.getDocumentElement();
SignaturePolicyInfoProvider policyInfoProvider = new SignaturePolicyInfoProvider() {
@Override
public SignaturePolicyBase getSignaturePolicy() {
return new SignaturePolicyIdentifierProperty(new ObjectIdentifier("oid:/1.2.4.0.9.4.5", IdentifierType.OIDAsURI, "Policy description"), new ByteArrayInputStream("Test policy input stream".getBytes())).withLocationUrl(locationUrl);
}
};
SignerEPES signer = (SignerEPES) new XadesEpesSigningProfile(keyingProviderMy, policyInfoProvider).newSigner();
new Enveloped(signer).sign(elemToSign);
outputDocument(doc, output);
}
use of xades4j.properties.SignaturePolicyIdentifierProperty in project xades4j by luisgoncalves.
the class SignaturePolicyVerifier method verify.
@Override
public QualifyingProperty verify(SignaturePolicyData propData, QualifyingPropertyVerificationContext ctx) throws SignaturePolicyVerificationException {
ObjectIdentifier policyId = propData.getIdentifier();
if (null == policyId) {
return new SignaturePolicyImpliedProperty();
}
// Get the policy document
InputStream sigDocStream = this.policyDocumentProvider.getSignaturePolicyDocumentStream(policyId);
if (null == sigDocStream) {
throw new SignaturePolicyNotAvailableException(policyId, null);
}
try {
MessageDigest md = this.messageDigestProvider.getEngine(propData.getDigestAlgorithm());
byte[] sigDocDigest = MessageDigestUtils.digestStream(md, sigDocStream);
// Check the document digest.
if (!Arrays.equals(sigDocDigest, propData.getDigestValue())) {
throw new SignaturePolicyDigestMismatchException(policyId);
}
return new SignaturePolicyIdentifierProperty(policyId, sigDocStream).withLocationUrl(propData.getLocationUrl());
} catch (IOException ex) {
throw new SignaturePolicyNotAvailableException(policyId, ex);
} catch (UnsupportedAlgorithmException ex) {
throw new SignaturePolicyCannotDigestException(policyId, ex);
} finally {
try {
sigDocStream.close();
} catch (IOException ex) {
throw new SignaturePolicyNotAvailableException(policyId, ex);
}
}
}
Aggregations