use of org.apache.xml.security.signature.XMLSignatureException in project xades4j by luisgoncalves.
the class SignatureUtils method checkSignedPropertiesIncorporation.
static void checkSignedPropertiesIncorporation(Element qualifyingPropsElem, Reference signedPropsRef) throws QualifyingPropertiesIncorporationException {
Element signedPropsElem = DOMHelper.getFirstChildElement(qualifyingPropsElem);
if (signedPropsElem == null || !signedPropsElem.getLocalName().equals(QualifyingProperty.SIGNED_PROPS_TAG) || !signedPropsElem.getNamespaceURI().equals(QualifyingProperty.XADES_XMLNS)) {
throw new QualifyingPropertiesIncorporationException("SignedProperties not found as the first child of QualifyingProperties.");
}
DOMHelper.useIdAsXmlId(signedPropsElem);
// that consists of a hash sign ('#') followed by a fragment"
if (!signedPropsRef.getURI().startsWith("#")) {
throw new QualifyingPropertiesIncorporationException("Only QualifyingProperties in the signature's document are supported");
}
try {
Node sPropsNode = signedPropsRef.getNodesetBeforeFirstCanonicalization().getSubNode();
if (sPropsNode == null || sPropsNode.getNodeType() != Node.ELEMENT_NODE) {
throw new QualifyingPropertiesIncorporationException("The supposed reference over signed properties doesn't cover an element.");
}
// The referenced signed properties element must be the child of qualifying properties.
Element referencedSignedPropsElem = (Element) sPropsNode;
if (referencedSignedPropsElem != signedPropsElem) {
throw new QualifyingPropertiesIncorporationException("The referenced SignedProperties are not contained by the proper QualifyingProperties element");
}
} catch (XMLSignatureException ex) {
throw new QualifyingPropertiesIncorporationException("Cannot get the referenced SignedProperties", ex);
}
}
use of org.apache.xml.security.signature.XMLSignatureException in project xades4j by luisgoncalves.
the class TimeStampDigestInputImpl method addReference.
@Override
public void addReference(Reference r) throws CannotAddDataToDigestInputException {
if (null == r) {
throw new NullPointerException();
}
try {
XMLSignatureInput refData = r.getContentsAfterTransformation();
addToDigestInput(refData, r.getDocument());
} catch (XMLSignatureException ex) {
throw new CannotAddDataToDigestInputException(ex);
}
}
use of org.apache.xml.security.signature.XMLSignatureException in project santuario-java by apache.
the class BaltimoreTest method test_fifteen_enveloping_hmac_sha1_40.
/**
* Method test_fifteen_enveloping_hmac_sha1_40
*
* @throws Exception
*/
@org.junit.Test
public void test_fifteen_enveloping_hmac_sha1_40() throws Exception {
String filename = merlinsDir15 + "signature-enveloping-hmac-sha1-40.xml";
ResourceResolverSpi resolver = new OfflineResolver();
boolean followManifests = false;
byte[] hmacKey = "secret".getBytes(StandardCharsets.US_ASCII);
try {
this.verifyHMAC(filename, resolver, followManifests, hmacKey);
fail("HMACOutputLength Exception not caught");
} catch (RuntimeException ex) {
LOG.error("Verification crashed for " + filename);
throw ex;
} catch (XMLSignatureException ex) {
if (!ex.getMsgID().equals("algorithms.HMACOutputLengthMin")) {
fail(ex.getMessage());
}
}
}
use of org.apache.xml.security.signature.XMLSignatureException in project santuario-java by apache.
the class BaltimoreTest method test_twenty_three_enveloping_hmac_sha1_40.
/**
* Method test_twenty_three_enveloping_hmac_sha1_40
*
* @throws Exception
*/
@org.junit.Test
public void test_twenty_three_enveloping_hmac_sha1_40() throws Exception {
String filename = merlinsDir23 + "signature-enveloping-hmac-sha1-40.xml";
ResourceResolverSpi resolver = new OfflineResolver();
boolean followManifests = false;
byte[] hmacKey = "secret".getBytes(StandardCharsets.US_ASCII);
try {
this.verifyHMAC(filename, resolver, followManifests, hmacKey);
fail("HMACOutputLength Exception not caught");
} catch (RuntimeException ex) {
LOG.error("Verification crashed for " + filename);
throw ex;
} catch (XMLSignatureException ex) {
if (!ex.getMsgID().equals("algorithms.HMACOutputLengthMin")) {
fail(ex.getMessage());
}
}
}
use of org.apache.xml.security.signature.XMLSignatureException in project santuario-java by apache.
the class SignatureAlgorithm method getSignatureAlgorithmSpi.
/**
* Get a SignatureAlgorithmSpi object corresponding to the algorithmURI argument
*/
private static SignatureAlgorithmSpi getSignatureAlgorithmSpi(String algorithmURI) throws XMLSignatureException {
try {
Class<? extends SignatureAlgorithmSpi> implementingClass = algorithmHash.get(algorithmURI);
LOG.debug("Create URI \"{}\" class \"{}\"", algorithmURI, implementingClass);
if (implementingClass == null) {
Object[] exArgs = { algorithmURI };
throw new XMLSignatureException("algorithms.NoSuchAlgorithmNoEx", exArgs);
}
return implementingClass.newInstance();
} catch (IllegalAccessException | InstantiationException | NullPointerException ex) {
Object[] exArgs = { algorithmURI, ex.getMessage() };
throw new XMLSignatureException(ex, "algorithms.NoSuchAlgorithm", exArgs);
}
}
Aggregations