Search in sources :

Example 36 with SSHCertRecord

use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.

the class InstanceCertManagerTest method testUpdateSSHCertRecordNoCertStore.

@Test
public void testUpdateSSHCertRecordNoCertStore() {
    InstanceCertManager instance = new InstanceCertManager(null, null, null, true, null);
    instance.setSSHSigner(null);
    instance.setSSHStore(null);
    SSHCertRecord sshCertRecord = new SSHCertRecord();
    assertFalse(instance.updateSSHCertRecord(sshCertRecord, true));
    instance.shutdown();
}
Also used : SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord) Test(org.testng.annotations.Test)

Example 37 with SSHCertRecord

use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.

the class InstanceCertManagerTest method testValidPrincipalsInvalidHostname.

@Test
public void testValidPrincipalsInvalidHostname() throws IOException {
    Path path = Paths.get("src/test/resources/sshhost_valid_sample.csr");
    String sshCsr = new String(Files.readAllBytes(path));
    SSHCertRecord sshCertRecord = new SSHCertRecord();
    sshCertRecord.setService("athenz.examples.httpd");
    // setup the hostname resolver for our request
    String hostname = "host1.athenz.cloud";
    HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
    when(hostnameResolver.isValidHostname(hostname)).thenReturn(false);
    InstanceCertManager instanceManager = new InstanceCertManager(null, null, hostnameResolver, true, null);
    ObjectMapper objectMapper = new ObjectMapper();
    boolean result = instanceManager.validPrincipals("host1.athenz.cloud", sshCertRecord, objectMapper.readValue(sshCsr, SshHostCsr.class));
    assertFalse(result);
    instanceManager.shutdown();
}
Also used : Path(java.nio.file.Path) HostnameResolver(com.yahoo.athenz.common.server.dns.HostnameResolver) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord) Test(org.testng.annotations.Test)

Example 38 with SSHCertRecord

use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.

the class InstanceCertManagerTest method testGenerateSshIdentityCertRequestValidPrincipals.

@Test
public void testGenerateSshIdentityCertRequestValidPrincipals() {
    SSHSigner sshSigner = Mockito.mock(com.yahoo.athenz.common.server.ssh.SSHSigner.class);
    SSHCertRequest sshRequest = new SSHCertRequest();
    sshRequest.setCertRequestData(new SSHCertRequestData().setPrincipals(Arrays.asList("host1.athenz.cloud", "cname.athenz.info", "vip.athenz.info", "10.1.2.3")).setPublicKey("sample public key"));
    sshRequest.setCertRequestMeta(new SSHCertRequestMeta().setKeyIdPrincipals(Arrays.asList("service.domain.athenz.cloud", "host1.athenz.cloud", "cname.athenz.info", "vip.athenz.info", "10.1.2.3")).setCertType("host").setTransId("123456").setOrigin("10.1.2.3"));
    SSHCertificates certs = new SSHCertificates();
    SSHCertificate cert = new SSHCertificate();
    cert.setCertificate("ssh-cert");
    SSHCertRecord sshCertRecord = new SSHCertRecord();
    sshCertRecord.setPrincipals("127.0.0.1");
    sshCertRecord.setService("athenz.service");
    InstanceIdentity identity = new InstanceIdentity().setName("athenz.service");
    final SSHCertificates sshCertificates = certs.setCertificates(Collections.singletonList(cert));
    when(sshSigner.generateCertificate(null, sshRequest, sshCertRecord, "host")).thenReturn(sshCertificates);
    when(sshSigner.getSignerCertificate(ZTSConsts.ZTS_SSH_HOST)).thenReturn("ssh-host");
    // setup the hostname resolver for our request
    String hostname = "host1.athenz.cloud";
    List<String> cnames = new ArrayList<>();
    cnames.add("cname.athenz.info");
    cnames.add("vip.athenz.info");
    HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
    when(hostnameResolver.isValidHostCnameList(sshCertRecord.getService(), hostname, cnames, CertType.SSH_HOST)).thenReturn(true);
    when(hostnameResolver.isValidHostname(hostname)).thenReturn(true);
    InstanceCertManager instanceManager = new InstanceCertManager(null, null, hostnameResolver, true, null);
    instanceManager.setSSHSigner(sshSigner);
    assertTrue(instanceManager.generateSSHIdentity(null, identity, hostname, null, sshRequest, sshCertRecord, "host"));
    assertEquals(identity.getSshCertificate(), "ssh-cert");
    assertEquals(identity.getSshCertificateSigner(), "ssh-host");
    instanceManager.shutdown();
}
Also used : HostnameResolver(com.yahoo.athenz.common.server.dns.HostnameResolver) SSHSigner(com.yahoo.athenz.common.server.ssh.SSHSigner) SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord) Test(org.testng.annotations.Test)

