Skip to content

Commit

Permalink
Merge branch 'phax:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
mmwlk authored Jun 23, 2023
2 parents 5c177dd + 5a8e6f1 commit 441c4b7
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 8 deletions.
Binary file added docs/DE/2022-09-01 AS4-Profil_final.pdf
Binary file not shown.
Binary file added docs/DE/2022-12-06 BSI-TR-03116-3.pdf
Binary file not shown.
Binary file added docs/DE/2023-05-12 AS4-Profil.pdf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@
*/
package com.helger.phase4.bdew;

import java.security.GeneralSecurityException;

import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;

import org.apache.hc.core5.util.Timeout;

import com.helger.commons.ws.TrustManagerTrustAll;
import com.helger.http.tls.ETLSVersion;
import com.helger.http.tls.TLSConfigurationMode;
import com.helger.httpclient.HttpClientSettings;
import com.helger.phase4.CAS4;
import com.helger.phase4.CAS4Version;
import org.apache.hc.core5.util.Timeout;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import java.security.GeneralSecurityException;

/**
* Special {@link HttpClientSettings} with better defaults for BDEW.
Expand All @@ -41,15 +45,34 @@ public class Phase4BDEWHttpClientSettings extends HttpClientSettings
public static final Timeout DEFAULT_BDEW_CONNECT_TIMEOUT = Timeout.ofSeconds (5);
public static final Timeout DEFAULT_BDEW_RESPONSE_TIMEOUT = Timeout.ofSeconds (100);

public Phase4BDEWHttpClientSettings() throws GeneralSecurityException
public Phase4BDEWHttpClientSettings () throws GeneralSecurityException
{
// BDEW recommends at least TLS v1.2 [TR02102-2]
final SSLContext aSSLContext = SSLContext.getInstance (ETLSVersion.TLS_12.getID ());

// TODO - trust store is required for mutual TLS (Spec section 2.2.6.1)
// But we're basically trusting all hosts - the exact list is hard to
// determine
aSSLContext.init (null, new TrustManager [] { new TrustManagerTrustAll (false) }, null);
aSSLContext.init ((KeyManager []) null, new TrustManager [] { new TrustManagerTrustAll (false) }, null);
setSSLContext (aSSLContext);

// Cipher Suite follow BSI TR03116-3, section 4 as of 2022-12-06
final TLSConfigurationMode aTLSConfigMode = new TLSConfigurationMode (new ETLSVersion [] { ETLSVersion.TLS_12,
ETLSVersion.TLS_13 },
new String [] {
// TLS
// 1.3
"TLS_AES_128_GCM_SHA256",
"TLS_AES_256_GCM_SHA384",
"TLS_AES_128_CCM_SHA256",
// TLS
// 1.2
"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256",
"TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384",
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384" });
setTLSConfigurationMode (aTLSConfigMode);

setConnectionRequestTimeout (DEFAULT_BDEW_CONNECTION_REQUEST_TIMEOUT);
setConnectTimeout (DEFAULT_BDEW_CONNECT_TIMEOUT);
setResponseTimeout (DEFAULT_BDEW_RESPONSE_TIMEOUT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.helger.phase4.attachment.AS4OutgoingAttachment;
import com.helger.phase4.attachment.WSS4JAttachment;
import com.helger.phase4.client.AS4ClientUserMessage;
import com.helger.phase4.crypto.ECryptoAlgorithmC14N;
import com.helger.phase4.crypto.ECryptoKeyEncryptionAlgorithm;
import com.helger.phase4.crypto.ECryptoKeyIdentifierType;
import com.helger.phase4.sender.AS4BidirectionalClientHelper;
Expand Down Expand Up @@ -78,6 +79,7 @@ public abstract static class AbstractBDEWUserMessageBuilder <IMPLTYPE extends Ab
extends
AbstractAS4UserMessageBuilder <IMPLTYPE>
{
// Default per section 2.2.6.2.1
public static final ECryptoKeyIdentifierType DEFAULT_KEY_IDENTIFIER_TYPE = ECryptoKeyIdentifierType.BST_DIRECT_REFERENCE;

private ECryptoKeyIdentifierType m_eSigningKeyIdentifierType;
Expand Down Expand Up @@ -193,9 +195,20 @@ protected final void mainSendMessage () throws Phase4Exception
final AS4ClientUserMessage aUserMsg = new AS4ClientUserMessage (aResHelper);
applyToUserMessage (aUserMsg);

// Other crypt parameters are located in the PMode security part
aUserMsg.cryptParams ().setKeyEncAlgorithm (ECryptoKeyEncryptionAlgorithm.ECDH_ES_KEYWRAP_AES_128);
aUserMsg.cryptParams ().setKeyIdentifierType (m_eEncryptionKeyIdentifierType);

// See BDEW specs 2.2.6.2
// Other signing parameters are located in the PMode security part
aUserMsg.signingParams ().setAlgorithmC14N (ECryptoAlgorithmC14N.C14N_EXCL_OMIT_COMMENTS);
aUserMsg.signingParams ().setKeyIdentifierType (m_eSigningKeyIdentifierType);
/**
* Assumption: the BST "ValueType" attribute is set to
* "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1"
* by WSS4J automatically (see WSSecSignature#addBST)
*/

