use of com.yahoo.athenz.common.server.dns.HostnameResolver in project athenz by yahoo.
the class SecureBootProviderTest method testConfirmInstanceWithSanIp.
@Test
public void testConfirmInstanceWithSanIp() {
System.setProperty(SecureBootProvider.ZTS_PROP_SB_ATTR_VALIDATOR_FACTORY_CLASS, "com.yahoo.athenz.instance.provider.impl.MockAttrValidatorFactory");
HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
Mockito.when(hostnameResolver.getAllByName("athenz-examples1.abc.com")).thenReturn(new HashSet<>(Arrays.asList("10.1.1.2", "2001:db8:a0b:12f0:0:0:0:1")));
SecureBootProvider provider = new SecureBootProvider();
provider.initialize("sys.auth.sb-provider", "com.yahoo.athenz.instance.provider.impl.SecureBootProvider", null, null);
provider.setHostnameResolver(hostnameResolver);
InstanceConfirmation confirmation = new InstanceConfirmation();
confirmation.setAttestationData("sample attestation data");
confirmation.setDomain("sports");
confirmation.setService("api");
confirmation.setProvider("sys.auth.sb-provider");
Map<String, String> attributes = new HashMap<>();
String subjectDn = "CN=athenz-examples1.abc.com,OU=Testing Domain,O=Athenz,L=LA,ST=CA,C=US";
attributes.put(InstanceProvider.ZTS_INSTANCE_SAN_DNS, "api.sports.zts.athenz.cloud,inst1.instanceid.athenz.zts.athenz.cloud");
attributes.put(InstanceProvider.ZTS_INSTANCE_HOSTNAME, "athenz-examples1.abc.com");
attributes.put(InstanceProvider.ZTS_INSTANCE_SAN_IP, "10.1.1.2");
attributes.put(InstanceProvider.ZTS_INSTANCE_CERT_ISSUER_DN, "CN=issuer1");
attributes.put(InstanceProvider.ZTS_INSTANCE_CERT_SUBJECT_DN, subjectDn);
confirmation.setAttributes(attributes);
assertNotNull(provider.confirmInstance(confirmation));
provider.close();
System.clearProperty(SecureBootProvider.ZTS_PROP_SB_ATTR_VALIDATOR_FACTORY_CLASS);
}
use of com.yahoo.athenz.common.server.dns.HostnameResolver in project athenz by yahoo.
the class SecureBootProviderTest method testValidateSanIp.
@Test
public void testValidateSanIp() {
assertTrue(new SecureBootProvider().validateSanIp("athenz-examples1.abc.com", null));
assertTrue(new SecureBootProvider().validateSanIp("athenz-examples1.abc.com", new HashMap<>()));
HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
Mockito.when(hostnameResolver.getAllByName("athenz-examples1.abc.com")).thenReturn(new HashSet<>(Arrays.asList("10.1.1.2", "2001:db8:a0b:12f0:0:0:0:1")));
SecureBootProvider provider = new SecureBootProvider();
provider.initialize("sys.auth.sb-provider", "com.yahoo.athenz.instance.provider.impl.SecureBootProvider", null, null);
provider.setHostnameResolver(hostnameResolver);
assertTrue(provider.validateSanIp("athenz-examples1.abc.com", Collections.singletonMap(InstanceProvider.ZTS_INSTANCE_SAN_IP, "10.1.1.2,2001:db8:a0b:12f0:0:0:0:1")));
assertTrue(provider.validateSanIp("athenz-examples1.abc.com", Collections.singletonMap(InstanceProvider.ZTS_INSTANCE_SAN_IP, "10.1.1.2")));
assertTrue(provider.validateSanIp("athenz-examples1.abc.com", Collections.singletonMap(InstanceProvider.ZTS_INSTANCE_SAN_IP, "2001:db8:a0b:12f0:0:0:0:1")));
assertTrue(provider.validateSanIp("athenz-examples1.abc.com", Collections.singletonMap(InstanceProvider.ZTS_INSTANCE_SAN_IP, "2001:db8:a0b:12f0:0:0:0:1,10.1.1.2")));
assertFalse(provider.validateSanIp("athenz-examples1.abc.com", Collections.singletonMap(InstanceProvider.ZTS_INSTANCE_SAN_IP, "10.1.1.3")));
assertFalse(provider.validateSanIp("athenz-examples1.abc.com", Collections.singletonMap(InstanceProvider.ZTS_INSTANCE_SAN_IP, "10.1.1.3,2001:db8:a0b:12f0:0:0:0:1")));
assertFalse(provider.validateSanIp("athenz-examples1.abc.com", Collections.singletonMap(InstanceProvider.ZTS_INSTANCE_SAN_IP, "10.1.1.2,2001:db8:a0b:12f0:0:0:0:2")));
}
use of com.yahoo.athenz.common.server.dns.HostnameResolver in project athenz by yahoo.
the class SecureBootProviderTest method testConfirmInstanceInvalidSanDns.
@Test
public void testConfirmInstanceInvalidSanDns() {
System.setProperty(SecureBootProvider.ZTS_PROP_SB_ATTR_VALIDATOR_FACTORY_CLASS, "com.yahoo.athenz.instance.provider.impl.MockAttrValidatorFactory");
HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
Mockito.when(hostnameResolver.getAllByName("athenz-examples1.abc.com")).thenReturn(new HashSet<>(Arrays.asList("10.1.1.2", "2001:db8:a0b:12f0:0:0:0:1")));
SecureBootProvider provider = new SecureBootProvider();
provider.initialize("sys.auth.sb-provider", "com.yahoo.athenz.instance.provider.impl.SecureBootProvider", null, null);
provider.setHostnameResolver(hostnameResolver);
InstanceConfirmation confirmation = new InstanceConfirmation();
confirmation.setAttestationData("sample attestation data");
confirmation.setDomain("sports");
confirmation.setService("api");
confirmation.setProvider("sys.auth.sb-provider");
Map<String, String> attributes = new HashMap<>();
String subjectDn = "CN=athenz-examples1.abc.com,OU=Testing Domain,O=Athenz,L=LA,ST=CA,C=US";
attributes.put(InstanceProvider.ZTS_INSTANCE_SAN_DNS, "api.sports.unknown.cloud,inst1.instanceid.athenz.zts.athenz.cloud");
attributes.put(InstanceProvider.ZTS_INSTANCE_HOSTNAME, "athenz-examples1.abc.com");
attributes.put(InstanceProvider.ZTS_INSTANCE_SAN_IP, "10.1.1.2");
attributes.put(InstanceProvider.ZTS_INSTANCE_CERT_ISSUER_DN, "CN=issuer1");
attributes.put(InstanceProvider.ZTS_INSTANCE_CERT_SUBJECT_DN, subjectDn);
confirmation.setAttributes(attributes);
try {
provider.confirmInstance(confirmation);
fail();
} catch (ResourceException e) {
assertTrue(e.getMessage().contains("Unable to validate certificate request DNS"));
}
provider.close();
System.clearProperty(SecureBootProvider.ZTS_PROP_SB_ATTR_VALIDATOR_FACTORY_CLASS);
}
use of com.yahoo.athenz.common.server.dns.HostnameResolver in project athenz by yahoo.
the class SecureBootProviderTest method testConfirmInstance.
@Test
public void testConfirmInstance() {
System.setProperty(SecureBootProvider.ZTS_PROP_SB_ATTR_VALIDATOR_FACTORY_CLASS, "com.yahoo.athenz.instance.provider.impl.MockAttrValidatorFactory");
HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
Mockito.when(hostnameResolver.getAllByName("athenz-examples1.abc.com")).thenReturn(new HashSet<>(Arrays.asList("10.1.1.2", "2001:db8:a0b:12f0:0:0:0:1")));
SecureBootProvider provider = new SecureBootProvider();
provider.initialize("sys.auth.sb-provider", "com.yahoo.athenz.instance.provider.impl.SecureBootProvider", null, null);
provider.setHostnameResolver(hostnameResolver);
InstanceConfirmation confirmation = new InstanceConfirmation();
confirmation.setAttestationData("sample attestation data");
confirmation.setDomain("sports");
confirmation.setService("api");
confirmation.setProvider("sys.auth.sb-provider");
Map<String, String> attributes = new HashMap<>();
String subjectDn = "CN=athenz-examples1.abc.com,OU=Testing Domain,O=Athenz,L=LA,ST=CA,C=US";
attributes.put(InstanceProvider.ZTS_INSTANCE_SAN_DNS, "api.sports.zts.athenz.cloud,inst1.instanceid.athenz.zts.athenz.cloud");
attributes.put(InstanceProvider.ZTS_INSTANCE_HOSTNAME, "athenz-examples1.abc.com");
attributes.put(InstanceProvider.ZTS_INSTANCE_CERT_ISSUER_DN, "CN=issuer1");
attributes.put(InstanceProvider.ZTS_INSTANCE_CERT_SUBJECT_DN, subjectDn);
confirmation.setAttributes(attributes);
assertNotNull(provider.confirmInstance(confirmation));
provider.close();
System.clearProperty(SecureBootProvider.ZTS_PROP_SB_ATTR_VALIDATOR_FACTORY_CLASS);
}
use of com.yahoo.athenz.common.server.dns.HostnameResolver in project athenz by yahoo.
the class SecureBootProviderTest method testConfirmInstanceInvalidSanIp.
@Test
public void testConfirmInstanceInvalidSanIp() {
System.setProperty(SecureBootProvider.ZTS_PROP_SB_ATTR_VALIDATOR_FACTORY_CLASS, "com.yahoo.athenz.instance.provider.impl.MockAttrValidatorFactory");
HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
Mockito.when(hostnameResolver.getAllByName("athenz-examples1.abc.com")).thenReturn(new HashSet<>(Arrays.asList("10.1.1.2", "2001:db8:a0b:12f0:0:0:0:1")));
SecureBootProvider provider = new SecureBootProvider();
provider.initialize("sys.auth.sb-provider", "com.yahoo.athenz.instance.provider.impl.SecureBootProvider", null, null);
provider.setHostnameResolver(hostnameResolver);
InstanceConfirmation confirmation = new InstanceConfirmation();
confirmation.setAttestationData("sample attestation data");
confirmation.setDomain("sports");
confirmation.setService("api");
confirmation.setProvider("sys.auth.sb-provider");
Map<String, String> attributes = new HashMap<>();
String subjectDn = "CN=athenz-examples1.abc.com,OU=Testing Domain,O=Athenz,L=LA,ST=CA,C=US";
attributes.put(InstanceProvider.ZTS_INSTANCE_SAN_DNS, "api.sports.zts.athenz.cloud,inst1.instanceid.athenz.zts.athenz.cloud");
attributes.put(InstanceProvider.ZTS_INSTANCE_HOSTNAME, "athenz-examples1.abc.com");
attributes.put(InstanceProvider.ZTS_INSTANCE_SAN_IP, "10.1.1.3");
attributes.put(InstanceProvider.ZTS_INSTANCE_CERT_ISSUER_DN, "CN=issuer1");
attributes.put(InstanceProvider.ZTS_INSTANCE_CERT_SUBJECT_DN, subjectDn);
confirmation.setAttributes(attributes);
try {
provider.confirmInstance(confirmation);
fail();
} catch (ResourceException e) {
assertTrue(e.getMessage().contains("Unable to validate request IP address"));
}
provider.close();
System.clearProperty(SecureBootProvider.ZTS_PROP_SB_ATTR_VALIDATOR_FACTORY_CLASS);
}
Aggregations