use of com.helger.as2lib.exception.AS2Exception in project as2-peppol-servlet by phax.
the class AS2ServletSBDModule method _checkIfReceiverEndpointURLMatches.
private static void _checkIfReceiverEndpointURLMatches(@Nonnull final String sLogPrefix, @Nonnull final EndpointType aRecipientEndpoint) throws AS2Exception {
// Get our public endpoint address from the configuration
final String sOwnAPUrl = AS2PeppolServletConfiguration.getAS2EndpointURL();
if (StringHelper.hasNoText(sOwnAPUrl))
throw new AS2Exception(sLogPrefix + "The endpoint URL of this AP is not configured!");
if (LOGGER.isDebugEnabled())
LOGGER.debug(sLogPrefix + "Our AP URL is " + sOwnAPUrl);
final String sRecipientAPUrl = SMPClientReadOnly.getEndpointAddress(aRecipientEndpoint);
if (LOGGER.isDebugEnabled())
LOGGER.debug(sLogPrefix + "Recipient AP URL is " + sRecipientAPUrl);
// Is it for us?
if (sRecipientAPUrl == null || !sRecipientAPUrl.contains(sOwnAPUrl)) {
final String sErrorMsg = sLogPrefix + " Internal error: The request is targeted for '" + sRecipientAPUrl + "' and is not for us (" + sOwnAPUrl + ")";
LOGGER.error(sErrorMsg);
throw new AS2Exception(sErrorMsg);
}
}
use of com.helger.as2lib.exception.AS2Exception in project as2-peppol-servlet by phax.
the class AS2ServletSBDModule method _checkIfEndpointCertificateMatches.
private static void _checkIfEndpointCertificateMatches(@Nonnull final String sLogPrefix, @Nonnull final EndpointType aRecipientEndpoint) throws AS2Exception {
final X509Certificate aOurCert = AS2PeppolServletConfiguration.getAPCertificate();
if (aOurCert == null)
throw new AS2Exception(sLogPrefix + "The certificate of this AP is not configured!");
final String sRecipientCertString = aRecipientEndpoint.getCertificate();
X509Certificate aRecipientCert = null;
try {
aRecipientCert = CertificateHelper.convertStringToCertficate(sRecipientCertString);
} catch (final CertificateException t) {
throw new AS2Exception(sLogPrefix + "Internal error: Failed to convert looked up endpoint certificate string '" + sRecipientCertString + "' to an X.509 certificate!", t);
}
if (aRecipientCert == null) {
// No certificate found - most likely because of invalid SMP entry
throw new AS2Exception(sLogPrefix + "No certificate found in looked up endpoint! Is this AP maybe NOT contained in an SMP?");
}
// Certificate found
if (LOGGER.isDebugEnabled())
LOGGER.debug(sLogPrefix + "Conformant recipient certificate present: " + aRecipientCert.toString());
// Compare serial numbers
if (!aOurCert.getSerialNumber().equals(aRecipientCert.getSerialNumber())) {
final String sErrorMsg = sLogPrefix + "Certificate retrieved from SMP lookup (" + aRecipientCert + ") does not match this APs configured Certificate (" + aOurCert + ") - different serial numbers - ignoring document";
LOGGER.error(sErrorMsg);
throw new AS2Exception(sErrorMsg);
}
if (LOGGER.isDebugEnabled())
LOGGER.debug(sLogPrefix + "The certificate of the SMP lookup matches our certificate");
}
Aggregations