Example 39 with SSHCertRecord

use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.

the class InstanceCertManagerTest method testGenerateSshIdentityInvalidSsh.

@Test
public void testGenerateSshIdentityInvalidSsh() {
    InstanceIdentity identity = new InstanceIdentity().setName("athenz.service");
    SSHSigner sshSigner = Mockito.mock(com.yahoo.athenz.common.server.ssh.SSHSigner.class);
    InstanceCertManager instanceManager = new InstanceCertManager(null, null, null, true, null);
    instanceManager.setSSHSigner(sshSigner);
    boolean result = instanceManager.generateSSHIdentity(null, identity, "host.athenz.com", "{\"csr\":\"csr\"}", null, new SSHCertRecord(), ZTSConsts.ZTS_SSH_HOST);
    assertFalse(result);
}
Also used : SSHSigner(com.yahoo.athenz.common.server.ssh.SSHSigner) SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord) Test(org.testng.annotations.Test)

Example 40 with SSHCertRecord

use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.

the class InstanceCertManagerTest method testGenerateSshIdentityCertRequestNoHostname.

@Test
public void testGenerateSshIdentityCertRequestNoHostname() {
    SSHSigner sshSigner = Mockito.mock(com.yahoo.athenz.common.server.ssh.SSHSigner.class);
    SSHCertRequest sshRequest = new SSHCertRequest();
    sshRequest.setCertRequestData(new SSHCertRequestData().setPrincipals(Arrays.asList("host1.athenz.cloud", "cname.athenz.info", "vip.athenz.info", "10.1.2.3")).setPublicKey("sample public key"));
    sshRequest.setCertRequestMeta(new SSHCertRequestMeta().setKeyIdPrincipals(Arrays.asList("service.domain.athenz.cloud", "host1.athenz.cloud", "cname.athenz.info", "vip.athenz.info", "10.1.2.3")).setCertType("host").setTransId("123456").setOrigin("10.1.2.3"));
    SSHCertificates certs = new SSHCertificates();
    SSHCertificate cert = new SSHCertificate();
    cert.setCertificate("ssh-cert");
    SSHCertRecord sshCertRecord = new SSHCertRecord();
    sshCertRecord.setPrincipals("127.0.0.1");
    sshCertRecord.setService("athenz.service");
    InstanceIdentity identity = new InstanceIdentity().setName("athenz.service");
    final SSHCertificates sshCertificates = certs.setCertificates(Collections.singletonList(cert));
    when(sshSigner.generateCertificate(null, sshRequest, sshCertRecord, "host")).thenReturn(sshCertificates);
    when(sshSigner.getSignerCertificate(ZTSConsts.ZTS_SSH_HOST)).thenReturn("ssh-host");
    HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
    InstanceCertManager instanceManager = new InstanceCertManager(null, null, hostnameResolver, true, null);
    instanceManager.setSSHSigner(sshSigner);
    assertTrue(instanceManager.generateSSHIdentity(null, identity, null, null, sshRequest, sshCertRecord, "host"));
    assertEquals(identity.getSshCertificate(), "ssh-cert");
    assertEquals(identity.getSshCertificateSigner(), "ssh-host");
    instanceManager.shutdown();
}
Also used : HostnameResolver(com.yahoo.athenz.common.server.dns.HostnameResolver) SSHSigner(com.yahoo.athenz.common.server.ssh.SSHSigner) SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord) Test(org.testng.annotations.Test)

Aggregations

SSHCertRecord (com.yahoo.athenz.common.server.ssh.SSHCertRecord)57 Test (org.testng.annotations.Test)51 SSHSigner (com.yahoo.athenz.common.server.ssh.SSHSigner)14 HostnameResolver (com.yahoo.athenz.common.server.dns.HostnameResolver)12 Path (java.nio.file.Path)5 File (java.io.File)4 AmazonDynamoDBException (com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 SSHRecordStore (com.yahoo.athenz.common.server.ssh.SSHRecordStore)3 SSHRecordStoreConnection (com.yahoo.athenz.common.server.ssh.SSHRecordStoreConnection)3 IOException (java.io.IOException)3 UpdateItemSpec (com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec)2 Principal (com.yahoo.athenz.auth.Principal)2 PrincipalToken (com.yahoo.athenz.auth.token.PrincipalToken)2 CryptoException (com.yahoo.athenz.auth.util.CryptoException)2 Priority (com.yahoo.athenz.common.server.cert.Priority)2 StatusCheckException (com.yahoo.athenz.common.server.status.StatusCheckException)2 InstanceConfirmation (com.yahoo.athenz.instance.provider.InstanceConfirmation)2 InstanceProvider (com.yahoo.athenz.instance.provider.InstanceProvider)2 ResourceException (com.yahoo.athenz.zts.ResourceException)2