Search in sources :

Example 41 with AS2Exception

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);
    }
}
Also used : AS2Exception(com.helger.as2lib.exception.AS2Exception) WrappedAS2Exception(com.helger.as2lib.exception.WrappedAS2Exception)

Example 42 with AS2Exception

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");
}
Also used : AS2Exception(com.helger.as2lib.exception.AS2Exception) WrappedAS2Exception(com.helger.as2lib.exception.WrappedAS2Exception) CertificateException(java.security.cert.CertificateException) X509Certificate(java.security.cert.X509Certificate)

Aggregations

AS2Exception (com.helger.as2lib.exception.AS2Exception)42 WrappedAS2Exception (com.helger.as2lib.exception.WrappedAS2Exception)23 IOException (java.io.IOException)16 IMicroElement (com.helger.xml.microdom.IMicroElement)8 Nonnull (javax.annotation.Nonnull)8 AS2DispositionException (com.helger.as2lib.disposition.AS2DispositionException)7 AS2NoModuleException (com.helger.as2lib.processor.AS2NoModuleException)7 File (java.io.File)7 MimeBodyPart (javax.mail.internet.MimeBodyPart)7 AS2ComponentNotFoundException (com.helger.as2lib.session.AS2ComponentNotFoundException)6 X509Certificate (java.security.cert.X509Certificate)6 MessagingException (javax.mail.MessagingException)6 ICertificateFactory (com.helger.as2lib.cert.ICertificateFactory)5 IMicroDocument (com.helger.xml.microdom.IMicroDocument)5 InputStream (java.io.InputStream)5 SMIMEException (org.bouncycastle.mail.smime.SMIMEException)5 AS2InvalidParameterException (com.helger.as2lib.params.AS2InvalidParameterException)4 Partnership (com.helger.as2lib.partner.Partnership)4 AS2ProcessorException (com.helger.as2lib.processor.AS2ProcessorException)4 ETriState (com.helger.commons.state.ETriState)4