@@ -56,6 +56,13 @@ public class AS4CryptParams implements ICloneable <AS4CryptParams>
5656 public static final ICryptoSessionKeyProvider DEFAULT_SESSION_KEY_PROVIDER = ICryptoSessionKeyProvider .INSTANCE_RANDOM_AES_128 ;
5757 public static final boolean DEFAULT_ENCRYPT_SYMMETRIC_SESSION_KEY = true ;
5858
59+ /**
60+ * HKDF PRF algorithm URI for HMAC-SHA256, as required by eDelivery AS4 2.0
61+ *
62+ * @since 4.4.0
63+ */
64+ public static final String HKDF_PRF_HMAC_SHA256 = WSS4JConstants .HMAC_SHA256 ;
65+
5966 private static final Logger LOGGER = Phase4LoggerFactory .getLogger (AS4CryptParams .class );
6067
6168 // The key identifier type to use
@@ -68,6 +75,14 @@ public class AS4CryptParams implements ICloneable <AS4CryptParams>
6875 private String m_sMGFAlgorithm = DEFAULT_MGF_ALGORITHM ;
6976 // The digest algorithm to use with the RSA-OAEP key transport algorithm
7077 private String m_sDigestAlgorithm = DEFAULT_DIGEST_ALGORITHM ;
78+ // Key agreement method (e.g. X25519, X448, ECDH-ES) - null means no key
79+ // agreement (use key transport instead)
80+ private ECryptoKeyAgreementMethod m_eKeyAgreementMethod ;
81+ // Key derivation function (e.g. HKDF, ConcatKDF) - only used with key
82+ // agreement
83+ private ECryptoKeyDerivationMethod m_eKeyDerivationMethod ;
84+ // Key wrap algorithm (e.g. AES-128 KeyWrap) - only used with key agreement
85+ private ECryptoKeyWrapAlgorithm m_eKeyWrapAlgorithm ;
7186 // The explicit certificate to use - has precedence over the alias
7287 private X509Certificate m_aCert ;
7388 // The alias into the WSS4J crypto config
@@ -220,6 +235,121 @@ public final AS4CryptParams setDigestAlgorithm (@NonNull @Nonempty final String
220235 return this ;
221236 }
222237
238+ /**
239+ * @return The key agreement method to use. May be <code>null</code>, in which case key transport
240+ * (e.g. RSA-OAEP) is used instead of key agreement.
241+ * @since 4.4.0
242+ */
243+ @ Nullable
244+ public final ECryptoKeyAgreementMethod getKeyAgreementMethod ()
245+ {
246+ return m_eKeyAgreementMethod ;
247+ }
248+
249+ /**
250+ * @return <code>true</code> if a key agreement method is set, <code>false</code> if not.
251+ * @since 4.4.0
252+ */
253+ public final boolean hasKeyAgreementMethod ()
254+ {
255+ return m_eKeyAgreementMethod != null ;
256+ }
257+
258+ /**
259+ * Set the key agreement method to use. When set, the encryption will use key agreement (e.g.
260+ * ECDH-ES, X25519) instead of key transport (e.g. RSA-OAEP). If set to <code>null</code>, key
261+ * transport is used.
262+ *
263+ * @param eKeyAgreementMethod
264+ * The key agreement method. May be <code>null</code>.
265+ * @return this for chaining
266+ * @since 4.4.0
267+ */
268+ @ NonNull
269+ public final AS4CryptParams setKeyAgreementMethod (@ Nullable final ECryptoKeyAgreementMethod eKeyAgreementMethod )
270+ {
271+ m_eKeyAgreementMethod = eKeyAgreementMethod ;
272+ return this ;
273+ }
274+
275+ /**
276+ * @return The key derivation function to use with key agreement. May be <code>null</code>.
277+ * @since 4.4.0
278+ */
279+ @ Nullable
280+ public final ECryptoKeyDerivationMethod getKeyDerivationMethod ()
281+ {
282+ return m_eKeyDerivationMethod ;
283+ }
284+
285+ /**
286+ * Set the key derivation function to use with key agreement (e.g. HKDF, ConcatKDF).
287+ *
288+ * @param eKeyDerivationMethod
289+ * The key derivation method. May be <code>null</code>.
290+ * @return this for chaining
291+ * @since 4.4.0
292+ */
293+ @ NonNull
294+ public final AS4CryptParams setKeyDerivationMethod (@ Nullable final ECryptoKeyDerivationMethod eKeyDerivationMethod )
295+ {
296+ m_eKeyDerivationMethod = eKeyDerivationMethod ;
297+ return this ;
298+ }
299+
300+ /**
301+ * @return The key wrap algorithm to use with key agreement. May be <code>null</code>.
302+ * @since 4.4.0
303+ */
304+ @ Nullable
305+ public final ECryptoKeyWrapAlgorithm getKeyWrapAlgorithm ()
306+ {
307+ return m_eKeyWrapAlgorithm ;
308+ }
309+
310+ /**
311+ * Set the key wrap algorithm to use with key agreement (e.g. AES-128 KeyWrap).
312+ *
313+ * @param eKeyWrapAlgorithm
314+ * The key wrap algorithm. May be <code>null</code>.
315+ * @return this for chaining
316+ * @since 4.4.0
317+ */
318+ @ NonNull
319+ public final AS4CryptParams setKeyWrapAlgorithm (@ Nullable final ECryptoKeyWrapAlgorithm eKeyWrapAlgorithm )
320+ {
321+ m_eKeyWrapAlgorithm = eKeyWrapAlgorithm ;
322+ return this ;
323+ }
324+
325+ /**
326+ * Convenience method to set all parameters required for eDelivery AS4 2.0 EdDSA/X25519 key
327+ * agreement: X25519 key agreement, HKDF key derivation, AES-128 key wrap.
328+ *
329+ * @return this for chaining
330+ * @since 4.4.0
331+ */
332+ @ NonNull
333+ public final AS4CryptParams setEDelivery2KeyAgreementX25519 ()
334+ {
335+ return setKeyAgreementMethod (ECryptoKeyAgreementMethod .X25519 ).setKeyDerivationMethod (ECryptoKeyDerivationMethod .HKDF )
336+ .setKeyWrapAlgorithm (ECryptoKeyWrapAlgorithm .AES_128 );
337+ }
338+
339+ /**
340+ * Convenience method to set all parameters required for eDelivery AS4 2.0 ECDSA/ECDH-ES key
341+ * agreement: ECDH-ES key agreement, HKDF key derivation, AES-128 key wrap.
342+ *
343+ * @return this for chaining
344+ * @since 4.4.0
345+ */
346+ @ NonNull
347+ public final AS4CryptParams setEDelivery2KeyAgreementECDHES ()
348+ {
349+ return setKeyAgreementMethod (ECryptoKeyAgreementMethod .ECDH_ES ).setKeyDerivationMethod (ECryptoKeyDerivationMethod .HKDF )
350+ .setKeyWrapAlgorithm (ECryptoKeyWrapAlgorithm .AES_128 );
351+ }
352+
223353 /**
224354 * @return The currently set X509 certificate. May be <code>null</code>.
225355 */
@@ -462,6 +592,9 @@ public void cloneTo (@NonNull final AS4CryptParams aTarget)
462592 .setKeyEncAlgorithm (m_eKeyEncAlgorithm )
463593 .setMGFAlgorithm (m_sMGFAlgorithm )
464594 .setDigestAlgorithm (m_sDigestAlgorithm )
595+ .setKeyAgreementMethod (m_eKeyAgreementMethod )
596+ .setKeyDerivationMethod (m_eKeyDerivationMethod )
597+ .setKeyWrapAlgorithm (m_eKeyWrapAlgorithm )
465598 .setCertificate (m_aCert )
466599 .setAlias (m_sAlias )
467600 .setSessionKeyProvider (m_aSessionKeyProvider )
@@ -488,6 +621,9 @@ public String toString ()
488621 .append ("KeyEncAlgorithm" , m_eKeyEncAlgorithm )
489622 .append ("MGFAlgorithm" , m_sMGFAlgorithm )
490623 .append ("DigestAlgorithm" , m_sDigestAlgorithm )
624+ .appendIfNotNull ("KeyAgreementMethod" , m_eKeyAgreementMethod )
625+ .appendIfNotNull ("KeyDerivationMethod" , m_eKeyDerivationMethod )
626+ .appendIfNotNull ("KeyWrapAlgorithm" , m_eKeyWrapAlgorithm )
491627 .append ("Certificate" , m_aCert )
492628 .append ("Alias" , m_sAlias )
493629 .append ("SessionKeyProvider" , m_aSessionKeyProvider )
0 commit comments