Skip to content

Commit

Permalink
Using ph-commons classes
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Nov 10, 2024
1 parent 229942a commit 76c8915
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 651 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
import com.helger.phase4.client.AS4ClientReceiptMessage;
import com.helger.phase4.client.AS4ClientSentMessage;
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;
Expand All @@ -68,6 +66,8 @@
import com.helger.phase4.util.AS4ResourceHelper;
import com.helger.phase4.util.Phase4Exception;
import com.helger.security.keystore.EKeyStoreType;
import com.helger.security.keystore.KeyStoreAndKeyDescriptor;
import com.helger.security.keystore.TrustStoreDescriptor;
import com.helger.servlet.mock.MockServletContext;
import com.helger.web.scope.mgr.WebScopeManager;

Expand All @@ -80,21 +80,21 @@ public class MainPhase4EuCtpSenderExample
@Nonnull
private static IAS4CryptoFactory _buildAs4CryptoFactory ()
{
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 (),
return new AS4CryptoFactoryInMemoryKeyStore (KeyStoreAndKeyDescriptor.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 ());
TrustStoreDescriptor.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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import com.helger.config.IConfig;
import com.helger.config.fallback.IConfigWithFallback;
import com.helger.phase4.config.AS4Configuration;
import com.helger.security.keystore.IKeyStoreAndKeyDescriptor;
import com.helger.security.keystore.ITrustStoreDescriptor;
import com.helger.security.keystore.LoadedKey;
import com.helger.security.keystore.LoadedKeyStore;

Expand Down Expand Up @@ -93,8 +95,8 @@ public static AS4CryptoFactoryConfiguration getDefaultInstanceOrNull ()
}
}

private final IAS4KeyStoreDescriptor m_aKeyStoreDesc;
private final IAS4TrustStoreDescriptor m_aTrustStorDesc;
private final IKeyStoreAndKeyDescriptor m_aKeyStoreDesc;
private final ITrustStoreDescriptor m_aTrustStorDesc;

/**
* This constructor takes the configuration object and uses the default prefix
Expand All @@ -109,10 +111,10 @@ public AS4CryptoFactoryConfiguration (@Nonnull final IConfigWithFallback aConfig
}

@Nonnull
private static IAS4KeyStoreDescriptor _loadKeyStore (@Nonnull final IConfigWithFallback aConfig,
@Nonnull @Nonempty final String sConfigPrefix)
private static IKeyStoreAndKeyDescriptor _loadKeyStore (@Nonnull final IConfigWithFallback aConfig,
@Nonnull @Nonempty final String sConfigPrefix)
{
final IAS4KeyStoreDescriptor aDescriptor = AS4KeyStoreDescriptor.createFromConfig (aConfig, sConfigPrefix, null);
final IKeyStoreAndKeyDescriptor aDescriptor = AS4KeyStoreDescriptor.createFromConfig (aConfig, sConfigPrefix, null);
final LoadedKeyStore aLKS = aDescriptor.loadKeyStore ();
if (aLKS.getKeyStore () == null)
{
Expand All @@ -136,13 +138,11 @@ private static IAS4KeyStoreDescriptor _loadKeyStore (@Nonnull final IConfigWithF
}

@Nullable
private static IAS4TrustStoreDescriptor _loadTrustStore (@Nonnull final IConfigWithFallback aConfig,
@Nonnull @Nonempty final String sConfigPrefix)
private static ITrustStoreDescriptor _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 ITrustStoreDescriptor aDescriptor = AS4TrustStoreDescriptor.createFromConfig (aConfig, sConfigPrefix, null);
if (aDescriptor != null)
{
final LoadedKeyStore aLTS = aDescriptor.loadTrustStore ();
Expand Down Expand Up @@ -182,8 +182,8 @@ public AS4CryptoFactoryConfiguration (@Nonnull final IConfigWithFallback aConfig
* The trust store descriptor. May be <code>null</code> in which case
* the global JRE CA certs list will be used.
*/
private AS4CryptoFactoryConfiguration (@Nonnull final IAS4KeyStoreDescriptor aKeyStoreDesc,
@Nonnull final IAS4TrustStoreDescriptor aTrustStorDesc)
private AS4CryptoFactoryConfiguration (@Nonnull final IKeyStoreAndKeyDescriptor aKeyStoreDesc,
@Nonnull final ITrustStoreDescriptor aTrustStorDesc)
{
super (aKeyStoreDesc, aTrustStorDesc);
m_aKeyStoreDesc = aKeyStoreDesc;
Expand All @@ -194,7 +194,7 @@ private AS4CryptoFactoryConfiguration (@Nonnull final IAS4KeyStoreDescriptor aKe
* @return The descriptor used to load the key store. Never <code>null</code>.
*/
@Nonnull
public IAS4KeyStoreDescriptor getKeyStoreDescriptor ()
public IKeyStoreAndKeyDescriptor getKeyStoreDescriptor ()
{
return m_aKeyStoreDesc;
}
Expand All @@ -204,7 +204,7 @@ public IAS4KeyStoreDescriptor getKeyStoreDescriptor ()
* <code>null</code>.
*/
@Nonnull
public IAS4TrustStoreDescriptor getTrustStoreDescriptor ()
public ITrustStoreDescriptor getTrustStoreDescriptor ()
{
return m_aTrustStorDesc;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import com.helger.commons.ValueEnforcer;
import com.helger.commons.annotation.Nonempty;
import com.helger.commons.string.ToStringGenerator;
import com.helger.security.keystore.IKeyStoreAndKeyDescriptor;
import com.helger.security.keystore.ITrustStoreDescriptor;

/**
* This class contains an implementation of {@link IAS4CryptoFactory} in which
Expand Down Expand Up @@ -58,8 +60,8 @@ public class AS4CryptoFactoryInMemoryKeyStore extends AbstractAS4CryptoFactory
* the global JRE CA certs list will be used.
* @since 3.0.0
*/
public AS4CryptoFactoryInMemoryKeyStore (@Nonnull final IAS4KeyStoreDescriptor aKeyStoreDesc,
@Nullable final IAS4TrustStoreDescriptor aTrustStoreDesc)
public AS4CryptoFactoryInMemoryKeyStore (@Nonnull final IKeyStoreAndKeyDescriptor aKeyStoreDesc,
@Nullable final ITrustStoreDescriptor aTrustStoreDesc)
{
this (aKeyStoreDesc.loadKeyStore ().getKeyStore (),
aKeyStoreDesc.getKeyAlias (),
Expand Down
Loading

0 comments on commit 76c8915

Please sign in to comment.