Search in sources :

Example 6 with CertPolicy

use of org.nhind.config.CertPolicy in project nhin-d by DirectProject.

the class ConfigServiceDNSStore_configCertPolicyTest method testConfigCertPolicy_invalidPolicy_assertNoPolicyConfiged.

public void testConfigCertPolicy_invalidPolicy_assertNoPolicyConfiged() throws Exception {
    System.setProperty(ConfigServiceDNSStore.DNS_CERT_POLICY_NAME_VAR, "InvalidPolicy");
    try {
        final CertPolicy policy = new CertPolicy();
        policy.setLexicon(PolicyLexicon.SIMPLE_TEXT_V1);
        policy.setPolicyName("InvalidPolicy");
        policy.setPolicyData(INVALID_VALID_POLICY.getBytes());
        proxy.addPolicy(policy);
        final ConfigServiceDNSStore store = new ConfigServiceDNSStore(new URL(ConfigServiceRunner.getConfigServiceURL()));
        assertNull(store.polExpression);
        assertNull(store.polFilter);
    } finally {
        System.setProperty(ConfigServiceDNSStore.DNS_CERT_POLICY_NAME_VAR, "");
    }
}
Also used : CertPolicy(org.nhind.config.CertPolicy) URL(java.net.URL)

Example 7 with CertPolicy

use of org.nhind.config.CertPolicy in project nhin-d by DirectProject.

the class ConfigServiceDNSStore_isCertCompliantWithPolicyTest method testisCertCompliantWithPolicy_policyConfigured_nonCompliantCert_assertNonCompliant.

public void testisCertCompliantWithPolicy_policyConfigured_nonCompliantCert_assertNonCompliant() throws Exception {
    System.setProperty(ConfigServiceDNSStore.DNS_CERT_POLICY_NAME_VAR, "ValidPolicy");
    try {
        final CertPolicy policy = new CertPolicy();
        policy.setLexicon(PolicyLexicon.SIMPLE_TEXT_V1);
        policy.setPolicyName("ValidPolicy");
        policy.setPolicyData(KEY_ENC_POLICY.getBytes());
        proxy.addPolicy(policy);
        final ConfigServiceDNSStore store = new ConfigServiceDNSStore(new URL(ConfigServiceRunner.getConfigServiceURL()));
        assertNotNull(store.polExpression);
        assertNotNull(store.polFilter);
        X509Certificate cert = DNSRecordUtil.loadCertificate("umesh.der");
        assertFalse(store.isCertCompliantWithPolicy(cert));
    } finally {
        System.setProperty(ConfigServiceDNSStore.DNS_CERT_POLICY_NAME_VAR, "");
    }
}
Also used : CertPolicy(org.nhind.config.CertPolicy) URL(java.net.URL) X509Certificate(java.security.cert.X509Certificate)

Example 8 with CertPolicy

use of org.nhind.config.CertPolicy in project nhin-d by DirectProject.

the class ConfigServiceDNSStore_isCertCompliantWithPolicyTest method testisCertCompliantWithPolicy_policyConfigured_compliantCert_assertCompliant.

public void testisCertCompliantWithPolicy_policyConfigured_compliantCert_assertCompliant() throws Exception {
    System.setProperty(ConfigServiceDNSStore.DNS_CERT_POLICY_NAME_VAR, "ValidPolicy");
    try {
        final CertPolicy policy = new CertPolicy();
        policy.setLexicon(PolicyLexicon.SIMPLE_TEXT_V1);
        policy.setPolicyName("ValidPolicy");
        policy.setPolicyData(KEY_ENC_POLICY.getBytes());
        proxy.addPolicy(policy);
        final ConfigServiceDNSStore store = new ConfigServiceDNSStore(new URL(ConfigServiceRunner.getConfigServiceURL()));
        assertNotNull(store.polExpression);
        assertNotNull(store.polFilter);
        X509Certificate cert = DNSRecordUtil.loadCertificate("bob.der");
        assertTrue(store.isCertCompliantWithPolicy(cert));
    } finally {
        System.setProperty(ConfigServiceDNSStore.DNS_CERT_POLICY_NAME_VAR, "");
    }
}
Also used : CertPolicy(org.nhind.config.CertPolicy) URL(java.net.URL) X509Certificate(java.security.cert.X509Certificate)

Example 9 with CertPolicy

use of org.nhind.config.CertPolicy in project nhin-d by DirectProject.

the class WSSmtpAgentConfig method addPolicyToMap.

