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