Search in sources :

Example 1 with SecretCertificateCredentials

use of com.microsoft.jenkins.keyvault.SecretCertificateCredentials in project azure-credentials-plugin by jenkinsci.

the class ITSecretCertificateCredentials method getKeyStoreNotFound.

@Test
public void getKeyStoreNotFound() {
    final String secretIdentifier = vaultUri + "/secrets/not-found/869660651aa3436994bd7290704c9394";
    // Verify configuration
    final SecretCertificateCredentials.DescriptorImpl descriptor = new SecretCertificateCredentials.DescriptorImpl();
    final FormValidation result = descriptor.doVerifyConfiguration(jenkinsAzureCredentialsId, secretIdentifier, Secret.fromString(""));
    Assert.assertEquals(FormValidation.Kind.ERROR, result.kind);
    // Get key store
    final SecretCertificateCredentials credentials = new SecretCertificateCredentials(CredentialsScope.SYSTEM, "", "", jenkinsAzureCredentialsId, secretIdentifier, Secret.fromString(""));
    try {
        final KeyStore keyStore = credentials.getKeyStore();
        Assert.fail("Should throw exception but not");
    } catch (Exception e) {
    // Expect exception
    }
}
Also used : SecretCertificateCredentials(com.microsoft.jenkins.keyvault.SecretCertificateCredentials) FormValidation(hudson.util.FormValidation) KeyStore(java.security.KeyStore) IOException(java.io.IOException) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) Test(org.junit.Test)

Example 2 with SecretCertificateCredentials

use of com.microsoft.jenkins.keyvault.SecretCertificateCredentials in project azure-credentials-plugin by jenkinsci.

the class ITSecretCertificateCredentials method getKeyStore.

@Test
public void getKeyStore() throws IOException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException {
    final String cert = IOUtils.toString(getClass().getResourceAsStream("../cert.pfx.b64"), StandardCharsets.UTF_8);
    final KeyVaultSecret secretBundle = createSecret("secret-cert", cert);
    final String secretIdentifier = secretBundle.getId();
    final Secret password = Secret.fromString("123456");
    // Verify configuration
    final SecretCertificateCredentials.DescriptorImpl descriptor = new SecretCertificateCredentials.DescriptorImpl();
    final FormValidation result = descriptor.doVerifyConfiguration(jenkinsAzureCredentialsId, secretIdentifier, password);
    Assert.assertEquals(FormValidation.Kind.OK, result.kind);
    // Get key store
    final SecretCertificateCredentials credentials = new SecretCertificateCredentials(CredentialsScope.SYSTEM, "", "", jenkinsAzureCredentialsId, secretIdentifier, password);
    final KeyStore keyStore = credentials.getKeyStore();
    Assert.assertTrue(keyStore.containsAlias("msft"));
    Assert.assertEquals(1, keyStore.size());
    final Key key = keyStore.getKey("msft", password.getPlainText().toCharArray());
    Assert.assertEquals("RSA", key.getAlgorithm());
}
Also used : KeyVaultSecret(com.azure.security.keyvault.secrets.models.KeyVaultSecret) Secret(hudson.util.Secret) KeyVaultSecret(com.azure.security.keyvault.secrets.models.KeyVaultSecret) SecretCertificateCredentials(com.microsoft.jenkins.keyvault.SecretCertificateCredentials) FormValidation(hudson.util.FormValidation) KeyStore(java.security.KeyStore) Key(java.security.Key) Test(org.junit.Test)

Aggregations

SecretCertificateCredentials (com.microsoft.jenkins.keyvault.SecretCertificateCredentials)2 FormValidation (hudson.util.FormValidation)2 KeyStore (java.security.KeyStore)2 Test (org.junit.Test)2 KeyVaultSecret (com.azure.security.keyvault.secrets.models.KeyVaultSecret)1 Secret (hudson.util.Secret)1 IOException (java.io.IOException)1 Key (java.security.Key)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 UnrecoverableKeyException (java.security.UnrecoverableKeyException)1