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());
}
Aggregations