// Empty string by purpose
aUserMsg.setConversationID ("");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public enum ECryptoKeyEncryptionAlgorithm implements IHasID <String>
RSA_OAEP (WSS4JConstants.KEYTRANSPORT_RSAOAEP),
RSA_OAEP_XENC11 (WSS4JConstants.KEYTRANSPORT_RSAOAEP_XENC11),

// ECDH-ES KEYWRAP are currently not yet supported by WSS4J 3.0.0
// TODO ECDH-ES KEYWRAP are currently not yet supported by WSS4J 3.0.0
ECDH_ES_KEYWRAP_AES_128 ("http://www.w3.org/2001/04/xmlenc#kw-aes128"),
ECDH_ES_KEYWRAP_AES_192 ("http://www.w3.org/2001/04/xmlenc#kw-aes192"),
ECDH_ES_KEYWRAP_AES_256 ("http://www.w3.org/2001/04/xmlenc#kw-aes256");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private static WSSecEncrypt _createEncrypt (@Nonnull final WSSecHeader aSecHeade
aBuilder.setDigestAlgorithm (aCryptParams.getDigestAlgorithm ());
// Encrypted key must be contained
aBuilder.setEncryptSymmKey (true);

if (aCryptParams.hasCertificate ())
{
// Certificate was provided externally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ private static Document _createSignedMessage (@Nonnull final IAS4CryptoFactory a
aBuilder.setDigestAlgo (aSigningParams.getAlgorithmSignDigest ().getAlgorithmURI ());
aBuilder.setSigCanonicalization (aSigningParams.getAlgorithmC14N ().getAlgorithmURI ());

// true: BST ValueType "#X509v3" (the default)
// false: BST ValueType "#X509PKIPathv1" (e.g. for BDEW)
aBuilder.setUseSingleCertificate (false);

// Sign the Ebms3 Messaging element itself
aBuilder.getParts ().add (new WSEncryptionPart (sMessagingID, ENCRYPTION_MODE_CONTENT));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ public static PModeLegSecurity generatePModeLegSecurity ()
final PModeLegSecurity aPModeLegSecurity = new PModeLegSecurity ();
aPModeLegSecurity.setWSSVersion (EWSSVersion.WSS_111);
aPModeLegSecurity.setX509SignatureAlgorithm (ECryptoAlgorithmSign.ECDSA_SHA_256);
// Curve to use: "brainpoolP256r1"
// Source: BSI TR03116-3, section 9.1
// Required by: BDEW AS4 profile section 2.2.6.2.1
aPModeLegSecurity.setX509SignatureHashFunction (ECryptoAlgorithmSignDigest.DIGEST_SHA_256);
aPModeLegSecurity.setX509EncryptionAlgorithm (ECryptoAlgorithmCrypt.AES_128_GCM);
aPModeLegSecurity.setX509EncryptionMinimumStrength (Integer.valueOf (128));
Expand Down

0 comments on commit 441c4b7

Please sign in to comment.