Search in sources :

Example 1 with SshCredentialValue

use of org.cloudfoundry.credhub.credential.SshCredentialValue in project credhub by cloudfoundry-incubator.

the class CredentialsControllerGenerateTest method beforeEach.

@Before
public void beforeEach() {
    Consumer<Long> fakeTimeSetter = mockOutCurrentTimeProvider(mockCurrentTimeProvider);
    userContext = mock(UserContext.class);
    fakeTimeSetter.accept(FROZEN_TIME.toEpochMilli());
    mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
    when(credentialGenerator.generateCredential(any(StringGenerationParameters.class))).thenReturn(new StringCredentialValue(FAKE_PASSWORD_NAME));
    when(sshGenerator.generateCredential(any(SshGenerationParameters.class))).thenReturn(new SshCredentialValue(PUBLIC_KEY, PRIVATE_KEY, null));
    when(rsaGenerator.generateCredential(any(RsaGenerationParameters.class))).thenReturn(new RsaCredentialValue(PUBLIC_KEY, PRIVATE_KEY));
    when(certificateGenerator.generateCredential(any(CertificateGenerationParameters.class))).thenReturn(new CertificateCredentialValue("ca_cert", CERT, PRIVATE_KEY, null));
}
Also used : RsaGenerationParameters(org.cloudfoundry.credhub.request.RsaGenerationParameters) CertificateGenerationParameters(org.cloudfoundry.credhub.domain.CertificateGenerationParameters) UserContext(org.cloudfoundry.credhub.auth.UserContext) CertificateCredentialValue(org.cloudfoundry.credhub.credential.CertificateCredentialValue) StringCredentialValue(org.cloudfoundry.credhub.credential.StringCredentialValue) RsaCredentialValue(org.cloudfoundry.credhub.credential.RsaCredentialValue) SshGenerationParameters(org.cloudfoundry.credhub.request.SshGenerationParameters) SshCredentialValue(org.cloudfoundry.credhub.credential.SshCredentialValue) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) Before(org.junit.Before)

Example 2 with SshCredentialValue

use of org.cloudfoundry.credhub.credential.SshCredentialValue in project credhub by cloudfoundry-incubator.

the class CredentialsControllerTypeSpecificGenerateTest method setup.

@Before
public void setup() throws Exception {
    String fakeSalt = cryptSaltFactory.generateSalt(FAKE_PASSWORD);
    Consumer<Long> fakeTimeSetter = mockOutCurrentTimeProvider(mockCurrentTimeProvider);
    fakeTimeSetter.accept(FROZEN_TIME.toEpochMilli());
    mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
    when(passwordGenerator.generateCredential(any(GenerationParameters.class))).thenReturn(new StringCredentialValue(FAKE_PASSWORD));
    when(certificateGenerator.generateCredential(any(GenerationParameters.class))).thenReturn(new CertificateCredentialValue(CA, CERTIFICATE, PRIVATE_KEY, null));
    when(sshGenerator.generateCredential(any(GenerationParameters.class))).thenReturn(new SshCredentialValue(PUBLIC_KEY, PRIVATE_KEY, null));
    when(rsaGenerator.generateCredential(any(GenerationParameters.class))).thenReturn(new RsaCredentialValue(PUBLIC_KEY, PRIVATE_KEY));
    when(userGenerator.generateCredential(any(GenerationParameters.class))).thenReturn(new UserCredentialValue(USERNAME, FAKE_PASSWORD, fakeSalt));
    auditingHelper = new AuditingHelper(requestAuditRecordRepository, eventAuditRecordRepository);
}
Also used : CertificateCredentialValue(org.cloudfoundry.credhub.credential.CertificateCredentialValue) StringCredentialValue(org.cloudfoundry.credhub.credential.StringCredentialValue) RsaCredentialValue(org.cloudfoundry.credhub.credential.RsaCredentialValue) GenerationParameters(org.cloudfoundry.credhub.request.GenerationParameters) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) Matchers.anyString(org.mockito.Matchers.anyString) AuditingHelper(org.cloudfoundry.credhub.helper.AuditingHelper) UserCredentialValue(org.cloudfoundry.credhub.credential.UserCredentialValue) SshCredentialValue(org.cloudfoundry.credhub.credential.SshCredentialValue) Before(org.junit.Before)

Example 3 with SshCredentialValue

use of org.cloudfoundry.credhub.credential.SshCredentialValue in project credhub by cloudfoundry-incubator.

the class CredentialFactoryTest method makeCredentialFromRequest_givenSshType_andNoExisting_returnsSshCredential.

@Test
public void makeCredentialFromRequest_givenSshType_andNoExisting_returnsSshCredential() throws Exception {
    SshCredentialValue sshValue = new SshCredentialValue("public-key", PLAINTEXT_VALUE, null);
    SshCredentialVersion credential = (SshCredentialVersion) subject.makeNewCredentialVersion(CredentialType.valueOf("ssh"), CREDENTIAL_NAME, sshValue, null, null);
    MatcherAssert.assertThat(credential.getCredential().getName(), equalTo(CREDENTIAL_NAME));
    assertThat(credential.getPublicKey(), equalTo("public-key"));
    assertThat(credential.getPrivateKey(), equalTo(PLAINTEXT_VALUE));
}
Also used : SshCredentialValue(org.cloudfoundry.credhub.credential.SshCredentialValue) Test(org.junit.Test)

Example 4 with SshCredentialValue

use of org.cloudfoundry.credhub.credential.SshCredentialValue 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 SshCredentialValue

use of org.cloudfoundry.credhub.credential.SshCredentialValue 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

SshCredentialValue (org.cloudfoundry.credhub.credential.SshCredentialValue)6 SshGenerationParameters (org.cloudfoundry.credhub.request.SshGenerationParameters)4 Test (org.junit.Test)3 RSAPublicKey (java.security.interfaces.RSAPublicKey)2 CertificateCredentialValue (org.cloudfoundry.credhub.credential.CertificateCredentialValue)2 RsaCredentialValue (org.cloudfoundry.credhub.credential.RsaCredentialValue)2 StringCredentialValue (org.cloudfoundry.credhub.credential.StringCredentialValue)2 StringGenerationParameters (org.cloudfoundry.credhub.request.StringGenerationParameters)2 Before (org.junit.Before)2 KeyPair (java.security.KeyPair)1 UserContext (org.cloudfoundry.credhub.auth.UserContext)1 UserCredentialValue (org.cloudfoundry.credhub.credential.UserCredentialValue)1 CertificateGenerationParameters (org.cloudfoundry.credhub.domain.CertificateGenerationParameters)1 AuditingHelper (org.cloudfoundry.credhub.helper.AuditingHelper)1 GenerationParameters (org.cloudfoundry.credhub.request.GenerationParameters)1 RsaGenerationParameters (org.cloudfoundry.credhub.request.RsaGenerationParameters)1 Matchers.anyString (org.mockito.Matchers.anyString)1