use of com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState in project photon-model by vmware.
the class SslTrustCertificateServiceTest method testPUT.
@Test
public void testPUT() throws Throwable {
this.sslTrustCert = doPost(this.sslTrustCert, SslTrustCertificateService.FACTORY_LINK);
this.sslTrustCert.certificate = this.sslTrust2;
boolean expectedFailure = false;
URI uri = UriUtils.buildUri(this.host, this.sslTrustCert.documentSelfLink);
doOperation(this.sslTrustCert, uri, expectedFailure, Action.PUT);
SslTrustCertificateState updatedSslTrustCert = getDocument(SslTrustCertificateState.class, this.sslTrustCert.documentSelfLink);
assertEquals(this.sslTrust2, updatedSslTrustCert.certificate);
validateCertProperties(updatedSslTrustCert);
}
use of com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState in project photon-model by vmware.
the class SslTrustCertificateServiceUtilsTest method registerAndDeleteCertificate.
@Test
public void registerAndDeleteCertificate() throws Throwable {
CountDownLatch register = new CountDownLatch(1);
CountDownLatch delete = new CountDownLatch(1);
SslTrustCertificateServiceUtils.subscribe(this.host, consumer(register, delete));
SslTrustCertificateState certState = new SslTrustCertificateState();
String certPEM = CommonTestStateFactory.getFileContent("test_ssl_trust.PEM").trim();
X509Certificate[] certificates = CertificateUtil.createCertificateChain(certPEM);
// Populate the certificate properties based on the first (end server) certificate
X509Certificate endCertificate = certificates[0];
certState.certificate = CertificateUtil.toPEMformat(endCertificate);
SslTrustCertificateState.populateCertificateProperties(certState, endCertificate);
this.logger.info(String.format("Register certificate with common name: %s and fingerprint: %s in trust store", certState.commonName, certState.fingerprint));
// save untrusted certificate to the trust store
this.host.send(Operation.createPost(this.host, SslTrustCertificateService.FACTORY_LINK).setBody(certState).addPragmaDirective(Operation.PRAGMA_DIRECTIVE_FORCE_INDEX_UPDATE));
if (!register.await(MAX_TIMEOUT_TO_WAIT_IN_MILLIS, TimeUnit.MILLISECONDS)) {
Assert.fail("No register notification received");
}
String certDocumentId = CertificateUtil.generatePureFingerPrint(CertificateUtil.createCertificateChain(certState.certificate));
this.logger.info("Certificate " + certDocumentId + " registered.");
String deleteLink = UriUtils.buildUriPath(SslTrustCertificateService.FACTORY_LINK, certDocumentId);
this.host.send(Operation.createDelete(this.host, deleteLink));
if (!delete.await(MAX_TIMEOUT_TO_WAIT_IN_MILLIS, TimeUnit.MILLISECONDS)) {
Assert.fail("No delete notification received for " + deleteLink);
}
this.logger.info("Certificate " + certDocumentId + " deleted.");
}
use of com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState in project photon-model by vmware.
the class SslTrustCertificateFactoryService method handlePost.
/**
* Override the handlePost method to set the documentSelfLink. We don't want to have multiple
* certificate states with the same certificate, so we build the documentSelfLink ourselves
*
* @param op
*/
@Override
public void handlePost(Operation op) {
if (op.isSynchronize()) {
op.complete();
return;
}
if (op.hasBody()) {
SslTrustCertificateState body = (SslTrustCertificateState) op.getBody(this.stateType);
if (body == null) {
op.fail(new IllegalArgumentException("structured body is required"));
return;
}
if (body.documentSourceLink != null) {
op.fail(new IllegalArgumentException("clone request not supported"));
return;
}
body.documentSelfLink = generateSelfLink(body);
op.setBody(body);
op.complete();
} else {
op.fail(new IllegalArgumentException("body is required"));
}
}
Aggregations