Search in sources :

Example 1 with DefaultCertStoreCachePolicy

use of org.nhindirect.stagent.cert.DefaultCertStoreCachePolicy in project nhin-d by DirectProject.

the class XMLSmtpAgentConfig method buildPublicCertStore.

/*
	 * Build the certificate resolver for public certificates
	 */
@SuppressWarnings("unchecked")
private void buildPublicCertStore(Node publicCertNode) {
    Provider<CertificateResolver> resolverProvider = null;
    if (publicCertNode.getNodeType() == Node.ELEMENT_NODE) {
        Element certNode = (Element) publicCertNode;
        String storeType = certNode.getAttribute("type");
        /*
			 * KeyStore based resolver
			 */
        if (storeType.equalsIgnoreCase("keystore")) {
            resolverProvider = new KeyStoreCertificateStoreProvider(certNode.getAttribute("file"), certNode.getAttribute("filePass"), certNode.getAttribute("privKeyPass"));
        } else /*
			 * DNS resolver
			 */
        if (storeType.equalsIgnoreCase("dns")) {
            resolverProvider = new DNSCertStoreProvider(Collections.EMPTY_LIST, null, new DefaultCertStoreCachePolicy());
        } else /*
			 * Default to DNS with a default cache policy
			 */
        {
            resolverProvider = new DNSCertStoreProvider(Collections.EMPTY_LIST, null, new DefaultCertStoreCachePolicy());
        }
    }
    resolverProviders.add(resolverProvider);
}
Also used : KeyStoreCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.KeyStoreCertificateStoreProvider) DefaultCertStoreCachePolicy(org.nhindirect.stagent.cert.DefaultCertStoreCachePolicy) Element(org.w3c.dom.Element) DNSCertStoreProvider(org.nhindirect.stagent.cert.impl.provider.DNSCertStoreProvider) CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver)

Example 2 with DefaultCertStoreCachePolicy

use of org.nhindirect.stagent.cert.DefaultCertStoreCachePolicy in project nhin-d by DirectProject.

the class XMLSmtpAgentConfig method buildLdapCertificateStoreProvider.

/**
	 * This will build an LdapCertificateStoreProvider to be used to grab certificates from the LDAP store.
	 * @param anchorStoreNode - The Element node in the xml file that contains anchor information
	 * @param cacheStoreName - The name of the bootstrap cacheStore used when cache and LDAP are unreachable.
	 * @return
	 */
protected LdapCertificateStoreProvider buildLdapCertificateStoreProvider(Element anchorStoreNode, String cacheStoreName) {
    //required
    String[] ldapURL = anchorStoreNode.getAttribute("ldapURL").split(",");
    String ldapSearchBase = anchorStoreNode.getAttribute("ldapSearchBase");
    String ldapSearchAttr = anchorStoreNode.getAttribute("ldapSearchAttr");
    String ldapCertAttr = anchorStoreNode.getAttribute("ldapCertAttr");
    String ldapCertFormat = anchorStoreNode.getAttribute("ldapCertFormat");
    if (ldapURL[0].isEmpty() || ldapSearchBase.isEmpty() || ldapSearchAttr.isEmpty() || ldapCertAttr.isEmpty() || ldapCertFormat.isEmpty()) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat);
    }
    //optional	    
    String ldapUser = anchorStoreNode.getAttribute("ldapUser");
    String ldapPassword = anchorStoreNode.getAttribute("ldapPassword");
    String ldapConnTimeout = anchorStoreNode.getAttribute("ldapConnTimeout");
    String ldapCertPassphrase = anchorStoreNode.getAttribute("ldapCertPassphrase");
    if (ldapCertFormat.equalsIgnoreCase("pkcs12") && ldapCertPassphrase.isEmpty()) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat);
    }
    LdapStoreConfiguration ldapStoreConfiguration = new LdapStoreConfiguration(ldapURL, ldapSearchBase, ldapSearchAttr, ldapCertAttr, ldapCertFormat);
    if (!(ldapUser.isEmpty() && ldapPassword.isEmpty())) {
        ldapStoreConfiguration.setEmployLdapAuthInformation(new EmployLdapAuthInformation(ldapUser, ldapPassword));
    }
    if (!ldapConnTimeout.isEmpty()) {
        ldapStoreConfiguration.setLdapConnectionTimeOut(ldapConnTimeout);
    }
    if (!ldapCertPassphrase.isEmpty()) {
        ldapStoreConfiguration.setLdapCertPassphrase(ldapCertPassphrase);
    }
    LdapCertificateStoreProvider ldapCertificateStoreProvider = new LdapCertificateStoreProvider(ldapStoreConfiguration, null, new DefaultCertStoreCachePolicy());
    return ldapCertificateStoreProvider;
}
Also used : LdapStoreConfiguration(org.nhindirect.stagent.cert.impl.LdapStoreConfiguration) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) DefaultCertStoreCachePolicy(org.nhindirect.stagent.cert.DefaultCertStoreCachePolicy) EmployLdapAuthInformation(org.nhindirect.stagent.cert.impl.EmployLdapAuthInformation) LdapCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.LdapCertificateStoreProvider)

Example 3 with DefaultCertStoreCachePolicy

use of org.nhindirect.stagent.cert.DefaultCertStoreCachePolicy in project nhin-d by DirectProject.

the class CacheableKeyStoreManagerCertificateStore_constructTest method testContrust_providedStoreAndCachePolicy_assertNonEmptyStoreAndCustomPolicy.

public void testContrust_providedStoreAndCachePolicy_assertNonEmptyStoreAndCustomPolicy() throws Exception {
    DefaultCertStoreCachePolicy policy = new DefaultCertStoreCachePolicy();
    policy.setMaxItems(456);
    policy.setSubjectTTL(999);
    final BootstrappedKeyStoreProtectionManager mgr = new BootstrappedKeyStoreProtectionManager();
    final CacheableKeyStoreManagerCertificateStore store = new CacheableKeyStoreManagerCertificateStore(mgr, policy);
    assertNotNull(store.storeMgr);
    assertNotNull(store.cachePolicy);
    assertEquals(456, store.cachePolicy.getMaxItems());
    assertEquals(999, store.cachePolicy.getSubjectTTL());
}
Also used : DefaultCertStoreCachePolicy(org.nhindirect.stagent.cert.DefaultCertStoreCachePolicy) BootstrappedKeyStoreProtectionManager(org.nhindirect.common.crypto.impl.BootstrappedKeyStoreProtectionManager)

Aggregations

DefaultCertStoreCachePolicy (org.nhindirect.stagent.cert.DefaultCertStoreCachePolicy)3 BootstrappedKeyStoreProtectionManager (org.nhindirect.common.crypto.impl.BootstrappedKeyStoreProtectionManager)1 SmtpAgentException (org.nhindirect.gateway.smtp.SmtpAgentException)1 CertificateResolver (org.nhindirect.stagent.cert.CertificateResolver)1 EmployLdapAuthInformation (org.nhindirect.stagent.cert.impl.EmployLdapAuthInformation)1 LdapStoreConfiguration (org.nhindirect.stagent.cert.impl.LdapStoreConfiguration)1 DNSCertStoreProvider (org.nhindirect.stagent.cert.impl.provider.DNSCertStoreProvider)1 KeyStoreCertificateStoreProvider (org.nhindirect.stagent.cert.impl.provider.KeyStoreCertificateStoreProvider)1 LdapCertificateStoreProvider (org.nhindirect.stagent.cert.impl.provider.LdapCertificateStoreProvider)1 Element (org.w3c.dom.Element)1