diff --git a/phase4-euctp-client/src/test/java/com/helger/phase4/euctp/MainPhase4EuCtpSenderExample.java b/phase4-euctp-client/src/test/java/com/helger/phase4/euctp/MainPhase4EuCtpSenderExample.java index 80413d3b8..cc3af36ef 100644 --- a/phase4-euctp-client/src/test/java/com/helger/phase4/euctp/MainPhase4EuCtpSenderExample.java +++ b/phase4-euctp-client/src/test/java/com/helger/phase4/euctp/MainPhase4EuCtpSenderExample.java @@ -43,10 +43,12 @@ import com.helger.phase4.client.AS4ClientErrorMessage; import com.helger.phase4.client.AS4ClientReceiptMessage; import com.helger.phase4.client.AS4ClientSentMessage; -import com.helger.phase4.crypto.AS4CryptoFactoryProperties; -import com.helger.phase4.crypto.AS4CryptoProperties; +import com.helger.phase4.crypto.AS4CryptoFactoryInMemoryKeyStore; +import com.helger.phase4.crypto.AS4KeyStoreDescriptor; +import com.helger.phase4.crypto.AS4TrustStoreDescriptor; import com.helger.phase4.crypto.ECryptoAlgorithmC14N; import com.helger.phase4.crypto.ECryptoKeyEncryptionAlgorithm; +import com.helger.phase4.crypto.IAS4CryptoFactory; import com.helger.phase4.dump.AS4DumpManager; import com.helger.phase4.dump.AS4IncomingDumperFileBased; import com.helger.phase4.dump.AS4OutgoingDumperFileBased; @@ -76,20 +78,23 @@ public class MainPhase4EuCtpSenderExample private static final Logger LOGGER = LoggerFactory.getLogger (MainPhase4EuCtpSenderExample.class); @Nonnull - private static AS4CryptoProperties _buildAs4CryptoProperties () + private static IAS4CryptoFactory _buildAs4CryptoFactory () { - final AS4CryptoProperties ret = new AS4CryptoProperties (); - ret.setKeyStorePath (System.getenv ("AS4_SIGNING_KEYSTORE_PATH")); - ret.setKeyStoreType (EKeyStoreType.PKCS12); - ret.setKeyStorePassword (System.getenv ("AS4_SIGNING_KEYSTORE_PASSWORD")); - ret.setKeyAlias (System.getenv ("AS4_SIGNING_KEY_ALIAS")); - ret.setKeyPassword (System.getenv ("AS4_SIGNING_KEY_PASSWORD")); - - // must include the Taxud CA and intermediate certificates - ret.setTrustStorePath (System.getenv ("AS4_SIGNING_TRUST_KEYSTORE_PATH")); - ret.setTrustStoreType (EKeyStoreType.PKCS12); - ret.setTrustStorePassword (System.getenv ("AS4_SIGNING_TRUST_KEYSTORE_PASSWORD")); - return ret; + return new AS4CryptoFactoryInMemoryKeyStore (AS4KeyStoreDescriptor.builder () + .type (EKeyStoreType.PKCS12) + .path (System.getenv ("AS4_SIGNING_KEYSTORE_PATH")) + .password (System.getenv ("AS4_SIGNING_KEYSTORE_PASSWORD")) + .keyAlias (System.getenv ("AS4_SIGNING_KEY_ALIAS")) + .keyPassword (System.getenv ("AS4_SIGNING_KEY_PASSWORD")) + .build (), + // must include the Taxud CA + // and intermediate + // certificates + AS4TrustStoreDescriptor.builder () + .type (EKeyStoreType.PKCS12) + .path (System.getenv ("AS4_SIGNING_TRUST_KEYSTORE_PATH")) + .password (System.getenv ("AS4_SIGNING_TRUST_KEYSTORE_PASSWORD")) + .build ()); } public static void main (final String [] args) @@ -113,8 +118,7 @@ public static void main (final String [] args) final Phase4EuCtpHttpClientSettings aHttpClientSettings = new Phase4EuCtpHttpClientSettings (aSslKeyStore, aKeyStorePassword); - final AS4CryptoProperties as4CryptoProperties = _buildAs4CryptoProperties (); - final AS4CryptoFactoryProperties cryptoFactoryProperties = new AS4CryptoFactoryProperties (as4CryptoProperties); + final IAS4CryptoFactory cryptoFactoryProperties = _buildAs4CryptoFactory (); // configured on the STI final String fromPartyID = System.getenv ("AS4_FROM_PARTY_ID"); @@ -142,7 +146,7 @@ public static void main (final String [] args) private static void _sendPullRequest (final Phase4EuCtpHttpClientSettings aHttpClientSettings, final String fromPartyID, - final AS4CryptoFactoryProperties cryptoFactoryProperties) throws Phase4Exception + final IAS4CryptoFactory cryptoFactory) throws Phase4Exception { final Wrapper aUserMessageHolder = new Wrapper <> (); final Wrapper aSignalMessageHolder = new Wrapper <> (); @@ -187,7 +191,7 @@ private static void _sendPullRequest (final Phase4EuCtpHttpClientSettings aHttpC aSignalMessageHolder.set (aEbmsSignalMsg); aSoapDocHolder.set (aIncomingState.getEffectiveDecryptedSoapDocument ()); }) - .cryptoFactory (cryptoFactoryProperties); + .cryptoFactory (cryptoFactory); final ESuccess eSuccess = prBuilder.sendMessage (); // LOGGER.info ("euctp pull request result: " + eSuccess); @@ -305,7 +309,7 @@ private static void _sendReceipt (final Wrapper aUserMessageH private static void _sendConnectionTest (final Phase4EuCtpHttpClientSettings aHttpClientSettings, final String fromPartyID, final Wrapper aSignalMsgHolder, - final AS4CryptoFactoryProperties cryptoFactoryProperties) + final IAS4CryptoFactory cryptoFactory) { EAS4UserMessageSendResult eResult; eResult = Phase4EuCtpSender.builderUserMessage () @@ -320,7 +324,7 @@ private static void _sendConnectionTest (final Phase4EuCtpHttpClientSettings aHt .service ("http://docs.oasis-open.org/ebxml-msg/ebms/v3.0/ns/core/200704/service") .action (EuCtpPMode.ACTION_TEST) .signalMsgConsumer ( (aSignalMsg, aMMD, aState) -> aSignalMsgHolder.set (aSignalMsg)) - .cryptoFactory (cryptoFactoryProperties) + .cryptoFactory (cryptoFactory) // .payload(new // AS4OutgoingAttachment.Builder().data(aPayloadBytes).mimeTypeXML()) .sendMessageAndCheckForReceipt (); @@ -330,7 +334,7 @@ private static void _sendConnectionTest (final Phase4EuCtpHttpClientSettings aHt private static void _sendENSFilling (final Phase4EuCtpHttpClientSettings aHttpClientSettings, final String fromPartyID, - final AS4CryptoFactoryProperties cryptoFactoryProperties) + final IAS4CryptoFactory cryptoFactory) { // Read XML payload to send final byte [] aPayloadBytes = StreamHelper.getAllBytes (new ClassPathResource ("/external/examples/base-example.xml")); @@ -349,7 +353,7 @@ private static void _sendENSFilling (final Phase4EuCtpHttpClientSettings aHttpCl .service (EuCtpPMode.DEFAULT_SERVICE_TYPE, EEuCtpService.TRADER_TO_CUSTOMS) .action (EEuCtpAction.IE3F26) .signalMsgConsumer ( (aSignalMsg, aMMD, aState) -> aSignalMsgHolder.set (aSignalMsg)) - .cryptoFactory (cryptoFactoryProperties) + .cryptoFactory (cryptoFactory) .conversationID (UUID.randomUUID ().toString ()) .payload (new AS4OutgoingAttachment.Builder ().compressionGZIP () .data (aPayloadBytes) diff --git a/phase4-lib/src/main/java/com/helger/phase4/crypto/AS4CryptoFactoryConfiguration.java b/phase4-lib/src/main/java/com/helger/phase4/crypto/AS4CryptoFactoryConfiguration.java index 2cf7d1826..5e08ead4d 100644 --- a/phase4-lib/src/main/java/com/helger/phase4/crypto/AS4CryptoFactoryConfiguration.java +++ b/phase4-lib/src/main/java/com/helger/phase4/crypto/AS4CryptoFactoryConfiguration.java @@ -69,6 +69,9 @@ public static AS4CryptoFactoryConfiguration getDefaultInstance () return DEFAULT_INSTANCE; } + private final IAS4KeyStoreDescriptor m_aKeyStoreDesc; + private final IAS4TrustStoreDescriptor m_aTrustStorDesc; + /** * This constructor takes the configuration object and uses the default prefix * for backwards compatibility. This is kind of the default constructor. @@ -81,7 +84,7 @@ public AS4CryptoFactoryConfiguration (@Nonnull final IConfigWithFallback aConfig this (aConfig, DEFAULT_CONFIG_PREFIX); } - @Nullable + @Nonnull private static IAS4KeyStoreDescriptor _loadKeyStore (@Nonnull final IConfigWithFallback aConfig, @Nonnull @Nonempty final String sConfigPrefix) { @@ -112,16 +115,20 @@ private static IAS4KeyStoreDescriptor _loadKeyStore (@Nonnull final IConfigWithF private static IAS4TrustStoreDescriptor _loadTrustStore (@Nonnull final IConfigWithFallback aConfig, @Nonnull @Nonempty final String sConfigPrefix) { + // Load the trust store - may be null final IAS4TrustStoreDescriptor aDescriptor = AS4TrustStoreDescriptor.createFromConfig (aConfig, sConfigPrefix, null); - final LoadedKeyStore aLTS = aDescriptor.loadTrustStore (); - if (aLTS.getKeyStore () == null) + if (aDescriptor != null) { - LOGGER.error ("Failed to load the trust store from the properties starting with '" + - sConfigPrefix + - "': " + - aLTS.getErrorText (Locale.ROOT)); + final LoadedKeyStore aLTS = aDescriptor.loadTrustStore (); + if (aLTS.getKeyStore () == null) + { + LOGGER.error ("Failed to load the trust store from the properties starting with '" + + sConfigPrefix + + "': " + + aLTS.getErrorText (Locale.ROOT)); + } } return aDescriptor; } @@ -139,6 +146,33 @@ private static IAS4TrustStoreDescriptor _loadTrustStore (@Nonnull final IConfigW public AS4CryptoFactoryConfiguration (@Nonnull final IConfigWithFallback aConfig, @Nonnull @Nonempty final String sConfigPrefix) { - super (_loadKeyStore (aConfig, sConfigPrefix), _loadTrustStore (aConfig, sConfigPrefix)); + this (_loadKeyStore (aConfig, sConfigPrefix), _loadTrustStore (aConfig, sConfigPrefix)); + } + + private AS4CryptoFactoryConfiguration (@Nonnull final IAS4KeyStoreDescriptor aKeyStoreDesc, + @Nonnull final IAS4TrustStoreDescriptor aTrustStorDesc) + { + super (aKeyStoreDesc, aTrustStorDesc); + m_aKeyStoreDesc = aKeyStoreDesc; + m_aTrustStorDesc = aTrustStorDesc; + } + + /** + * @return The descriptor used to load the key store. Never null. + */ + @Nonnull + public IAS4KeyStoreDescriptor getKeyStoreDescriptor () + { + return m_aKeyStoreDesc; + } + + /** + * @return The descriptor used to load the trust store. Never + * null. + */ + @Nonnull + public IAS4TrustStoreDescriptor getTrustStoreDescriptor () + { + return m_aTrustStorDesc; } } diff --git a/phase4-lib/src/main/java/com/helger/phase4/crypto/AS4CryptoFactoryInMemoryKeyStore.java b/phase4-lib/src/main/java/com/helger/phase4/crypto/AS4CryptoFactoryInMemoryKeyStore.java index 47134b1ac..6effbbb92 100644 --- a/phase4-lib/src/main/java/com/helger/phase4/crypto/AS4CryptoFactoryInMemoryKeyStore.java +++ b/phase4-lib/src/main/java/com/helger/phase4/crypto/AS4CryptoFactoryInMemoryKeyStore.java @@ -54,15 +54,17 @@ public class AS4CryptoFactoryInMemoryKeyStore extends AbstractAS4CryptoFactory * @param aKeyStoreDesc * The key store descriptor. May not be null. * @param aTrustStoreDesc - * The trust store descriptor. May not be null. + * The trust store descriptor. May be null in which case + * the global JRE CA certs list will be used. + * @since 3.0.0 */ - protected AS4CryptoFactoryInMemoryKeyStore (@Nonnull final IAS4KeyStoreDescriptor aKeyStoreDesc, - @Nonnull final IAS4TrustStoreDescriptor aTrustStoreDesc) + public AS4CryptoFactoryInMemoryKeyStore (@Nonnull final IAS4KeyStoreDescriptor aKeyStoreDesc, + @Nonnull final IAS4TrustStoreDescriptor aTrustStoreDesc) { this (aKeyStoreDesc.loadKeyStore ().getKeyStore (), aKeyStoreDesc.getKeyAlias (), aKeyStoreDesc.getKeyPassword (), - aTrustStoreDesc.loadTrustStore ().getKeyStore ()); + aTrustStoreDesc == null ? null : aTrustStoreDesc.loadTrustStore ().getKeyStore ()); } /** diff --git a/phase4-lib/src/main/java/com/helger/phase4/crypto/AS4KeyStoreDescriptor.java b/phase4-lib/src/main/java/com/helger/phase4/crypto/AS4KeyStoreDescriptor.java index 305f2044f..8e2426702 100644 --- a/phase4-lib/src/main/java/com/helger/phase4/crypto/AS4KeyStoreDescriptor.java +++ b/phase4-lib/src/main/java/com/helger/phase4/crypto/AS4KeyStoreDescriptor.java @@ -9,6 +9,7 @@ import com.helger.commons.ValueEnforcer; import com.helger.commons.annotation.Nonempty; import com.helger.commons.annotation.ReturnsMutableObject; +import com.helger.commons.builder.IBuilder; import com.helger.commons.string.StringHelper; import com.helger.commons.string.ToStringGenerator; import com.helger.config.fallback.IConfigWithFallback; @@ -177,4 +178,103 @@ public static AS4KeyStoreDescriptor createFromConfig (@Nonnull final IConfigWith return new AS4KeyStoreDescriptor (aType, sPath, aPassword, aProvider, sKeyAlias, aKeyPassword); } + + /** + * @return A new builder for {@link AS4KeyStoreDescriptor} objects. Never + * null. + */ + @Nonnull + public static AS4KeyStoreDescriptorBuilder builder () + { + return new AS4KeyStoreDescriptorBuilder (); + } + + /** + * Builder class for class {@link AS4KeyStoreDescriptor}. + * + * @author Philip Helger + */ + public static class AS4KeyStoreDescriptorBuilder implements IBuilder + { + private IKeyStoreType m_aType; + private String m_sPath; + private char [] m_aPassword; + private Provider m_aProvider; + private String m_sKeyAlias; + private char [] m_aKeyPassword; + + public AS4KeyStoreDescriptorBuilder () + {} + + @Nonnull + public AS4KeyStoreDescriptorBuilder type (@Nullable final IKeyStoreType a) + { + m_aType = a; + return this; + } + + @Nonnull + public AS4KeyStoreDescriptorBuilder path (@Nullable final String s) + { + m_sPath = s; + return this; + } + + @Nonnull + public AS4KeyStoreDescriptorBuilder password (@Nullable final String s) + { + return password (s == null ? null : s.toCharArray ()); + } + + @Nonnull + public AS4KeyStoreDescriptorBuilder password (@Nullable final char [] a) + { + m_aPassword = a; + return this; + } + + @Nonnull + public AS4KeyStoreDescriptorBuilder provider (@Nullable final Provider a) + { + m_aProvider = a; + return this; + } + + @Nonnull + public AS4KeyStoreDescriptorBuilder keyAlias (@Nullable final String s) + { + m_sKeyAlias = s; + return this; + } + + @Nonnull + public AS4KeyStoreDescriptorBuilder keyPassword (@Nullable final String s) + { + return keyPassword (s == null ? null : s.toCharArray ()); + } + + @Nonnull + public AS4KeyStoreDescriptorBuilder keyPassword (@Nullable final char [] a) + { + m_aKeyPassword = a; + return this; + } + + @Nonnull + public AS4KeyStoreDescriptor build () + { + if (m_aType == null) + throw new IllegalStateException ("Type is missing"); + if (StringHelper.hasNoText (m_sPath)) + throw new IllegalStateException ("Path is empty"); + if (m_aPassword == null) + throw new IllegalStateException ("Password is missing"); + // Provider may be null + if (StringHelper.hasNoText (m_sKeyAlias)) + throw new IllegalStateException ("KeyAlias is empty"); + if (m_aKeyPassword == null) + throw new IllegalStateException ("KeyPassword is missing"); + return new AS4KeyStoreDescriptor (m_aType, m_sPath, m_aPassword, m_aProvider, m_sKeyAlias, m_aKeyPassword); + } + } } diff --git a/phase4-lib/src/main/java/com/helger/phase4/crypto/AS4TrustStoreDescriptor.java b/phase4-lib/src/main/java/com/helger/phase4/crypto/AS4TrustStoreDescriptor.java index deb1d450f..c9491ca22 100644 --- a/phase4-lib/src/main/java/com/helger/phase4/crypto/AS4TrustStoreDescriptor.java +++ b/phase4-lib/src/main/java/com/helger/phase4/crypto/AS4TrustStoreDescriptor.java @@ -8,6 +8,7 @@ import com.helger.commons.ValueEnforcer; import com.helger.commons.annotation.Nonempty; import com.helger.commons.annotation.ReturnsMutableObject; +import com.helger.commons.builder.IBuilder; import com.helger.commons.string.StringHelper; import com.helger.commons.string.ToStringGenerator; import com.helger.config.fallback.IConfigWithFallback; @@ -109,10 +110,10 @@ public String toString () * @param aProvider * The Java security provider for loading the trust store. May be * null to use the default. - * @return A new {@link AS4TrustStoreDescriptor} object and never - * null. + * @return A new {@link AS4TrustStoreDescriptor} object or null + * if path or password are not present. */ - @Nonnull + @Nullable public static AS4TrustStoreDescriptor createFromConfig (@Nonnull final IConfigWithFallback aConfig, @Nonnull @Nonempty final String sConfigPrefix, @Nullable final Provider aProvider) @@ -128,6 +129,83 @@ public static AS4TrustStoreDescriptor createFromConfig (@Nonnull final IConfigWi final String sPath = aConfig.getAsString (sConfigPrefix + "truststore.file"); final char [] aPassword = aConfig.getAsCharArray (sConfigPrefix + "truststore.password"); + // No trust store configured + if (StringHelper.hasNoText (sPath) || aPassword == null) + return null; + return new AS4TrustStoreDescriptor (aType, sPath, aPassword, aProvider); } + + /** + * @return A new builder for {@link AS4TrustStoreDescriptor} objects. Never + * null. + */ + @Nonnull + public static AS4TrustStoreDescriptorBuilder builder () + { + return new AS4TrustStoreDescriptorBuilder (); + } + + /** + * Builder class for class {@link AS4TrustStoreDescriptor}. + * + * @author Philip Helger + */ + public static class AS4TrustStoreDescriptorBuilder implements IBuilder + { + private IKeyStoreType m_aType; + private String m_sPath; + private char [] m_aPassword; + private Provider m_aProvider; + + public AS4TrustStoreDescriptorBuilder () + {} + + @Nonnull + public AS4TrustStoreDescriptorBuilder type (@Nullable final IKeyStoreType a) + { + m_aType = a; + return this; + } + + @Nonnull + public AS4TrustStoreDescriptorBuilder path (@Nullable final String s) + { + m_sPath = s; + return this; + } + + @Nonnull + public AS4TrustStoreDescriptorBuilder password (@Nullable final String s) + { + return password (s == null ? null : s.toCharArray ()); + } + + @Nonnull + public AS4TrustStoreDescriptorBuilder password (@Nullable final char [] a) + { + m_aPassword = a; + return this; + } + + @Nonnull + public AS4TrustStoreDescriptorBuilder provider (@Nullable final Provider a) + { + m_aProvider = a; + return this; + } + + @Nonnull + public AS4TrustStoreDescriptor build () + { + if (m_aType == null) + throw new IllegalStateException ("Type is missing"); + if (StringHelper.hasNoText (m_sPath)) + throw new IllegalStateException ("Path is empty"); + if (m_aPassword == null) + throw new IllegalStateException ("Password is missing"); + // Provider may be null + return new AS4TrustStoreDescriptor (m_aType, m_sPath, m_aPassword, m_aProvider); + } + } } diff --git a/phase4-lib/src/test/java/com/helger/phase4/supplementary/tools/MainDecipherAS4In.java b/phase4-lib/src/test/java/com/helger/phase4/supplementary/tools/MainDecipherAS4In.java index 9faea6978..01ceed6d2 100644 --- a/phase4-lib/src/test/java/com/helger/phase4/supplementary/tools/MainDecipherAS4In.java +++ b/phase4-lib/src/test/java/com/helger/phase4/supplementary/tools/MainDecipherAS4In.java @@ -25,6 +25,7 @@ import com.helger.commons.io.resource.FileSystemResource; import com.helger.phase4.crypto.AS4CryptoFactoryProperties; import com.helger.phase4.crypto.AS4CryptoProperties; +import com.helger.phase4.crypto.IAS4CryptoFactory; import com.helger.phase4.dump.AS4DumpReader; /** @@ -55,12 +56,13 @@ public static void main (final String [] args) throws Exception if (aBytes == null) throw new IllegalStateException ("Failed to read file content as byte array"); - final AS4CryptoFactoryProperties aCryptoFactory = new AS4CryptoFactoryProperties (aCP); + final IAS4CryptoFactory aCryptoFactory = new AS4CryptoFactoryProperties (aCP); AS4DumpReader.decryptAS4In (aBytes, aCryptoFactory, aCryptoFactory, null, - (nIndex, aDecryptedBytes) -> SimpleFileIO.writeFile (new File (folder, + (nIndex, aDecryptedBytes) -> SimpleFileIO.writeFile ( + new File (folder, "payload-" + nIndex + ".decrypted"), diff --git a/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/receivers/MainPhase4PeppolSenderExplicitCryptoProperties.java b/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/receivers/MainPhase4PeppolSenderExplicitCryptoProperties.java index 22ceac59d..d7674ab9d 100644 --- a/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/receivers/MainPhase4PeppolSenderExplicitCryptoProperties.java +++ b/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/receivers/MainPhase4PeppolSenderExplicitCryptoProperties.java @@ -23,9 +23,11 @@ import com.helger.commons.io.file.SimpleFileIO; import com.helger.peppol.sml.ESML; +import com.helger.peppol.utils.PeppolKeyStoreHelper; import com.helger.peppolid.IParticipantIdentifier; -import com.helger.phase4.crypto.AS4CryptoFactoryProperties; -import com.helger.phase4.crypto.AS4CryptoProperties; +import com.helger.phase4.crypto.AS4CryptoFactoryInMemoryKeyStore; +import com.helger.phase4.crypto.AS4KeyStoreDescriptor; +import com.helger.phase4.crypto.AS4TrustStoreDescriptor; import com.helger.phase4.peppol.Phase4PeppolSender; import com.helger.phase4.peppol.Phase4PeppolValidatonResultHandler; import com.helger.phase4.sender.EAS4UserMessageSendResult; @@ -56,20 +58,24 @@ public static void main (final String [] args) throw new IllegalStateException ("Failed to read XML file to be send"); // Manual information - don't use crypto.properties - final AS4CryptoProperties aCP = new AS4CryptoProperties ().setKeyStoreType (EKeyStoreType.PKCS12) - .setKeyStorePath ("test-ap.p12") - .setKeyStorePassword ("peppol") - .setKeyAlias ("openpeppol aisbl id von pop000306") - .setKeyPassword ("peppol") - .setTrustStoreType (EKeyStoreType.JKS) - .setTrustStorePath ("complete-truststore.jks") - .setTrustStorePassword ("peppol"); + final AS4KeyStoreDescriptor aKSD = AS4KeyStoreDescriptor.builder () + .type (EKeyStoreType.PKCS12) + .path ("test-ap.p12") + .password ("peppol") + .keyAlias ("openpeppol aisbl id von pop000306") + .keyPassword ("peppol") + .build (); + final AS4TrustStoreDescriptor aTSD = AS4TrustStoreDescriptor.builder () + .type (PeppolKeyStoreHelper.TRUSTSTORE_TYPE) + .path (PeppolKeyStoreHelper.Config2018.TRUSTSTORE_AP_PILOT_CLASSPATH) + .password (PeppolKeyStoreHelper.TRUSTSTORE_PASSWORD) + .build (); // Start configuring here final IParticipantIdentifier aReceiverID = Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme ("9958:peppol-development-governikus-01"); final EAS4UserMessageSendResult eResult; eResult = Phase4PeppolSender.builder () - .cryptoFactory (new AS4CryptoFactoryProperties (aCP)) + .cryptoFactory (new AS4CryptoFactoryInMemoryKeyStore (aKSD, aTSD)) .documentTypeID (Phase4PeppolSender.IF.createDocumentTypeIdentifierWithDefaultScheme ("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0::2.1")) .processID (Phase4PeppolSender.IF.createProcessIdentifierWithDefaultScheme ("urn:fdc:peppol.eu:2017:poacc:billing:01:1.0")) .senderParticipantID (Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme ("9915:phase4-test-sender")) diff --git a/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/receivers/MainPhase4PeppolSenderQvalia.java b/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/receivers/MainPhase4PeppolSenderQvalia.java index 151de8bd9..a366a5851 100644 --- a/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/receivers/MainPhase4PeppolSenderQvalia.java +++ b/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/receivers/MainPhase4PeppolSenderQvalia.java @@ -42,8 +42,8 @@ import com.helger.peppol.utils.PeppolKeyStoreHelper; import com.helger.peppolid.IParticipantIdentifier; import com.helger.phase4.client.IAS4ClientBuildMessageCallback; +import com.helger.phase4.crypto.AS4CryptoFactoryConfiguration; import com.helger.phase4.crypto.AS4CryptoFactoryInMemoryKeyStore; -import com.helger.phase4.crypto.AS4CryptoFactoryProperties; import com.helger.phase4.crypto.IAS4CryptoFactory; import com.helger.phase4.dump.AS4DumpManager; import com.helger.phase4.dump.AS4IncomingDumperFileBased; @@ -101,7 +101,7 @@ public void onAS4Message (final AbstractAS4Message aMsg) }; // Invalid certificate is valid until 2029 - final IAS4CryptoFactory cf = true ? AS4CryptoFactoryProperties.getDefaultInstance () + final IAS4CryptoFactory cf = true ? AS4CryptoFactoryConfiguration.getDefaultInstance () : new AS4CryptoFactoryInMemoryKeyStore (KeyStoreHelper.loadKeyStoreDirect (EKeyStoreType.JKS, "invalid-keystore-pw-peppol.jks", "peppol"), diff --git a/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/receivers/MainPhase4PeppolSenderQvaliaConstantReceiver.java b/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/receivers/MainPhase4PeppolSenderQvaliaConstantReceiver.java index 513083fd9..72040b7b7 100644 --- a/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/receivers/MainPhase4PeppolSenderQvaliaConstantReceiver.java +++ b/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/receivers/MainPhase4PeppolSenderQvaliaConstantReceiver.java @@ -24,7 +24,7 @@ import com.helger.peppolid.IParticipantIdentifier; import com.helger.phase4.client.IAS4ClientBuildMessageCallback; -import com.helger.phase4.crypto.AS4CryptoFactoryProperties; +import com.helger.phase4.crypto.AS4CryptoFactoryConfiguration; import com.helger.phase4.crypto.IAS4CryptoFactory; import com.helger.phase4.dump.AS4DumpManager; import com.helger.phase4.dump.AS4IncomingDumperFileBased; @@ -78,7 +78,7 @@ public void onAS4Message (final AbstractAS4Message aMsg) } }; - final IAS4CryptoFactory cf = AS4CryptoFactoryProperties.getDefaultInstance (); + final IAS4CryptoFactory cf = AS4CryptoFactoryConfiguration.getDefaultInstance (); final EAS4UserMessageSendResult eResult; eResult = Phase4PeppolSender.builder () .httpRetrySettings (new HttpRetrySettings ().setMaxRetries (0)) diff --git a/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/receivers/MainPhase4PeppolSenderQvaliaLargeFile.java b/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/receivers/MainPhase4PeppolSenderQvaliaLargeFile.java index f8bbaea57..28b036a04 100644 --- a/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/receivers/MainPhase4PeppolSenderQvaliaLargeFile.java +++ b/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/receivers/MainPhase4PeppolSenderQvaliaLargeFile.java @@ -24,7 +24,7 @@ import com.helger.peppol.sml.ESML; import com.helger.peppolid.IParticipantIdentifier; -import com.helger.phase4.crypto.AS4CryptoFactoryProperties; +import com.helger.phase4.crypto.AS4CryptoFactoryConfiguration; import com.helger.phase4.crypto.IAS4CryptoFactory; import com.helger.phase4.dump.AS4DumpManager; import com.helger.phase4.dump.AS4IncomingDumperFileBased; @@ -64,8 +64,7 @@ public static void main (final String [] args) // Start configuring here final IParticipantIdentifier aReceiverID = Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme ("0007:5567321707"); - // Invalid certificate is valid until 2029 - final IAS4CryptoFactory cf = AS4CryptoFactoryProperties.getDefaultInstance (); + final IAS4CryptoFactory cf = AS4CryptoFactoryConfiguration.getDefaultInstance (); final EAS4UserMessageSendResult eResult; eResult = Phase4PeppolSender.builder () .httpRetrySettings (new HttpRetrySettings ().setMaxRetries (0)) diff --git a/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/receivers/MainPhase4PeppolSenderQvaliaUBL.java b/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/receivers/MainPhase4PeppolSenderQvaliaUBL.java index 2eea852d3..e3c72f619 100644 --- a/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/receivers/MainPhase4PeppolSenderQvaliaUBL.java +++ b/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/receivers/MainPhase4PeppolSenderQvaliaUBL.java @@ -25,7 +25,7 @@ import com.helger.peppol.sml.ESML; import com.helger.peppolid.IParticipantIdentifier; import com.helger.phase4.client.IAS4ClientBuildMessageCallback; -import com.helger.phase4.crypto.AS4CryptoFactoryProperties; +import com.helger.phase4.crypto.AS4CryptoFactoryConfiguration; import com.helger.phase4.crypto.IAS4CryptoFactory; import com.helger.phase4.dump.AS4DumpManager; import com.helger.phase4.dump.AS4IncomingDumperFileBased; @@ -90,8 +90,7 @@ public void onAS4Message (final AbstractAS4Message aMsg) final IValidationExecutorSetRegistry aVESRegistry = Phase4PeppolValidation.createDefaultRegistry (); EN16931Validation.initEN16931 (aVESRegistry); - // Invalid certificate is valid until 2029 - final IAS4CryptoFactory cf = AS4CryptoFactoryProperties.getDefaultInstance (); + final IAS4CryptoFactory cf = AS4CryptoFactoryConfiguration.getDefaultInstance (); final EAS4UserMessageSendResult eResult; eResult = Phase4PeppolSender.builder () .httpRetrySettings (new HttpRetrySettings ().setMaxRetries (0)) diff --git a/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/supplementary/tools/MainDecipherAS4In.java b/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/supplementary/tools/MainDecipherAS4In.java index 84e02c517..a632d6c17 100644 --- a/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/supplementary/tools/MainDecipherAS4In.java +++ b/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/supplementary/tools/MainDecipherAS4In.java @@ -22,7 +22,7 @@ import org.slf4j.LoggerFactory; import com.helger.commons.io.file.SimpleFileIO; -import com.helger.phase4.crypto.AS4CryptoFactoryProperties; +import com.helger.phase4.crypto.AS4CryptoFactoryConfiguration; import com.helger.phase4.crypto.IAS4CryptoFactory; import com.helger.phase4.dump.AS4DumpReader; import com.helger.phase4.dump.AS4DumpReader.IDecryptedPayloadConsumer; @@ -50,14 +50,14 @@ public static void main (final String [] args) throws Exception if (aBytes == null) throw new IllegalStateException ("Failed to read file content as byte array"); - final IAS4CryptoFactory aCryptoFactory = AS4CryptoFactoryProperties.getDefaultInstance (); + final IAS4CryptoFactory aCryptoFactory = AS4CryptoFactoryConfiguration.getDefaultInstance (); // What to do with the decrypted payload - final IDecryptedPayloadConsumer aDecryptedConsumer = (idx, aDecryptedBytes) -> SimpleFileIO.writeFile (new File ( - aFile.getParentFile (), - "payload-" + - idx + - ".decrypted"), - aDecryptedBytes); + final IDecryptedPayloadConsumer aDecryptedConsumer = (idx, + aDecryptedBytes) -> SimpleFileIO.writeFile (new File (aFile.getParentFile (), + "payload-" + + idx + + ".decrypted"), + aDecryptedBytes); // Do it AS4DumpReader.decryptAS4In (aBytes, aCryptoFactory, aCryptoFactory, null, aDecryptedConsumer); diff --git a/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/supplementary/tools/MainVerifySignature.java b/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/supplementary/tools/MainVerifySignature.java index 6726ef70f..dbb2eaa12 100644 --- a/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/supplementary/tools/MainVerifySignature.java +++ b/phase4-peppol-client/src/test/java/com/helger/phase4/peppol/supplementary/tools/MainVerifySignature.java @@ -42,7 +42,7 @@ import com.helger.commons.state.ESuccess; import com.helger.phase4.attachment.WSS4JAttachment; import com.helger.phase4.attachment.WSS4JAttachmentCallbackHandler; -import com.helger.phase4.crypto.AS4CryptoFactoryProperties; +import com.helger.phase4.crypto.AS4CryptoFactoryConfiguration; import com.helger.phase4.crypto.ECryptoMode; import com.helger.phase4.crypto.IAS4CryptoFactory; import com.helger.phase4.dump.AS4DumpReader; @@ -172,7 +172,7 @@ public static void main (final String [] args) throw new IllegalStateException ("Failed to read the payload as XML. Maybe it is a MIME message? MIME messages are unfortunately not yet supported."); // Main action - final IAS4CryptoFactory aCryptoFactory = AS4CryptoFactoryProperties.getDefaultInstance (); + final IAS4CryptoFactory aCryptoFactory = AS4CryptoFactoryConfiguration.getDefaultInstance (); final ICommonsList aAttachments = new CommonsArrayList <> (); _verifyAndDecrypt (aResHelper, aCryptoFactory, diff --git a/phase4-peppol-server-webapp/src/main/java/com/helger/phase4/peppol/server/servlet/Phase4PeppolWebAppListener.java b/phase4-peppol-server-webapp/src/main/java/com/helger/phase4/peppol/server/servlet/Phase4PeppolWebAppListener.java index 93d7e8319..22d875216 100644 --- a/phase4-peppol-server-webapp/src/main/java/com/helger/phase4/peppol/server/servlet/Phase4PeppolWebAppListener.java +++ b/phase4-peppol-server-webapp/src/main/java/com/helger/phase4/peppol/server/servlet/Phase4PeppolWebAppListener.java @@ -48,8 +48,7 @@ import com.helger.peppol.utils.PeppolCertificateChecker; import com.helger.phase4.CAS4; import com.helger.phase4.config.AS4Configuration; -import com.helger.phase4.crypto.AS4CryptoFactoryProperties; -import com.helger.phase4.crypto.AS4CryptoProperties; +import com.helger.phase4.crypto.AS4CryptoFactoryConfiguration; import com.helger.phase4.dump.AS4DumpManager; import com.helger.phase4.dump.AS4IncomingDumperFileBased; import com.helger.phase4.dump.AS4OutgoingDumperFileBased; @@ -139,8 +138,8 @@ protected void initGlobalSettings () HttpDebugger.setEnabled (false); // Sanity check - if (CommandMap.getDefaultCommandMap ().createDataContentHandler (CMimeType.MULTIPART_RELATED.getAsString ()) == - null) + if (CommandMap.getDefaultCommandMap () + .createDataContentHandler (CMimeType.MULTIPART_RELATED.getAsString ()) == null) throw new IllegalStateException ("No DataContentHandler for MIME Type '" + CMimeType.MULTIPART_RELATED.getAsString () + "' is available. There seems to be a problem with the dependencies/packaging"); @@ -187,8 +186,9 @@ public void onEndRequest (@Nonnull final IAS4IncomingMessageMetadata aMessageMet final File aFile = StorageHelper.getStorageFile (aMessageMetadata, ".metadata"); if (SimpleFileIO.writeFile (aFile, AS4IncomingHelper.getIncomingMetadataAsJson (aMessageMetadata) - .getAsJsonString (JsonWriterSettings.DEFAULT_SETTINGS_FORMATTED), - StandardCharsets.UTF_8).isFailure ()) + .getAsJsonString (JsonWriterSettings.DEFAULT_SETTINGS_FORMATTED), + StandardCharsets.UTF_8) + .isFailure ()) LOGGER.error ("Failed to write metadata to '" + aFile.getAbsolutePath () + "'"); else LOGGER.info ("Wrote metadata to '" + aFile.getAbsolutePath () + "'"); @@ -196,10 +196,11 @@ public void onEndRequest (@Nonnull final IAS4IncomingMessageMetadata aMessageMet }); // Store the outgoings file as well - AS4DumpManager.setOutgoingDumper (new AS4OutgoingDumperFileBased ( (eMsgMode, sMessageID, nTry) -> StorageHelper - .getStorageFile (sMessageID, - nTry, - ".as4out"))); + AS4DumpManager.setOutgoingDumper (new AS4OutgoingDumperFileBased ( (eMsgMode, + sMessageID, + nTry) -> StorageHelper.getStorageFile (sMessageID, + nTry, + ".as4out"))); } private static void _initPeppolAS4 () @@ -222,15 +223,14 @@ private static void _initPeppolAS4 () AS4Configuration.getConfig ().getAsInt ("http.proxy.port"))); PeppolCRLDownloader.setAsDefaultCRLCache (aHCS); - final AS4CryptoFactoryProperties aCF = AS4CryptoFactoryProperties.getDefaultInstance (); - final AS4CryptoProperties aCP = aCF.cryptoProperties (); + final AS4CryptoFactoryConfiguration aCF = AS4CryptoFactoryConfiguration.getDefaultInstance (); // Check if crypto properties are okay - fail early if something is // misconfigured LOGGER.info ("Trying to load configured key store (type=" + - aCP.getKeyStoreType () + + aCF.getKeyStoreDescriptor ().getKeyStoreType () + ", path=" + - aCP.getKeyStorePath () + + aCF.getKeyStoreDescriptor ().getKeyStorePath () + ")"); final KeyStore aKS = aCF.getKeyStore (); if (aKS == null) @@ -250,7 +250,8 @@ private static void _initPeppolAS4 () try { final KeyStore.Entry aEntry = aKS.getEntry (sAlias, - new KeyStore.PasswordProtection (aCP.getKeyPasswordCharArray ())); + new KeyStore.PasswordProtection (aCF.getKeyStoreDescriptor () + .getKeyPassword ())); if (aEntry instanceof KeyStore.PrivateKeyEntry) sType = "private-key"; else @@ -283,7 +284,7 @@ private static void _initPeppolAS4 () // Check if the key configuration is okay - fail early if something is // misconfigured - LOGGER.info ("Trying to load configured private key (alias=" + aCP.getKeyAlias () + ")"); + LOGGER.info ("Trying to load configured private key (alias=" + aCF.getKeyAlias () + ")"); final PrivateKeyEntry aPKE = aCF.getPrivateKeyEntry (); if (aPKE == null) throw new InitializationException ("Failed to load configured private key"); diff --git a/phase4-server-webapp/src/main/java/com/helger/phase4/server/servlet/AS4WebAppListener.java b/phase4-server-webapp/src/main/java/com/helger/phase4/server/servlet/AS4WebAppListener.java index 45eb5f55b..0af1ae3e1 100644 --- a/phase4-server-webapp/src/main/java/com/helger/phase4/server/servlet/AS4WebAppListener.java +++ b/phase4-server-webapp/src/main/java/com/helger/phase4/server/servlet/AS4WebAppListener.java @@ -36,7 +36,7 @@ import com.helger.httpclient.HttpDebugger; import com.helger.json.serialize.JsonWriterSettings; import com.helger.phase4.config.AS4Configuration; -import com.helger.phase4.crypto.AS4CryptoFactoryProperties; +import com.helger.phase4.crypto.AS4CryptoFactoryConfiguration; import com.helger.phase4.crypto.IAS4CryptoFactory; import com.helger.phase4.dump.AS4DumpManager; import com.helger.phase4.dump.AS4IncomingDumperFileBased; @@ -120,8 +120,8 @@ protected void initGlobalSettings () HttpDebugger.setEnabled (false); // Sanity check - if (CommandMap.getDefaultCommandMap ().createDataContentHandler (CMimeType.MULTIPART_RELATED.getAsString ()) == - null) + if (CommandMap.getDefaultCommandMap () + .createDataContentHandler (CMimeType.MULTIPART_RELATED.getAsString ()) == null) throw new IllegalStateException ("No DataContentHandler for MIME Type '" + CMimeType.MULTIPART_RELATED.getAsString () + "' is available. There seems to be a problem with the dependencies/packaging"); @@ -153,7 +153,7 @@ private static void _initAS4 () // Check if crypto properties are okay { - final IAS4CryptoFactory aCF = AS4CryptoFactoryProperties.getDefaultInstance (); + final IAS4CryptoFactory aCF = AS4CryptoFactoryConfiguration.getDefaultInstance (); final KeyStore aKS = aCF.getKeyStore (); if (aKS == null) @@ -179,8 +179,9 @@ public void onEndRequest (@Nonnull final IAS4IncomingMessageMetadata aMessageMet final File aFile = StorageHelper.getStorageFile (aMessageMetadata, ".metadata"); if (SimpleFileIO.writeFile (aFile, AS4IncomingHelper.getIncomingMetadataAsJson (aMessageMetadata) - .getAsJsonString (JsonWriterSettings.DEFAULT_SETTINGS_FORMATTED), - StandardCharsets.UTF_8).isFailure ()) + .getAsJsonString (JsonWriterSettings.DEFAULT_SETTINGS_FORMATTED), + StandardCharsets.UTF_8) + .isFailure ()) LOGGER.error ("Failed to write metadata to '" + aFile.getAbsolutePath () + "'"); else LOGGER.info ("Wrote metadata to '" + aFile.getAbsolutePath () + "'"); @@ -188,17 +189,18 @@ public void onEndRequest (@Nonnull final IAS4IncomingMessageMetadata aMessageMet }); // Store the outgoings file as well - AS4DumpManager.setOutgoingDumper (new AS4OutgoingDumperFileBased ( (eMsgMode, sMessageID, nTry) -> StorageHelper - .getStorageFile (sMessageID, - nTry, - ".as4out"))); + AS4DumpManager.setOutgoingDumper (new AS4OutgoingDumperFileBased ( (eMsgMode, + sMessageID, + nTry) -> StorageHelper.getStorageFile (sMessageID, + nTry, + ".as4out"))); } @Override protected void initManagers () { _initAS4 (); - DropFolderUserMessage.init (AS4CryptoFactoryProperties.getDefaultInstance ()); + DropFolderUserMessage.init (AS4CryptoFactoryConfiguration.getDefaultInstance ()); } @Override diff --git a/phase4-server-webapp/src/main/java/com/helger/phase4/server/servlet/Phase4PeppolStatusXServletHandler.java b/phase4-server-webapp/src/main/java/com/helger/phase4/server/servlet/Phase4PeppolStatusXServletHandler.java index cb9294c7c..889d3b1aa 100644 --- a/phase4-server-webapp/src/main/java/com/helger/phase4/server/servlet/Phase4PeppolStatusXServletHandler.java +++ b/phase4-server-webapp/src/main/java/com/helger/phase4/server/servlet/Phase4PeppolStatusXServletHandler.java @@ -36,7 +36,7 @@ import com.helger.json.IJsonObject; import com.helger.json.JsonObject; import com.helger.phase4.CAS4Version; -import com.helger.phase4.crypto.AS4CryptoFactoryProperties; +import com.helger.phase4.crypto.AS4CryptoFactoryConfiguration; import com.helger.phase4.crypto.IAS4CryptoFactory; import com.helger.servlet.response.UnifiedResponse; import com.helger.web.scope.IRequestWebScopeWithoutResponse; @@ -64,7 +64,7 @@ public static IJsonObject getDefaultStatusData () aStatusData.add ("phase4.version", CAS4Version.BUILD_VERSION); aStatusData.add ("phase4.build-timestamp", CAS4Version.BUILD_TIMESTAMP); - final IAS4CryptoFactory aCF = AS4CryptoFactoryProperties.getDefaultInstance (); + final IAS4CryptoFactory aCF = AS4CryptoFactoryConfiguration.getDefaultInstance (); final KeyStore aKS = aCF.getKeyStore (); aStatusData.add ("phase4.keystore.loaded", aKS != null); if (aKS != null) diff --git a/phase4-spring-boot-demo/src/main/java/com/helger/phase4/springboot/servlet/ServletConfig.java b/phase4-spring-boot-demo/src/main/java/com/helger/phase4/springboot/servlet/ServletConfig.java index 8f6540a95..bf1fb8a96 100644 --- a/phase4-spring-boot-demo/src/main/java/com/helger/phase4/springboot/servlet/ServletConfig.java +++ b/phase4-spring-boot-demo/src/main/java/com/helger/phase4/springboot/servlet/ServletConfig.java @@ -40,7 +40,7 @@ import com.helger.peppol.utils.EPeppolCertificateCheckResult; import com.helger.peppol.utils.PeppolCertificateChecker; import com.helger.phase4.config.AS4Configuration; -import com.helger.phase4.crypto.AS4CryptoFactoryProperties; +import com.helger.phase4.crypto.AS4CryptoFactoryConfiguration; import com.helger.phase4.crypto.IAS4CryptoFactory; import com.helger.phase4.incoming.AS4IncomingProfileSelectorFromGlobal; import com.helger.phase4.incoming.AS4RequestHandler; @@ -84,7 +84,7 @@ public class ServletConfig public static IAS4CryptoFactory getCryptoFactoryToUse () { // If you have a custom crypto factory, build/return it here - return AS4CryptoFactoryProperties.getDefaultInstance (); + return AS4CryptoFactoryConfiguration.getDefaultInstance (); } public static class MyAS4Servlet extends AbstractXServlet @@ -203,8 +203,8 @@ private static void _initGlobalSettings (@Nonnull final ServletContext aSC) HttpDebugger.setEnabled (false); // Sanity check - if (CommandMap.getDefaultCommandMap ().createDataContentHandler (CMimeType.MULTIPART_RELATED.getAsString ()) == - null) + if (CommandMap.getDefaultCommandMap () + .createDataContentHandler (CMimeType.MULTIPART_RELATED.getAsString ()) == null) throw new IllegalStateException ("No DataContentHandler for MIME Type '" + CMimeType.MULTIPART_RELATED.getAsString () + "' is available. There seems to be a problem with the dependencies/packaging"); @@ -250,12 +250,12 @@ private static void _initPeppolAS4 () PeppolCRLDownloader.setAsDefaultCRLCache (new Phase4PeppolHttpClientSettings ()); // Check if crypto properties are okay - final KeyStore aKS = AS4CryptoFactoryProperties.getDefaultInstance ().getKeyStore (); + final KeyStore aKS = AS4CryptoFactoryConfiguration.getDefaultInstance ().getKeyStore (); if (aKS == null) throw new InitializationException ("Failed to load configured AS4 Key store - fix the configuration"); LOGGER.info ("Successfully loaded configured AS4 key store from the crypto factory"); - final KeyStore.PrivateKeyEntry aPKE = AS4CryptoFactoryProperties.getDefaultInstance ().getPrivateKeyEntry (); + final KeyStore.PrivateKeyEntry aPKE = AS4CryptoFactoryConfiguration.getDefaultInstance ().getPrivateKeyEntry (); if (aPKE == null) throw new InitializationException ("Failed to load configured AS4 private key - fix the configuration"); LOGGER.info ("Successfully loaded configured AS4 private key from the crypto factory"); diff --git a/phase4-test/src/test/java/com/helger/phase4/client/AS4ClientReceiptMessageTest.java b/phase4-test/src/test/java/com/helger/phase4/client/AS4ClientReceiptMessageTest.java index cb9bdcfc0..cfc7beeff 100644 --- a/phase4-test/src/test/java/com/helger/phase4/client/AS4ClientReceiptMessageTest.java +++ b/phase4-test/src/test/java/com/helger/phase4/client/AS4ClientReceiptMessageTest.java @@ -28,8 +28,8 @@ import com.helger.commons.io.resource.ClassPathResource; import com.helger.phase4.AS4TestConstants; -import com.helger.phase4.crypto.AS4CryptoFactoryProperties; -import com.helger.phase4.crypto.AS4CryptoProperties; +import com.helger.phase4.crypto.AS4CryptoFactoryInMemoryKeyStore; +import com.helger.phase4.crypto.AS4KeyStoreDescriptor; import com.helger.phase4.crypto.ECryptoAlgorithmSign; import com.helger.phase4.crypto.ECryptoAlgorithmSignDigest; import com.helger.phase4.model.ESoapVersion; @@ -121,12 +121,14 @@ public void testBuildMessageSignedChecks () throws Exception aClient.setNonRepudiation (true); aClient.setReceiptShouldBeSigned (true); - final AS4CryptoProperties aCP = new AS4CryptoProperties ().setKeyStoreType (EKeyStoreType.JKS) - .setKeyStorePath ("keys/dummy-pw-test.jks") - .setKeyStorePassword ("test") - .setKeyAlias ("ph-as4") - .setKeyPassword ("test"); - aClient.setCryptoFactory (new AS4CryptoFactoryProperties (aCP)); + aClient.setCryptoFactory (new AS4CryptoFactoryInMemoryKeyStore (AS4KeyStoreDescriptor.builder () + .type (EKeyStoreType.JKS) + .path ("keys/dummy-pw-test.jks") + .password ("test") + .keyAlias ("ph-as4") + .keyPassword ("test") + .build (), + null)); aClient.signingParams () .setAlgorithmSign (ECryptoAlgorithmSign.SIGN_ALGORITHM_DEFAULT) diff --git a/phase4-test/src/test/java/com/helger/phase4/client/AS4ClientUserMessageTest.java b/phase4-test/src/test/java/com/helger/phase4/client/AS4ClientUserMessageTest.java index c127a59ca..7818c9c45 100644 --- a/phase4-test/src/test/java/com/helger/phase4/client/AS4ClientUserMessageTest.java +++ b/phase4-test/src/test/java/com/helger/phase4/client/AS4ClientUserMessageTest.java @@ -41,8 +41,10 @@ import com.helger.phase4.AS4TestConstants; import com.helger.phase4.CAS4; import com.helger.phase4.attachment.EAS4CompressionMode; +import com.helger.phase4.crypto.AS4CryptoFactoryInMemoryKeyStore; import com.helger.phase4.crypto.AS4CryptoFactoryProperties; import com.helger.phase4.crypto.AS4CryptoProperties; +import com.helger.phase4.crypto.AS4KeyStoreDescriptor; import com.helger.phase4.crypto.ECryptoAlgorithmCrypt; import com.helger.phase4.crypto.ECryptoAlgorithmSign; import com.helger.phase4.crypto.ECryptoAlgorithmSignDigest; @@ -172,13 +174,15 @@ private static TestClientUserMessage _createMandatoryAttributesSuccessMessage () @Nonnull private static AS4ClientUserMessage _setKeyStoreTestData (@Nonnull final AS4ClientUserMessage aClient) { - final AS4CryptoProperties aCP = new AS4CryptoProperties ().setKeyStoreType (EKeyStoreType.JKS) - .setKeyStorePath ("keys/dummy-pw-test.jks") - .setKeyStorePassword ("test") - .setKeyAlias ("ph-as4") - .setKeyPassword ("test"); - aClient.setCryptoFactory (new AS4CryptoFactoryProperties (aCP)); - aClient.cryptParams ().setAlias (aCP.getKeyAlias ()); + final AS4KeyStoreDescriptor aKSD = AS4KeyStoreDescriptor.builder () + .type (EKeyStoreType.JKS) + .path ("keys/dummy-pw-test.jks") + .password ("test") + .keyAlias ("ph-as4") + .keyPassword ("test") + .build (); + aClient.setCryptoFactory (new AS4CryptoFactoryInMemoryKeyStore (aKSD, null)); + aClient.cryptParams ().setAlias (aKSD.getKeyAlias ()); return aClient; } diff --git a/phase4-test/src/test/java/com/helger/phase4/server/message/AbstractUserMessageTestSetUp.java b/phase4-test/src/test/java/com/helger/phase4/server/message/AbstractUserMessageTestSetUp.java index 91da2b82b..61f02474b 100644 --- a/phase4-test/src/test/java/com/helger/phase4/server/message/AbstractUserMessageTestSetUp.java +++ b/phase4-test/src/test/java/com/helger/phase4/server/message/AbstractUserMessageTestSetUp.java @@ -48,7 +48,7 @@ import com.helger.httpclient.HttpClientSettings; import com.helger.phase4.config.AS4Configuration; import com.helger.phase4.crypto.AS4CryptParams; -import com.helger.phase4.crypto.AS4CryptoFactoryProperties; +import com.helger.phase4.crypto.AS4CryptoFactoryConfiguration; import com.helger.phase4.crypto.IAS4CryptoFactory; import com.helger.phase4.messaging.http.AS4HttpDebug; import com.helger.phase4.messaging.http.HttpMimeMessageEntity; @@ -73,7 +73,7 @@ public abstract class AbstractUserMessageTestSetUp extends AbstractAS4TestSetUp protected static AS4ResourceHelper s_aResMgr; - protected final IAS4CryptoFactory m_aCryptoFactory = AS4CryptoFactoryProperties.getDefaultInstance (); + protected final IAS4CryptoFactory m_aCryptoFactory = AS4CryptoFactoryConfiguration.getDefaultInstance (); protected final AS4CryptParams m_aCryptParams = AS4CryptParams.createDefault ().setAlias ("ph-as4"); private final int m_nRetries; @@ -194,12 +194,13 @@ private String _sendPlainMessage (@Nonnull final HttpPost aPost, else { // 200, 400 or 500 - assertTrue ("Server responded with StatusCode=" + nStatusCode + ". Response:\n" + sResponse, + assertTrue ("Server responded with StatusCode=" + + nStatusCode + + ". Response:\n" + + sResponse, nStatusCode == CHttp.HTTP_OK || - nStatusCode == - CHttp.HTTP_BAD_REQUEST || - nStatusCode == - CHttp.HTTP_INTERNAL_SERVER_ERROR); + nStatusCode == CHttp.HTTP_BAD_REQUEST || + nStatusCode == CHttp.HTTP_INTERNAL_SERVER_ERROR); assertTrue ("Server responded with different error message than expected (" + sExecptedResponseContent + ")." + diff --git a/phase4-test/src/test/java/com/helger/phase4/server/message/MockMessages.java b/phase4-test/src/test/java/com/helger/phase4/server/message/MockMessages.java index 2e2b45ea7..3b336a70b 100644 --- a/phase4-test/src/test/java/com/helger/phase4/server/message/MockMessages.java +++ b/phase4-test/src/test/java/com/helger/phase4/server/message/MockMessages.java @@ -31,7 +31,7 @@ import com.helger.phase4.AS4TestConstants; import com.helger.phase4.CAS4; import com.helger.phase4.attachment.WSS4JAttachment; -import com.helger.phase4.crypto.AS4CryptoFactoryProperties; +import com.helger.phase4.crypto.AS4CryptoFactoryConfiguration; import com.helger.phase4.crypto.AS4SigningParams; import com.helger.phase4.ebms3header.Ebms3CollaborationInfo; import com.helger.phase4.ebms3header.Ebms3Error; @@ -70,7 +70,7 @@ public static Document createUserMessageSigned (@Nonnull final ESoapVersion eSOA @Nonnull final AS4ResourceHelper aResMgr) throws WSSecurityException { final AS4UserMessage aMsg = createUserMessageNotSigned (eSOAPVersion, aPayload, aAttachments); - return AS4Signer.createSignedMessage (AS4CryptoFactoryProperties.getDefaultInstance (), + return AS4Signer.createSignedMessage (AS4CryptoFactoryConfiguration.getDefaultInstance (), aMsg.getAsSoapDocument (aPayload), eSOAPVersion, aMsg.getMessagingID (), @@ -89,7 +89,7 @@ public static Document createErrorMessageSigned (@Nonnull final ESoapVersion eSO .build ()); final AS4ErrorMessage aErrorMsg = AS4ErrorMessage.create (eSOAPVersion, "srcmsgid", aEbms3ErrorList) .setMustUnderstand (true); - return AS4Signer.createSignedMessage (AS4CryptoFactoryProperties.getDefaultInstance (), + return AS4Signer.createSignedMessage (AS4CryptoFactoryConfiguration.getDefaultInstance (), aErrorMsg.getAsSoapDocument (), eSOAPVersion, aErrorMsg.getMessagingID (), @@ -109,7 +109,8 @@ public static AS4ReceiptMessage createReceiptMessage (@Nonnull final ESoapVersio aEbms3UserMessage, aUserMessage, true, - null).setMustUnderstand (true); + null) + .setMustUnderstand (true); } @Nonnull @@ -168,7 +169,8 @@ public static AS4UserMessage createUserMessageNotSigned (@Nonnull final ESoapVer aEbms3PartyInfo, aEbms3MessageProperties, null, - eSOAPVersion).setMustUnderstand (true); + eSOAPVersion) + .setMustUnderstand (true); } @Nonnull @@ -204,7 +206,8 @@ public static Document testUserMessageNotSignedNotPModeConform (@Nonnull final E aEbms3PartyInfo, aEbms3MessageProperties, null, - eSOAPVersion).setMustUnderstand (true); + eSOAPVersion) + .setMustUnderstand (true); return aDoc.getAsSoapDocument (aPayload); } @@ -239,7 +242,8 @@ public static Document createEmptyUserMessage (@Nonnull final ESoapVersion eSOAP aEbms3PartyInfo, aEbms3MessageProperties, null, - eSOAPVersion).setMustUnderstand (true); + eSOAPVersion) + .setMustUnderstand (true); return aDoc.getAsSoapDocument (aPayload); } } diff --git a/phase4-test/src/test/java/com/helger/phase4/server/supplementary/test/EncryptionTest.java b/phase4-test/src/test/java/com/helger/phase4/server/supplementary/test/EncryptionTest.java index 9dc8b5bc3..a903884e8 100644 --- a/phase4-test/src/test/java/com/helger/phase4/server/supplementary/test/EncryptionTest.java +++ b/phase4-test/src/test/java/com/helger/phase4/server/supplementary/test/EncryptionTest.java @@ -40,7 +40,7 @@ import com.helger.commons.io.resource.ClassPathResource; import com.helger.commons.io.stream.NonBlockingByteArrayOutputStream; -import com.helger.phase4.crypto.AS4CryptoFactoryProperties; +import com.helger.phase4.crypto.AS4CryptoFactoryConfiguration; import com.helger.phase4.crypto.ECryptoAlgorithmCrypt; import com.helger.phase4.crypto.ECryptoKeyIdentifierType; import com.helger.phase4.crypto.ECryptoMode; @@ -78,7 +78,7 @@ private static Document _getSoapEnvelope11 () private static String _prettyDocumentToString (final Document doc) throws TransformerException { - try (NonBlockingByteArrayOutputStream baos = new NonBlockingByteArrayOutputStream ()) + try (final NonBlockingByteArrayOutputStream baos = new NonBlockingByteArrayOutputStream ()) { XMLUtils.elementToStream (doc.getDocumentElement (), baos); return baos.getAsString (StandardCharsets.UTF_8); @@ -96,7 +96,7 @@ private static String _prettyDocumentToString (final Document doc) throws Transf @Test public void testEncryptionDecryptionAES128GCM () throws Exception { - final IAS4CryptoFactory aCryptoFactory = AS4CryptoFactoryProperties.getDefaultInstance (); + final IAS4CryptoFactory aCryptoFactory = AS4CryptoFactoryConfiguration.getDefaultInstance (); final Document aSoapDoc = _getSoapEnvelope11 (); final WSSecHeader aSecHeader = new WSSecHeader (aSoapDoc); @@ -129,7 +129,7 @@ public void testEncryptionDecryptionAES128GCM () throws Exception @Test public void testAES128GCM () throws Exception { - final IAS4CryptoFactory aCryptoFactory = AS4CryptoFactoryProperties.getDefaultInstance (); + final IAS4CryptoFactory aCryptoFactory = AS4CryptoFactoryConfiguration.getDefaultInstance (); final Document doc = _getSoapEnvelope11 (); final WSSecHeader secHeader = new WSSecHeader (doc); diff --git a/phase4-test/src/test/java/com/helger/phase4/server/supplementary/test/SignatureTest.java b/phase4-test/src/test/java/com/helger/phase4/server/supplementary/test/SignatureTest.java index 3a0739d6e..25af47de2 100644 --- a/phase4-test/src/test/java/com/helger/phase4/server/supplementary/test/SignatureTest.java +++ b/phase4-test/src/test/java/com/helger/phase4/server/supplementary/test/SignatureTest.java @@ -34,7 +34,7 @@ import org.w3c.dom.Document; import com.helger.commons.io.resource.ClassPathResource; -import com.helger.phase4.crypto.AS4CryptoFactoryProperties; +import com.helger.phase4.crypto.AS4CryptoFactoryConfiguration; import com.helger.phase4.crypto.ECryptoAlgorithmSign; import com.helger.phase4.crypto.ECryptoAlgorithmSignDigest; import com.helger.phase4.crypto.ECryptoKeyIdentifierType; @@ -78,7 +78,7 @@ private static Document _getSoapEnvelope11 () @Test public void testX509SignatureIS () throws Exception { - final IAS4CryptoFactory aCryptoFactory = AS4CryptoFactoryProperties.getDefaultInstance (); + final IAS4CryptoFactory aCryptoFactory = AS4CryptoFactoryConfiguration.getDefaultInstance (); final Document aDoc = _getSoapEnvelope11 (); final WSSecHeader aSecHeader = new WSSecHeader (aDoc);