Search in sources :

Example 11 with SslTrustCertificateState

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);
}
Also used : SslTrustCertificateState(com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState) URI(java.net.URI) Test(org.junit.Test)

Example 12 with SslTrustCertificateState

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.");
}
Also used : SslTrustCertificateState(com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState) CountDownLatch(java.util.concurrent.CountDownLatch) X509Certificate(java.security.cert.X509Certificate) Test(org.junit.Test)

Example 13 with SslTrustCertificateState

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"));
    }
}
Also used : SslTrustCertificateState(com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState)

Aggregations

SslTrustCertificateState (com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState)13 Test (org.junit.Test)6 URI (java.net.URI)2 X509Certificate (java.security.cert.X509Certificate)2 Before (org.junit.Before)2 ResourceOperation (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation)1 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)1 ServerX509TrustManager (com.vmware.photon.controller.model.security.ssl.ServerX509TrustManager)1 X509TrustManagerResolver (com.vmware.photon.controller.model.security.ssl.X509TrustManagerResolver)1 Operation (com.vmware.xenon.common.Operation)1 QueryTask (com.vmware.xenon.services.common.QueryTask)1 Query (com.vmware.xenon.services.common.QueryTask.Query)1 IOException (java.io.IOException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1