Search in sources :

Example 6 with KeyPair

use of com.walmartlabs.concord.common.secret.KeyPair in project concord by walmartlabs.

the class SecretManager method createKeyPair.

/**
 * Stores a new SSH key pair using the provided public and private keys.
 */
public DecryptedKeyPair createKeyPair(UUID orgId, UUID projectId, String name, String storePassword, InputStream publicKey, InputStream privateKey, SecretVisibility visibility, String secretStoreType) throws IOException {
    orgManager.assertAccess(orgId, true);
    KeyPair k = buildKeyPair(publicKey, privateKey);
    UUID id = create(name, orgId, projectId, k, storePassword, visibility, secretStoreType, INSERT);
    return new DecryptedKeyPair(id, k.getPublicKey());
}
Also used : KeyPair(com.walmartlabs.concord.common.secret.KeyPair)

Example 7 with KeyPair

use of com.walmartlabs.concord.common.secret.KeyPair in project concord by walmartlabs.

the class SecretIT method testSecretPasswordUpdate.

@Test
public void testSecretPasswordUpdate() throws Exception {
    String orgName = "org_" + randomString();
    OrganizationsApi orgApi = new OrganizationsApi(getApiClient());
    orgApi.createOrUpdate(new OrganizationEntry().setName(orgName));
    // ---
    String initPassword = "q1q1Q1Q1";
    String secretName = "secret_" + randomString();
    generateKeyPair(orgName, null, secretName, false, initPassword);
    // ---
    String newPassword = "q2q2Q2Q2";
    UpdateSecretRequest request = UpdateSecretRequest.builder().currentPassword(initPassword).newPassword(newPassword).build();
    // ---
    SecretClient secretsApi = new SecretClient(getApiClient());
    secretsApi.updateSecret(orgName, secretName, request);
    KeyPair kp = secretsApi.getData(orgName, secretName, newPassword, SecretEntry.TypeEnum.KEY_PAIR);
    assertNotNull(kp);
}
Also used : KeyPair(com.walmartlabs.concord.common.secret.KeyPair) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 8 with KeyPair

use of com.walmartlabs.concord.common.secret.KeyPair in project concord by walmartlabs.

the class SecretServiceImpl method exportKeyAsFile.

@Override
public Map<String, String> exportKeyAsFile(Context ctx, String instanceId, String workDir, String orgName, String name, String password) throws Exception {
    KeyPair kp = get(ctx, orgName, name, password, SecretEntry.TypeEnum.KEY_PAIR);
    Path baseDir = Paths.get(workDir);
    Path tmpDir = assertTempDir(baseDir);
    Path privateKey = Files.createTempFile(tmpDir, "private", ".key");
    Files.write(privateKey, kp.getPrivateKey());
    Path publicKey = Files.createTempFile(tmpDir, "public", ".key");
    Files.write(publicKey, kp.getPublicKey());
    Map<String, String> m = new HashMap<>();
    m.put("private", baseDir.relativize(privateKey).toString());
    m.put("public", baseDir.relativize(publicKey).toString());
    return m;
}
Also used : Path(java.nio.file.Path) KeyPair(com.walmartlabs.concord.common.secret.KeyPair) HashMap(java.util.HashMap)

Aggregations

KeyPair (com.walmartlabs.concord.common.secret.KeyPair)8 Path (java.nio.file.Path)4 BinaryDataSecret (com.walmartlabs.concord.common.secret.BinaryDataSecret)2 UsernamePassword (com.walmartlabs.concord.common.secret.UsernamePassword)1 Secret (com.walmartlabs.concord.sdk.Secret)1 ProcessException (com.walmartlabs.concord.server.process.ProcessException)1 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.jupiter.api.Test)1