use of xades4j.properties.ObjectIdentifier 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.ObjectIdentifier in project xades4j by luisgoncalves.
the class SignaturePolicyDataStructureVerifier method verifyStructure.
@Override
public void verifyStructure(PropertyDataObject propData) throws PropertyDataStructureException {
SignaturePolicyData sigPolicyData = (SignaturePolicyData) propData;
String alg = sigPolicyData.getDigestAlgorithm();
byte[] dig = sigPolicyData.getDigestValue();
ObjectIdentifier id = sigPolicyData.getIdentifier();
if (!ObjectUtils.allNull(alg, dig, id) && ObjectUtils.anyNull(alg, dig, id))
throw new PropertyDataStructureException("all the properties must be specified", SignaturePolicyIdentifierProperty.PROP_NAME);
}
use of xades4j.properties.ObjectIdentifier 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.ObjectIdentifier 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);
}
}
}
use of xades4j.properties.ObjectIdentifier in project xades4j by luisgoncalves.
the class ToXmlDataObjectFormatConverter method getXmlObjId.
private XmlObjectIdentifierType getXmlObjId(DataObjectFormatData dataObjFormatData) {
ObjectIdentifier identifier = dataObjFormatData.getIdentifier();
if (null == identifier)
return null;
XmlObjectIdentifierType xmlObjId = ToXmlUtils.getXmlObjectId(identifier);
// Documentation references
Collection<String> docsUris = dataObjFormatData.getDocumentationUris();
if (docsUris != null && !docsUris.isEmpty()) {
XmlDocumentationReferencesType docRefs = new XmlDocumentationReferencesType();
docRefs.getDocumentationReference().addAll(docsUris);
xmlObjId.setDocumentationReferences(docRefs);
}
return xmlObjId;
}
Aggregations