Search in sources :

Example 6 with SshKeyPair

use of com.sshtools.common.ssh.components.SshKeyPair in project vcert-java by Venafi.

the class TppConnectorATForSSH method requestAndRetrieveSshCertificateWithKeyPairProvided.

@Test
@DisplayName("TPP - Testing the requestSshCertificate() and retrieveSshCertificate() methods when KeyPair is provided")
public void requestAndRetrieveSshCertificateWithKeyPairProvided() throws VCertException, Exception {
    String keyId = TppTestUtils.getRandSshKeyId();
    // getting an SSH Key Pair with a key size of 3072 bits
    SshKeyPair pair = SshKeyPairGenerator.generateKeyPair(SshKeyPairGenerator.SSH2_RSA, 3072);
    // extracting the Public Key and adding the KeyId as comment, at the end of the Public Key
    // because TPP returns the Public Key on that way
    String publicKeyData = SshKeyUtils.getFormattedKey(pair.getPublicKey(), keyId);
    // building an SshCertificateRequest
    SshCertificateRequest req = new SshCertificateRequest().keyId(keyId).validityPeriod("4h").template(System.getenv("TPP_SSH_CA")).publicKeyData(publicKeyData).sourceAddresses(new String[] { "test.com" });
    // requesting the SSH Certificate
    String pickUpID = classUnderTest.requestSshCertificate(req);
    // setting the pickUp ID
    req.pickupID(pickUpID);
    // retrieving the Cert and details
    SshCertRetrieveDetails sshCertRetrieveDetails = classUnderTest.retrieveSshCertificate(req);
    assertEquals(publicKeyData, sshCertRetrieveDetails.publicKeyData());
    assertNotNull(sshCertRetrieveDetails.certificateData());
    Long validityPeriodFromCert = Long.parseLong(sshCertRetrieveDetails.certificateDetails().validTo()) - Long.parseLong(sshCertRetrieveDetails.certificateDetails().validFrom());
    // 4h
    assertEquals(14400L, validityPeriodFromCert.longValue());
}
Also used : SshKeyPair(com.sshtools.common.ssh.components.SshKeyPair) SshCertificateRequest(com.venafi.vcert.sdk.certificate.SshCertificateRequest) SshCertRetrieveDetails(com.venafi.vcert.sdk.certificate.SshCertRetrieveDetails) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

SshKeyPair (com.sshtools.common.ssh.components.SshKeyPair)6 SshCertRetrieveDetails (com.venafi.vcert.sdk.certificate.SshCertRetrieveDetails)5 SshCertificateRequest (com.venafi.vcert.sdk.certificate.SshCertificateRequest)5 DisplayName (org.junit.jupiter.api.DisplayName)4 Test (org.junit.jupiter.api.Test)4 SshException (com.jn.agileway.ssh.client.SshException)1 ToSynergyHostKeyVerifierAdapter (com.jn.agileway.ssh.client.impl.synergy.verifier.ToSynergyHostKeyVerifierAdapter)1 SshClient (com.sshtools.client.SshClient)1 SshClientContext (com.sshtools.client.SshClientContext)1 Config (com.venafi.vcert.sdk.Config)1 VCertTknClient (com.venafi.vcert.sdk.VCertTknClient)1 Authentication (com.venafi.vcert.sdk.endpoint.Authentication)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1