use of com.microsoft.azure.keyvault.models.CertificateBundle 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.CertificateBundle in project azure-sdk-for-java by Azure.
the class KeyVaultClientImpl method mergeCertificateWithServiceResponseAsync.
/**
* Merges a certificate or a certificate chain with a key pair existing on the server.
*
* @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net.
* @param certificateName The name of the certificate.
* @param x509Certificates The certificate or the certificate chain to merge.
* @return the observable to the CertificateBundle object
*/
public Observable<ServiceResponse<CertificateBundle>> mergeCertificateWithServiceResponseAsync(String vaultBaseUrl, String certificateName, List<byte[]> x509Certificates) {
if (vaultBaseUrl == null) {
throw new IllegalArgumentException("Parameter vaultBaseUrl is required and cannot be null.");
}
if (certificateName == null) {
throw new IllegalArgumentException("Parameter certificateName is required and cannot be null.");
}
if (this.apiVersion() == null) {
throw new IllegalArgumentException("Parameter this.apiVersion() is required and cannot be null.");
}
if (x509Certificates == null) {
throw new IllegalArgumentException("Parameter x509Certificates is required and cannot be null.");
}
Validator.validate(x509Certificates);
final CertificateAttributes certificateAttributes = null;
final Map<String, String> tags = null;
CertificateMergeParameters parameters = new CertificateMergeParameters();
parameters.withX509Certificates(x509Certificates);
parameters.withCertificateAttributes(null);
parameters.withTags(null);
String parameterizedHost = Joiner.on(", ").join("{vaultBaseUrl}", vaultBaseUrl);
return service.mergeCertificate(certificateName, this.apiVersion(), this.acceptLanguage(), parameters, parameterizedHost, this.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<CertificateBundle>>>() {
@Override
public Observable<ServiceResponse<CertificateBundle>> call(Response<ResponseBody> response) {
try {
ServiceResponse<CertificateBundle> clientResponse = mergeCertificateDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
use of com.microsoft.azure.keyvault.models.CertificateBundle 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());
}
}
use of com.microsoft.azure.keyvault.models.CertificateBundle in project azure-sdk-for-java by Azure.
the class KeyVaultClientImpl method updateCertificateWithServiceResponseAsync.
/**
* Updates the specified attributes associated with the given certificate.
*
* @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net.
* @param certificateName The name of the certificate in the given key vault.
* @param certificateVersion The version of the certificate.
* @return the observable to the CertificateBundle object
*/
public Observable<ServiceResponse<CertificateBundle>> updateCertificateWithServiceResponseAsync(String vaultBaseUrl, String certificateName, String certificateVersion) {
if (vaultBaseUrl == null) {
throw new IllegalArgumentException("Parameter vaultBaseUrl is required and cannot be null.");
}
if (certificateName == null) {
throw new IllegalArgumentException("Parameter certificateName is required and cannot be null.");
}
if (certificateVersion == null) {
throw new IllegalArgumentException("Parameter certificateVersion is required and cannot be null.");
}
if (this.apiVersion() == null) {
throw new IllegalArgumentException("Parameter this.apiVersion() is required and cannot be null.");
}
final CertificatePolicy certificatePolicy = null;
final CertificateAttributes certificateAttributes = null;
final Map<String, String> tags = null;
CertificateUpdateParameters parameters = new CertificateUpdateParameters();
parameters.withCertificatePolicy(null);
parameters.withCertificateAttributes(null);
parameters.withTags(null);
String parameterizedHost = Joiner.on(", ").join("{vaultBaseUrl}", vaultBaseUrl);
return service.updateCertificate(certificateName, certificateVersion, this.apiVersion(), this.acceptLanguage(), parameters, parameterizedHost, this.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<CertificateBundle>>>() {
@Override
public Observable<ServiceResponse<CertificateBundle>> call(Response<ResponseBody> response) {
try {
ServiceResponse<CertificateBundle> clientResponse = updateCertificateDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
use of com.microsoft.azure.keyvault.models.CertificateBundle in project azure-sdk-for-java by Azure.
the class KeyVaultClientImpl method importCertificateWithServiceResponseAsync.
/**
* Imports a certificate into a specified key vault.
*
* @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net.
* @param certificateName The name of the certificate.
* @param base64EncodedCertificate Base64 encoded representation of the certificate object to import. This certificate needs to contain the private key.
* @return the observable to the CertificateBundle object
*/
public Observable<ServiceResponse<CertificateBundle>> importCertificateWithServiceResponseAsync(String vaultBaseUrl, String certificateName, String base64EncodedCertificate) {
if (vaultBaseUrl == null) {
throw new IllegalArgumentException("Parameter vaultBaseUrl is required and cannot be null.");
}
if (certificateName == null) {
throw new IllegalArgumentException("Parameter certificateName is required and cannot be null.");
}
if (this.apiVersion() == null) {
throw new IllegalArgumentException("Parameter this.apiVersion() is required and cannot be null.");
}
if (base64EncodedCertificate == null) {
throw new IllegalArgumentException("Parameter base64EncodedCertificate is required and cannot be null.");
}
final String password = null;
final CertificatePolicy certificatePolicy = null;
final CertificateAttributes certificateAttributes = null;
final Map<String, String> tags = null;
CertificateImportParameters parameters = new CertificateImportParameters();
parameters.withBase64EncodedCertificate(base64EncodedCertificate);
parameters.withPassword(null);
parameters.withCertificatePolicy(null);
parameters.withCertificateAttributes(null);
parameters.withTags(null);
String parameterizedHost = Joiner.on(", ").join("{vaultBaseUrl}", vaultBaseUrl);
return service.importCertificate(certificateName, this.apiVersion(), this.acceptLanguage(), parameters, parameterizedHost, this.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<CertificateBundle>>>() {
@Override
public Observable<ServiceResponse<CertificateBundle>> call(Response<ResponseBody> response) {
try {
ServiceResponse<CertificateBundle> clientResponse = importCertificateDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
Aggregations