use of com.microsoft.azure.keyvault.models.X509CertificateProperties in project azure-sdk-for-java by Azure.
the class CertificateOperationsTest method createCsr.
/**
* Create a certificate signing request with key in Key Vault.
* @throws ExecutionException
* @throws InterruptedException
* @throws IOException
* @throws IllegalArgumentException
* @throws KeyVaultErrorException
*
* @throws Exception
*/
@Test
public void createCsr() throws InterruptedException, ExecutionException, KeyVaultErrorException, IllegalArgumentException, IOException {
SecretProperties secretProperties = new SecretProperties();
secretProperties.withContentType(MIME_PKCS12);
X509CertificateProperties x509Properties = new X509CertificateProperties();
String subjectName = "CN=ManualEnrollmentJava";
x509Properties.withSubject(subjectName);
x509Properties.withValidityInMonths(12);
// Set issuer to "Unknown"
IssuerParameters issuerParameters = new IssuerParameters();
issuerParameters.withName(ISSUER_UNKNOWN);
CertificatePolicy certificatePolicy = new CertificatePolicy().withSecretProperties(secretProperties).withIssuerParameters(issuerParameters).withX509CertificateProperties(x509Properties);
String vaultUri = getVaultUri();
String certificateName = "createManualEnrollmentJava";
CertificateOperation certificateOperation = keyVaultClient.createCertificate(new CreateCertificateRequest.Builder(vaultUri, certificateName).withPolicy(certificatePolicy).build());
Assert.assertNotNull(certificateOperation);
Assert.assertTrue(certificateOperation.status().equalsIgnoreCase(STATUS_IN_PROGRESS));
Assert.assertNotNull(certificateOperation.csr());
String csr = keyVaultClient.getPendingCertificateSigningRequest(vaultUri, certificateName);
Assert.assertNotNull(csr);
CertificateBundle deletedCertificateBundle = keyVaultClient.deleteCertificate(getVaultUri(), certificateName);
Assert.assertNotNull(deletedCertificateBundle);
try {
keyVaultClient.getCertificate(deletedCertificateBundle.certificateIdentifier().baseIdentifier());
} catch (KeyVaultErrorException e) {
Assert.assertNotNull(e.body().error());
Assert.assertEquals("CertificateNotFound", e.body().error().code());
}
}
use of com.microsoft.azure.keyvault.models.X509CertificateProperties in project azure-sdk-for-java by Azure.
the class CertificateOperationsTest method createSelfSignedCertificatePem.
/**
* Create a self-signed certificate in PEM format (which includes the
* private key) certificate.
*
* @throws Exception
*/
@Test
public void createSelfSignedCertificatePem() throws Exception {
// Set content type to indicate the certificate is PKCS12 format.
SecretProperties secretProperties = new SecretProperties().withContentType(MIME_PEM);
String subjectName = "CN=SelfSignedJavaPem";
X509CertificateProperties x509Properties = new X509CertificateProperties().withSubject(subjectName).withValidityInMonths(12);
// Set issuer to "Self"
IssuerParameters issuerParameters = new IssuerParameters().withName(ISSUER_SELF);
CertificatePolicy certificatePolicy = new CertificatePolicy().withSecretProperties(secretProperties).withIssuerParameters(issuerParameters).withX509CertificateProperties(x509Properties);
String vaultUri = getVaultUri();
String certificateName = "SelfSignedJavaPem";
CertificateOperation certificateOperation = keyVaultClient.createCertificate(new CreateCertificateRequest.Builder(vaultUri, certificateName).withPolicy(certificatePolicy).build());
Assert.assertNotNull(certificateOperation);
Assert.assertTrue(certificateOperation.status().equalsIgnoreCase(STATUS_IN_PROGRESS));
CertificateBundle certificateBundle = pollOnCertificateOperation(certificateOperation);
validateCertificateBundle(certificateBundle, certificatePolicy);
validatePem(certificateBundle, subjectName);
CertificateBundle deletedCertificateBundle = keyVaultClient.deleteCertificate(getVaultUri(), certificateName);
Assert.assertNotNull(deletedCertificateBundle);
try {
keyVaultClient.getCertificate(deletedCertificateBundle.certificateIdentifier().baseIdentifier());
} catch (KeyVaultErrorException e) {
Assert.assertNotNull(e.body().error());
Assert.assertEquals("CertificateNotFound", e.body().error().code());
}
}
Aggregations