use of org.apache.xml.security.signature.XMLSignatureException in project santuario-java by apache.
the class X509IssuerSerialResolver method engineLookupResolveX509Certificate.
/**
* {@inheritDoc}
*/
public X509Certificate engineLookupResolveX509Certificate(Element element, String baseURI, StorageResolver storage) throws KeyResolverException {
LOG.debug("Can I resolve {}?", element.getTagName());
X509Data x509data = null;
try {
x509data = new X509Data(element, baseURI);
} catch (XMLSignatureException ex) {
LOG.debug("I can't");
return null;
} catch (XMLSecurityException ex) {
LOG.debug("I can't");
return null;
}
if (!x509data.containsIssuerSerial()) {
return null;
}
try {
if (storage == null) {
Object[] exArgs = { Constants._TAG_X509ISSUERSERIAL };
KeyResolverException ex = new KeyResolverException("KeyResolver.needStorageResolver", exArgs);
LOG.debug("", ex);
throw ex;
}
int noOfISS = x509data.lengthIssuerSerial();
Iterator<Certificate> storageIterator = storage.getIterator();
while (storageIterator.hasNext()) {
X509Certificate cert = (X509Certificate) storageIterator.next();
XMLX509IssuerSerial certSerial = new XMLX509IssuerSerial(element.getOwnerDocument(), cert);
LOG.debug("Found Certificate Issuer: {}", certSerial.getIssuerName());
LOG.debug("Found Certificate Serial: {}", certSerial.getSerialNumber().toString());
for (int i = 0; i < noOfISS; i++) {
XMLX509IssuerSerial xmliss = x509data.itemIssuerSerial(i);
LOG.debug("Found Element Issuer: {}", xmliss.getIssuerName());
LOG.debug("Found Element Serial: {}", xmliss.getSerialNumber().toString());
if (certSerial.equals(xmliss)) {
LOG.debug("match !!! ");
return cert;
}
LOG.debug("no match...");
}
}
return null;
} catch (XMLSecurityException ex) {
LOG.debug("XMLSecurityException", ex);
throw new KeyResolverException(ex);
}
}
use of org.apache.xml.security.signature.XMLSignatureException in project santuario-java by apache.
the class IAIKTest method test_signatureAlgorithms_signatures_hMACShortSignature.
/**
* Method test_signatureAlgorithms_signatures_hMACShortSignature
*
* @throws Exception
*/
@org.junit.Test
public void test_signatureAlgorithms_signatures_hMACShortSignature() throws Exception {
String filename = gregorsDir + "signatureAlgorithms/signatures/hMACShortSignature.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 Bug45961Test method testBug.
@org.junit.Test
public void testBug() throws Exception {
Document document = getSignedDocument();
NodeList list = document.getElementsByTagNameNS(Constants.SignatureSpecNS, Constants._TAG_SIGNATURE);
Element element = (Element) list.item(0);
XMLSignature signature = new XMLSignature(element, null);
KeyInfo keyInfo = signature.getKeyInfo();
X509Certificate certificate = keyInfo.getX509Certificate();
assertNotNull(certificate);
try {
signature.checkSignatureValue(certificate);
} catch (XMLSignatureException e) {
fail(e.getMessage());
}
}
Aggregations