Search in sources :

Example 1 with SshGenerationParameters

use of org.cloudfoundry.credhub.request.SshGenerationParameters in project credhub by cloudfoundry-incubator.

the class SshCredentialRegeneratable method createGenerateRequest.

@Override
public BaseCredentialGenerateRequest createGenerateRequest(CredentialVersion credentialVersion, List<EventAuditRecordParameters> auditRecordParameters) {
    SshCredentialVersion sshCredential = (SshCredentialVersion) credentialVersion;
    SshGenerateRequest generateRequest = new SshGenerateRequest();
    generateRequest.setName(sshCredential.getName());
    generateRequest.setType(sshCredential.getCredentialType());
    SshGenerationParameters generationParameters = new SshGenerationParameters();
    generationParameters.setSshComment(sshCredential.getComment());
    generateRequest.setGenerationParameters(generationParameters);
    generateRequest.setOverwrite(true);
    return generateRequest;
}
Also used : SshGenerateRequest(org.cloudfoundry.credhub.request.SshGenerateRequest) SshCredentialVersion(org.cloudfoundry.credhub.domain.SshCredentialVersion) SshGenerationParameters(org.cloudfoundry.credhub.request.SshGenerationParameters)

Example 2 with SshGenerationParameters

use of org.cloudfoundry.credhub.request.SshGenerationParameters in project credhub by cloudfoundry-incubator.

the class SshCredentialVersionTest method matchesGenerationParameters_returnsFalseWhenParametersDontMatch.

@Test
public void matchesGenerationParameters_returnsFalseWhenParametersDontMatch() {
    SshGenerationParameters generationParameters = new SshGenerationParameters();
    generationParameters.setKeyLength(4096);
    assertThat(subject.matchesGenerationParameters(generationParameters), equalTo(false));
}
Also used : SshGenerationParameters(org.cloudfoundry.credhub.request.SshGenerationParameters) Test(org.junit.Test)

Example 3 with SshGenerationParameters

use of org.cloudfoundry.credhub.request.SshGenerationParameters in project credhub by cloudfoundry-incubator.

the class SshGeneratorTest method generateCredential_shouldUseTheProvidedKeyLength.

@Test
public void generateCredential_shouldUseTheProvidedKeyLength() throws Exception {
    SshGenerationParameters sshGenerationParameters = new SshGenerationParameters();
    sshGenerationParameters.setKeyLength(4096);
    subject.generateCredential(sshGenerationParameters);
    verify(keyPairGeneratorMock).generateKeyPair(4096);
}
Also used : SshGenerationParameters(org.cloudfoundry.credhub.request.SshGenerationParameters) Test(org.junit.Test)

Example 4 with SshGenerationParameters

use of org.cloudfoundry.credhub.request.SshGenerationParameters in project credhub by cloudfoundry-incubator.

the class SshGenerator method generateCredential.

@Override
public SshCredentialValue generateCredential(GenerationParameters p) {
    SshGenerationParameters params = (SshGenerationParameters) p;
    try {
        final KeyPair keyPair = keyGenerator.generateKeyPair(params.getKeyLength());
        String sshComment = params.getSshComment();
        String sshCommentMessage = StringUtils.isEmpty(sshComment) ? "" : " " + sshComment;
        String publicKey = CertificateFormatter.derOf((RSAPublicKey) keyPair.getPublic()) + sshCommentMessage;
        String privateKey = CertificateFormatter.pemOf(keyPair.getPrivate());
        return new SshCredentialValue(publicKey, privateKey, null);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : KeyPair(java.security.KeyPair) RSAPublicKey(java.security.interfaces.RSAPublicKey) SshGenerationParameters(org.cloudfoundry.credhub.request.SshGenerationParameters) SshCredentialValue(org.cloudfoundry.credhub.credential.SshCredentialValue)

Example 5 with SshGenerationParameters

use of org.cloudfoundry.credhub.request.SshGenerationParameters in project credhub by cloudfoundry-incubator.

the class SshGeneratorTest method generateCredential_shouldUseTheProvidedSSHComment.

@Test
public void generateCredential_shouldUseTheProvidedSSHComment() throws Exception {
    SshGenerationParameters sshGenerationParameters = new SshGenerationParameters();
    sshGenerationParameters.setSshComment("this is an ssh comment");
    final SshCredentialValue ssh = subject.generateCredential(sshGenerationParameters);
    String expectedPublicKey = CertificateFormatter.derOf((RSAPublicKey) keyPair.getPublic()) + " this is an ssh comment";
    assertThat(ssh.getPublicKey(), equalTo(expectedPublicKey));
}
Also used : RSAPublicKey(java.security.interfaces.RSAPublicKey) SshGenerationParameters(org.cloudfoundry.credhub.request.SshGenerationParameters) SshCredentialValue(org.cloudfoundry.credhub.credential.SshCredentialValue) Test(org.junit.Test)

Aggregations

SshGenerationParameters (org.cloudfoundry.credhub.request.SshGenerationParameters)7 Test (org.junit.Test)5 SshCredentialValue (org.cloudfoundry.credhub.credential.SshCredentialValue)3 RSAPublicKey (java.security.interfaces.RSAPublicKey)2 KeyPair (java.security.KeyPair)1 SshCredentialVersion (org.cloudfoundry.credhub.domain.SshCredentialVersion)1 SshGenerateRequest (org.cloudfoundry.credhub.request.SshGenerateRequest)1