Search in sources :

Example 1 with EKeyStoreType

use of com.helger.security.keystore.EKeyStoreType in project as2-lib by phax.

the class AbstractCertificateFactory method initEmptyKeyStore.

/**
 * This method is responsible to create a new empty keystore based on the
 * configured type.
 *
 * @throws AS2Exception
 *         In case of error
 * @see #getKeyStoreType()
 * @see #createNewKeyStore(EKeyStoreType)
 * @see #setKeyStore(KeyStore)
 */
protected void initEmptyKeyStore() throws AS2Exception {
    try {
        final String sKeyStoreType = getKeyStoreType();
        final EKeyStoreType eKeyStoreType = EKeyStoreType.getFromIDCaseInsensitiveOrDefault(sKeyStoreType, DEFAULT_KEY_STORE_TYPE);
        if (LOGGER.isInfoEnabled())
            LOGGER.info("Using internal keystore of type " + eKeyStoreType);
        final KeyStore aKeyStore = createNewKeyStore(eKeyStoreType);
        if (aKeyStore == null) {
            debugLog(() -> "initDynamicComponent -> no keystore");
            throw new InitializationException("Failed to create new keystore with type " + eKeyStoreType);
        }
        setKeyStore(aKeyStore);
    } catch (final GeneralSecurityException ex) {
        debugLog(() -> "initDynamicComponent -> " + _debug(ex));
        throw WrappedAS2Exception.wrap(ex);
    }
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) EKeyStoreType(com.helger.security.keystore.EKeyStoreType) InitializationException(com.helger.commons.exception.InitializationException) KeyStore(java.security.KeyStore)

Example 2 with EKeyStoreType

use of com.helger.security.keystore.EKeyStoreType in project phoss-directory by phax.

the class PDServerConfiguration method getAllTrustStores.

/**
 * @return A list of trust stores configured. Property names are
 *         <code>truststore.X.type</code>, <code>truststore.X.path</code>,
 *         <code>truststore.X.password</code>,
 *         <code>truststore.X.alias</code>, where "X" is an ascending number
 *         starting from 1.
 * @since 0.6.0
 */
@Nonnull
public static ICommonsList<PDConfiguredTrustStore> getAllTrustStores() {
    final ICommonsList<PDConfiguredTrustStore> ret = new CommonsArrayList<>();
    int nIndex = 1;
    while (true) {
        final String sPrefix = "truststore." + nIndex;
        final String sType = getConfig().getAsString(sPrefix + ".type");
        final EKeyStoreType eType = EKeyStoreType.getFromIDCaseInsensitiveOrDefault(sType, PeppolKeyStoreHelper.TRUSTSTORE_TYPE);
        final String sPath = getConfig().getAsString(sPrefix + ".path");
        final String sPassword = getConfig().getAsString(sPrefix + ".password");
        final String sAlias = getConfig().getAsString(sPrefix + ".alias");
        if (StringHelper.hasNoText(sPath) || StringHelper.hasNoText(sPassword) || StringHelper.hasNoText(sAlias))
            break;
        // Present - try next
        ret.add(new PDConfiguredTrustStore(eType, sPath, sPassword, sAlias));
        ++nIndex;
    }
    return ret;
}
Also used : EKeyStoreType(com.helger.security.keystore.EKeyStoreType) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) Nonnull(javax.annotation.Nonnull)

Example 3 with EKeyStoreType

use of com.helger.security.keystore.EKeyStoreType in project peppol-commons by phax.

the class MainForArunFromBasware method main.

public static void main(final String[] args) throws Exception {
    // START MODIFY BELOW
    // Your SMP ID
    final String SMP_ID = "TEST-SMP";
    // Use SMK or SML?
    final ISMLInfo aSMLInfo = ESML.DIGIT_TEST;
    // Keystore path and password
    final EKeyStoreType eKeyStoreType = EKeyStoreType.JKS;
    final String sKeystorePath = "keystore/smp.pilot.jks";
    final String sKeystorePassword = "peppol";
    // Participant to be created
    final String sServiceGroupID = "0088:5798000000001";
    // Create (true) or delete (false) participant?
    final boolean bCreate = false;
    // Proxy server settings
    final String sProxyHostname = null;
    final int nProxyPort = 0;
    WSHelper.setMetroDebugSystemProperties(true);
    // Set proxy as system properties
    if (nProxyPort > 0 && StringHelper.hasText(sProxyHostname)) {
        SystemProperties.setPropertyValue("http.proxyHost", sProxyHostname);
        SystemProperties.setPropertyValue("http.proxyPort", nProxyPort);
        SystemProperties.setPropertyValue("https.proxyHost", sProxyHostname);
        SystemProperties.setPropertyValue("https.proxyPort", nProxyPort);
    }
    final ManageParticipantIdentifierServiceCaller aParticipantClient = new ManageParticipantIdentifierServiceCaller(aSMLInfo);
    if (aSMLInfo.isClientCertificateRequired()) {
        // Main key storage
        final KeyStore aKeyStore = KeyStoreHelper.loadKeyStoreDirect(eKeyStoreType, sKeystorePath, sKeystorePassword);
        // Key manager
        final KeyManagerFactory aKeyManagerFactory = KeyManagerFactory.getInstance("SunX509");
        aKeyManagerFactory.init(aKeyStore, sKeystorePassword.toCharArray());
        // Assign key manager and empty trust manager to SSL context
        final SSLContext aSSLCtx = SSLContext.getInstance("TLS");
        aSSLCtx.init(aKeyManagerFactory.getKeyManagers(), new TrustManager[] { new TrustManagerTrustAll(false) }, null);
        aParticipantClient.setSSLSocketFactory(aSSLCtx.getSocketFactory());
    }
    // Main WS call
    final IParticipantIdentifier aServiceGroupID = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme(sServiceGroupID);
    if (bCreate) {
        // Create
        aParticipantClient.create(SMP_ID, aServiceGroupID);
        LOGGER.info("Successfully created participant " + aServiceGroupID.getURIEncoded());
    } else {
        // Delete
        aParticipantClient.delete(SMP_ID, aServiceGroupID);
        LOGGER.info("Successfully deleted participant " + aServiceGroupID.getURIEncoded());
    }
}
Also used : ISMLInfo(com.helger.peppol.sml.ISMLInfo) EKeyStoreType(com.helger.security.keystore.EKeyStoreType) SSLContext(javax.net.ssl.SSLContext) KeyStore(java.security.KeyStore) TrustManagerTrustAll(com.helger.commons.ws.TrustManagerTrustAll) ManageParticipantIdentifierServiceCaller(com.helger.peppol.smlclient.ManageParticipantIdentifierServiceCaller) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Aggregations

EKeyStoreType (com.helger.security.keystore.EKeyStoreType)3 KeyStore (java.security.KeyStore)2 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)1 InitializationException (com.helger.commons.exception.InitializationException)1 TrustManagerTrustAll (com.helger.commons.ws.TrustManagerTrustAll)1 ISMLInfo (com.helger.peppol.sml.ISMLInfo)1 ManageParticipantIdentifierServiceCaller (com.helger.peppol.smlclient.ManageParticipantIdentifierServiceCaller)1 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)1 GeneralSecurityException (java.security.GeneralSecurityException)1 Nonnull (javax.annotation.Nonnull)1 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)1 SSLContext (javax.net.ssl.SSLContext)1