use of xades4j.algorithms.GenericAlgorithm in project xades4j by luisgoncalves.
the class FromXmlBaseTimeStampConverter method convertTimeStamps.
protected void convertTimeStamps(List<XmlXAdESTimeStampType> xmlTimeStamps, QualifyingPropertiesDataCollector propertyDataCollector) throws PropertyUnmarshalException {
if (null == xmlTimeStamps || xmlTimeStamps.isEmpty())
return;
for (XmlXAdESTimeStampType xmlTS : xmlTimeStamps) {
if (!xmlTS.getReferenceInfo().isEmpty())
throw new PropertyUnmarshalException("ReferenceInfo is not supported in XAdESTimeStamp", propName);
Algorithm c14n;
XmlCanonicalizationMethodType xmlCanonMethod = xmlTS.getCanonicalizationMethod();
if (null == xmlCanonMethod) {
c14n = new GenericAlgorithm(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
} else {
List params = CollectionUtils.filterByType(xmlCanonMethod.getContent(), Element.class);
c14n = new GenericAlgorithm(xmlCanonMethod.getAlgorithm(), params);
}
TPropData tsData = createTSData(c14n);
List<Object> tsTokens = xmlTS.getEncapsulatedTimeStampOrXMLTimeStamp();
if (tsTokens.isEmpty())
throw new PropertyUnmarshalException("No time-stamp tokens", propName);
for (Object tkn : tsTokens) {
if (!(tkn instanceof XmlEncapsulatedPKIDataType))
throw new PropertyUnmarshalException("XML time-stamps are not supported", propName);
tsData.addTimeStampToken(((XmlEncapsulatedPKIDataType) tkn).getValue());
}
doSpecificConvert(xmlTS, tsData);
setTSData(tsData, propertyDataCollector);
}
}
use of xades4j.algorithms.GenericAlgorithm in project xades4j by luisgoncalves.
the class SignatureUtils method processReferences.
static ReferencesRes processReferences(XMLSignature signature) throws QualifyingPropertiesIncorporationException, XAdES4jXMLSigException {
SignedInfo signedInfo = signature.getSignedInfo();
List<RawDataObjectDesc> dataObjsReferences = new ArrayList<RawDataObjectDesc>(signedInfo.getLength() - 1);
Reference signedPropsRef = null;
for (int i = 0; i < signedInfo.getLength(); i++) {
Reference ref;
try {
ref = signedInfo.item(i);
} catch (XMLSecurityException ex) {
throw new XAdES4jXMLSigException(String.format("Cannot process the %dth reference", i), ex);
}
String refTypeUri = ref.getType();
// with its value set to: http://uri.etsi.org/01903#SignedProperties."
if (QualifyingProperty.SIGNED_PROPS_TYPE_URI.equals(refTypeUri)) {
if (signedPropsRef != null) {
throw new QualifyingPropertiesIncorporationException("Multiple references to SignedProperties");
}
signedPropsRef = ref;
} else {
RawDataObjectDesc dataObj = new RawDataObjectDesc(ref);
dataObjsReferences.add(dataObj);
try {
Transforms transfs = ref.getTransforms();
if (transfs != null) {
for (int j = 0; j < transfs.getLength(); ++j) {
dataObj.withTransform(new GenericAlgorithm(transfs.item(j).getURI()));
}
}
} catch (XMLSecurityException ex) {
throw new XAdES4jXMLSigException("Cannot process transfroms", ex);
}
}
}
if (null == signedPropsRef) // !!!
// Still may be a XAdES signature, if the signing certificate is
// protected. For now, that scenario is not supported.
{
throw new QualifyingPropertiesIncorporationException("SignedProperties reference not found");
}
return new ReferencesRes(dataObjsReferences, signedPropsRef);
}
use of xades4j.algorithms.GenericAlgorithm in project xades4j by luisgoncalves.
the class DataObjectDescTest method testWithTransform.
@Test
public void testWithTransform() throws Exception {
System.out.println("withTransform");
Document doc = SignatureServicesTestBase.getNewDocument();
DataObjectDesc instance = new DataObjectDescTestImpl().withTransform(new XPathTransform("xpath")).withTransform(XPath2Filter.subtract("xpath1").intersect("xpath2")).withTransform(new GenericAlgorithm("uri", doc.createElement("param1"), doc.createElement("param2")));
Algorithm[] transforms = instance.getTransforms().toArray(new Algorithm[0]);
assertEquals(3, transforms.length);
assertEquals(XPathTransform.class, transforms[0].getClass());
assertEquals(XPath2FilterTransform.class, transforms[1].getClass());
assertEquals(GenericAlgorithm.class, transforms[2].getClass());
}
Aggregations