public void addPolicyToMap(Map<String, Collection<PolicyExpression>> policyMap, String domainName, CertPolicyGroupReltn policyReltn) {
    // check to see if the domain is in the map
    Collection<PolicyExpression> policyExpressionCollection = policyMap.get(domainName);
    if (policyExpressionCollection == null) {
        policyExpressionCollection = new ArrayList<PolicyExpression>();
        policyMap.put(domainName, policyExpressionCollection);
    }
    final CertPolicy policy = policyReltn.getCertPolicy();
    final PolicyLexicon lexicon;
    if (policy.getLexicon().equals(org.nhind.config.PolicyLexicon.JAVA_SER))
        lexicon = PolicyLexicon.JAVA_SER;
    else if (policy.getLexicon().equals(org.nhind.config.PolicyLexicon.SIMPLE_TEXT_V1))
        lexicon = PolicyLexicon.SIMPLE_TEXT_V1;
    else
        lexicon = PolicyLexicon.XML;
    final InputStream inStr = new ByteArrayInputStream(policy.getPolicyData());
    try {
        // grab a parser and compile this policy
        final PolicyLexiconParser parser = PolicyLexiconParserFactory.getInstance(lexicon);
        policyExpressionCollection.add(parser.parse(inStr));
    } catch (PolicyParseException ex) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "Failed parse policy into policy expression: " + ex.getMessage(), ex);
    } finally {
        IOUtils.closeQuietly(inStr);
    }
}
Also used : PolicyLexicon(org.nhindirect.policy.PolicyLexicon) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) CertPolicy(org.nhind.config.CertPolicy) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PolicyLexiconParser(org.nhindirect.policy.PolicyLexiconParser) PolicyExpression(org.nhindirect.policy.PolicyExpression) PolicyParseException(org.nhindirect.policy.PolicyParseException)

Example 10 with CertPolicy

use of org.nhind.config.CertPolicy in project nhin-d by DirectProject.

the class ClientProxyCertificatePolicyTest method testAddGetRemovePolicyGroupAndDomain_dissasociateGroupBeforeDeleteDomain.

@Test
public void testAddGetRemovePolicyGroupAndDomain_dissasociateGroupBeforeDeleteDomain() throws Exception {
    CertPolicy addPolicy = new CertPolicy();
    addPolicy.setLexicon(PolicyLexicon.XML);
    addPolicy.setPolicyName("Test Policy");
    addPolicy.setPolicyData(new byte[] { 1, 2, 3 });
    proxy.addPolicy(addPolicy);
    CertPolicy[] retrievedPolicies = proxy.getPolicies();
    assertEquals(1, retrievedPolicies.length);
    CertPolicyGroup addGroup = new CertPolicyGroup();
    addGroup.setPolicyGroupName("Test Group");
    proxy.addPolicyGroup(addGroup);
    CertPolicyGroup[] retrievedGroups = proxy.getPolicyGroups();
    assertEquals(1, retrievedGroups.length);
    proxy.addPolicyUseToGroup(retrievedGroups[0].getId(), retrievedPolicies[0].getId(), CertPolicyUse.TRUST, true, true);
    CertPolicyGroup retrievedGroup = proxy.getPolicyGroupById(retrievedGroups[0].getId());
    assertNotNull(retrievedGroup);
    assertEquals(1, retrievedGroup.getCertPolicyGroupReltn().length);
    assertEquals(addPolicy.getPolicyName(), retrievedGroup.getCertPolicyGroupReltn()[0].getCertPolicy().getPolicyName());
    Domain domain = new Domain();
    domain.setDomainName("Test Domain");
    proxy.addDomain(domain);
    Domain[] retrievedDomains = proxy.getDomains(new String[] { domain.getDomainName() }, null);
    assertEquals(1, retrievedDomains.length);
    proxy.associatePolicyGroupToDomain(retrievedDomains[0].getId(), retrievedGroups[0].getId());
    CertPolicyGroupDomainReltn[] domainGroups = proxy.getPolicyGroupsByDomain(retrievedDomains[0].getId());
    assertEquals(1, domainGroups.length);
    // remove policy from single domain
    proxy.disassociatePolicyGroupFromDomain(retrievedDomains[0].getId(), retrievedGroups[0].getId());
    domainGroups = proxy.getPolicyGroupsByDomain(retrievedDomains[0].getId());
    assertNull(domainGroups);
    // should delete domain without error
    proxy.removeDomainById(retrievedDomains[0].getId());
}
Also used : CertPolicyGroupDomainReltn(org.nhind.config.CertPolicyGroupDomainReltn) CertPolicy(org.nhind.config.CertPolicy) CertPolicyGroup(org.nhind.config.CertPolicyGroup) Domain(org.nhind.config.Domain) Test(org.junit.Test)

Aggregations

CertPolicy (org.nhind.config.CertPolicy)11 CertPolicyGroup (org.nhind.config.CertPolicyGroup)6 Test (org.junit.Test)5 URL (java.net.URL)4 Domain (org.nhind.config.Domain)4 CertPolicyGroupDomainReltn (org.nhind.config.CertPolicyGroupDomainReltn)3 X509Certificate (java.security.cert.X509Certificate)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Before (org.junit.Before)1 SmtpAgentException (org.nhindirect.gateway.smtp.SmtpAgentException)1 PolicyExpression (org.nhindirect.policy.PolicyExpression)1 PolicyLexicon (org.nhindirect.policy.PolicyLexicon)1 PolicyLexiconParser (org.nhindirect.policy.PolicyLexiconParser)1 PolicyParseException (org.nhindirect.policy.PolicyParseException)1