Skip to content

Commit

Permalink
Some #187 follow-up
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Oct 31, 2023
1 parent 1a0d1a9 commit afffefd
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
*/
package com.helger.phase4.profile.bdew;

import java.security.cert.X509Certificate;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.bouncycastle.asn1.x500.RDN;
import org.bouncycastle.asn1.x500.X500Name;
import org.bouncycastle.asn1.x500.style.BCStyle;
import org.bouncycastle.asn1.x500.style.IETFUtils;

import com.helger.commons.ValueEnforcer;
import com.helger.commons.annotation.Nonempty;
import com.helger.commons.error.IError;
Expand Down Expand Up @@ -52,14 +62,6 @@
import com.helger.phase4.profile.IAS4ProfileValidator;
import com.helger.phase4.soap.ESoapVersion;
import com.helger.phase4.wss.EWSSVersion;
import org.bouncycastle.asn1.x500.RDN;
import org.bouncycastle.asn1.x500.X500Name;
import org.bouncycastle.asn1.x500.style.BCStyle;
import org.bouncycastle.asn1.x500.style.IETFUtils;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.security.cert.X509Certificate;

/**
* Validate certain requirements imposed by the BDEW project.
Expand Down Expand Up @@ -118,21 +120,21 @@ private static void _checkIfLegIsValid (@Nonnull final ErrorList aErrorList,
aErrorList.add (_createError (sFieldPrefix + "AddressProtocol is missing"));
}

final PModeLegBusinessInformation aBusinessInfo = aPModeLeg.getBusinessInfo();
final PModeLegBusinessInformation aBusinessInfo = aPModeLeg.getBusinessInfo ();
if (aBusinessInfo == null)
{
aErrorList.add (_createError ("BusinessInfo is missing"));
aErrorList.add (_createError (sFieldPrefix + "BusinessInfo is missing"));
}
else
{
String sService = aBusinessInfo.getService();
if (sService == null || !BDEWPMode.getServices ().contains (sService))
final String sService = aBusinessInfo.getService ();
if (sService == null || !BDEWPMode.containsService (sService))
{
aErrorList.add (_createError (sFieldPrefix + "BusinessInfo.Service '" + sService + "' is unsupported"));
}

String sAction = aBusinessInfo.getAction ();
if (sAction == null || !BDEWPMode.getActions ().contains (sAction))
final String sAction = aBusinessInfo.getAction ();
if (sAction == null || !BDEWPMode.containsAction (sAction))
{
aErrorList.add (_createError (sFieldPrefix + "BusinessInfo.Action '" + sAction + "' is unsupported"));
}
Expand Down Expand Up @@ -194,20 +196,22 @@ private static void _checkIfLegIsValid (@Nonnull final ErrorList aErrorList,
}
else
{
if (!aPModeLegSecurity.getX509EncryptionAlgorithm().equals(ECryptoAlgorithmCrypt.AES_128_GCM)) {
aErrorList.add(_createError(sFieldPrefix +
"Security.X509EncryptionAlgorithm must use the value '" +
ECryptoAlgorithmCrypt.AES_128_GCM.getID() +
"' instead of '" +
aPModeLegSecurity.getX509EncryptionAlgorithm().getID() +
"'"));
if (!aPModeLegSecurity.getX509EncryptionAlgorithm ().equals (ECryptoAlgorithmCrypt.AES_128_GCM))
{
aErrorList.add (_createError (sFieldPrefix +
"Security.X509EncryptionAlgorithm must use the value '" +
ECryptoAlgorithmCrypt.AES_128_GCM.getID () +
"' instead of '" +
aPModeLegSecurity.getX509EncryptionAlgorithm ().getID () +
"'"));
}
}

final Integer nEncryptionMinimumStrength = aPModeLegSecurity.getX509EncryptionMinimumStrength ();
if (nEncryptionMinimumStrength == null || !nEncryptionMinimumStrength.equals(128))
final Integer aEncryptionMinimumStrength = aPModeLegSecurity.getX509EncryptionMinimumStrength ();
if (aEncryptionMinimumStrength == null || aEncryptionMinimumStrength.intValue () != 128)
{
aErrorList.add (_createError (sFieldPrefix + "Security.X509Encryption.MinimalStrength must be defined and set to 128"));
aErrorList.add (_createError (sFieldPrefix +
"Security.X509Encryption.MinimalStrength must be defined and set to 128"));
}

// Check WSS Version = 1.1.1
Expand Down Expand Up @@ -242,7 +246,8 @@ private static void _checkIfLegIsValid (@Nonnull final ErrorList aErrorList,
aErrorList.add (_createError (sFieldPrefix + "Security.PModeAuthorize is missing"));
}

if (!aPModeLegSecurity.isSendReceiptDefined () || !aPModeLegSecurity.isSendReceipt ()) {
if (!aPModeLegSecurity.isSendReceiptDefined () || !aPModeLegSecurity.isSendReceipt ())
{
aErrorList.add (_createError (sFieldPrefix + "Security.SendReceipt must be defined and set to 'true'"));
}
else
Expand All @@ -257,7 +262,7 @@ private static void _checkIfLegIsValid (@Nonnull final ErrorList aErrorList,
EPModeSendReceiptReplyPattern.RESPONSE +
" instead of " +
aPModeLegSecurity.getSendReceiptReplyPattern ()));
}
}
}
else
{
Expand Down Expand Up @@ -355,7 +360,7 @@ public void validatePMode (@Nonnull final IPMode aPMode, @Nonnull final ErrorLis
}

final PModeParty aResponderParty = aPMode.getResponder ();
if (aResponderParty != null && !aResponderParty.getRole().equals (CAS4.DEFAULT_RESPONDER_URL))
if (aResponderParty != null && !aResponderParty.getRole ().equals (CAS4.DEFAULT_RESPONDER_URL))
{
aErrorList.add (_createError ("PMode.Responder.Role must be set to '" + CAS4.DEFAULT_RESPONDER_URL + "'"));
}
Expand Down Expand Up @@ -398,19 +403,21 @@ public void validatePMode (@Nonnull final IPMode aPMode, @Nonnull final ErrorLis
final PModeReceptionAwareness aPModeReceptionAwareness = aPMode.getReceptionAwareness ();
if (aPModeReceptionAwareness != null)
{
if (!aPModeReceptionAwareness.isReceptionAwarenessDefined () || !aPModeReceptionAwareness.isReceptionAwareness ()) {
aErrorList.add(_createError("PMode[1].ReceptionAwareness must be defined and set to 'true'"));
if (!aPModeReceptionAwareness.isReceptionAwarenessDefined () || !aPModeReceptionAwareness.isReceptionAwareness ())
{
aErrorList.add (_createError ("PMode[1].ReceptionAwareness must be defined and set to 'true'"));
}
else
{
if (!aPModeReceptionAwareness.isRetryDefined () || !aPModeReceptionAwareness.isRetry ())
{
aErrorList.add(_createError("PMode[1].ReceptionAwareness.Retry must be defined and set to 'true'"));
aErrorList.add (_createError ("PMode[1].ReceptionAwareness.Retry must be defined and set to 'true'"));
}

if (!aPModeReceptionAwareness.isDuplicateDetectionDefined () || !aPModeReceptionAwareness.isDuplicateDetection ())
if (!aPModeReceptionAwareness.isDuplicateDetectionDefined () ||
!aPModeReceptionAwareness.isDuplicateDetection ())
{
aErrorList.add(_createError("PMode[1].ReceptionAwareness.DuplicateDetection must be defined and set to 'true'"));
aErrorList.add (_createError ("PMode[1].ReceptionAwareness.DuplicateDetection must be defined and set to 'true'"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import javax.annotation.concurrent.Immutable;

import com.helger.commons.annotation.Nonempty;
import com.helger.commons.collection.impl.CommonsHashSet;
import com.helger.commons.collection.impl.ICommonsSet;
import com.helger.commons.state.ETriState;
import com.helger.phase4.CAS4;
import com.helger.phase4.attachment.EAS4CompressionMode;
Expand All @@ -44,8 +46,6 @@
import com.helger.phase4.model.pmode.leg.PModeLegSecurity;
import com.helger.phase4.wss.EWSSVersion;

import java.util.Set;

/**
* PMode creation code.
*
Expand Down Expand Up @@ -75,6 +75,18 @@ public final class BDEWPMode
public static final String ACTION_REQUEST_SWITCH = "https://www.bdew.de/as4/communication/actions/requestSwitch";
public static final String ACTION_CONFIRM_SWITCH = "https://www.bdew.de/as4/communication/actions/confirmSwitch";

private static final ICommonsSet <String> ALL_SERVICES = new CommonsHashSet <> (SERVICE_TEST,
SERVICE_PATH_SWITCH,
SERVICE_MARKTPROZESSE,
SERVICE_FAHRPLAN,
SERVICE_REDISPATCH_2_0,
SERVICE_KWEP,
SERVICE_SOGL);
private static final ICommonsSet <String> ALL_ACTIONS = new CommonsHashSet <> (ACTION_DEFAULT,
ACTION_TEST_SERVICE,
ACTION_REQUEST_SWITCH,
ACTION_CONFIRM_SWITCH);

private BDEWPMode ()
{}

Expand Down Expand Up @@ -215,14 +227,13 @@ public static PMode createBDEWPMode (@Nonnull @Nonempty final String sInitiatorI
return aPMode;
}

public static Set<String> getServices ()
public static boolean containsService (@Nonnull final String sService)
{
return Set.of(SERVICE_TEST, SERVICE_PATH_SWITCH, SERVICE_MARKTPROZESSE, SERVICE_FAHRPLAN,
SERVICE_REDISPATCH_2_0, SERVICE_KWEP, SERVICE_SOGL);
return ALL_SERVICES.contains (sService);
}

public static Set<String> getActions ()
public static boolean containsAction (@Nonnull final String sAction)
{
return Set.of(ACTION_DEFAULT, ACTION_TEST_SERVICE, ACTION_REQUEST_SWITCH, ACTION_CONFIRM_SWITCH);
return ALL_ACTIONS.contains (sAction);
}
}

0 comments on commit afffefd

Please sign in to comment.