Search in sources :

Example 6 with SslTrustCertificateState

use of com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState in project photon-model by vmware.

the class CommonTestStateFactory method createSslTrustCertificateState.

public static SslTrustCertificateState createSslTrustCertificateState(String pemFileName, String id) {
    SslTrustCertificateState sslTrustState = new SslTrustCertificateState();
    sslTrustState.documentSelfLink = id;
    sslTrustState.certificate = getFileContent(pemFileName);
    return sslTrustState;
}
Also used : SslTrustCertificateState(com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState)

Example 7 with SslTrustCertificateState

use of com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState in project photon-model by vmware.

the class SslTrustCertificateServiceUtils method loadCertificates.

static void loadCertificates(ServiceHost host, Consumer<SslTrustCertificateState> consumer) {
    Query.Builder query = Query.Builder.create().addKindFieldClause(SslTrustCertificateState.class);
    QueryStrategy<SslTrustCertificateState> queryLocalStates = new QueryUtils.QueryByPages<>(host, query.build(), SslTrustCertificateState.class, null, null).setMaxPageSize(QUERY_RESULT_LIMIT);
    queryLocalStates.queryDocuments(c -> {
        try {
            host.log(Level.FINE, "Processing '%s'.", c);
            SslTrustCertificateState sslTrustCert = Utils.fromJson(c, SslTrustCertificateState.class);
            host.log(Level.FINE, "Certificate with '%s', issuer '%s' and alias '%s' loaded.", sslTrustCert.commonName, sslTrustCert.issuerName, sslTrustCert.getAlias());
            consumer.accept(sslTrustCert);
        } catch (Exception e) {
            host.log(Level.WARNING, "cannot deserialize " + c);
        }
    });
}
Also used : Query(com.vmware.xenon.services.common.QueryTask.Query) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) SslTrustCertificateState(com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState)

Example 8 with SslTrustCertificateState

use of com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState in project photon-model by vmware.

the class BaseVSphereAdapterTest method setUp.

@Before
public void setUp() throws Throwable {
    this.host = VerificationHost.create(Integer.getInteger(TestProperties.HOST_PREFERRED_PORT, 0));
    String bindingAddress = System.getProperty(TestProperties.HOST_BINDING_ADDRESS);
    if (!StringUtils.isEmpty(bindingAddress)) {
        this.host.setBindAddress(bindingAddress);
    }
    this.host.start();
    this.host.waitForServiceAvailable(ExampleService.FACTORY_LINK);
    // TODO: VSYM-992 - improve test/fix arbitrary timeout
    // must be at least 15min as default timeout to get an IP is 10min
    this.host.setTimeoutSeconds(15 * 60);
    try {
        PhotonModelAdaptersRegistryAdapters.startServices(this.host);
        PhotonModelServices.startServices(this.host);
        PhotonModelMetricServices.startServices(this.host);
        PhotonModelTaskServices.startServices(this.host);
        PhotonModelSecurityServices.startServices(this.host);
        this.host.waitForServiceAvailable(PhotonModelServices.LINKS);
        this.host.waitForServiceAvailable(PhotonModelTaskServices.LINKS);
        this.host.waitForServiceAvailable(PhotonModelSecurityServices.LINKS);
        startAdditionalServices();
        ServerX509TrustManager.create(this.host);
    } catch (Throwable e) {
        this.host.log("Error starting up services for the test %s", e.getMessage());
        throw new Exception(e);
    }
    if (this.vcUrl == null) {
        this.vcUrl = "http://not-configured";
    } else {
        X509TrustManagerResolver resolver = CertificateUtil.resolveCertificate(URI.create(this.vcUrl), 20000);
        if (!resolver.isCertsTrusted()) {
            SslTrustCertificateState certState = new SslTrustCertificateState();
            certState.certificate = CertificateUtil.toPEMformat(resolver.getCertificate());
            SslTrustCertificateState.populateCertificateProperties(certState, resolver.getCertificate());
            Operation op = Operation.createPost(this.host, SslTrustCertificateService.FACTORY_LINK).setReferer(this.host.getReferer()).setBody(certState);
            this.host.waitForResponse(op);
        }
    }
    if (this.dataStoreId != null) {
        this.dataStoreId = this.dataStoreId.substring(this.dataStoreId.lastIndexOf("/") + 1, this.dataStoreId.length());
    }
    doSetup();
}
Also used : SslTrustCertificateState(com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState) X509TrustManagerResolver(com.vmware.photon.controller.model.security.ssl.X509TrustManagerResolver) ResourceOperation(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation) Operation(com.vmware.xenon.common.Operation) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Before(org.junit.Before)

Example 9 with SslTrustCertificateState

use of com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState in project photon-model by vmware.

the class SslTrustCertificateServiceTest method testIdempotentPOST.

@Test
public void testIdempotentPOST() throws Throwable {
    SslTrustCertificateState sslTrustCert1 = new SslTrustCertificateState();
    sslTrustCert1.certificate = this.sslTrust1;
    sslTrustCert1.subscriptionLink = null;
    sslTrustCert1 = doPost(sslTrustCert1, SslTrustCertificateService.FACTORY_LINK);
    SslTrustCertificateState sslTrustCert2 = new SslTrustCertificateState();
    sslTrustCert2.certificate = this.sslTrust1;
    sslTrustCert2.subscriptionLink = "subscription-link";
    sslTrustCert2 = doPost(sslTrustCert2, SslTrustCertificateService.FACTORY_LINK);
    this.sslTrustCert = getDocument(SslTrustCertificateState.class, sslTrustCert1.documentSelfLink);
    /* We POST two different objects without explicitly setting the documentSelfLink, but these
         * objects have the same certificate. The factory will build the same documentSelfLink for
         * both of these objects and the idempotent option will turn the post to a put, so we expect
         * to have the subscriptionLink set after the POST */
    assertEquals(sslTrustCert2.subscriptionLink, this.sslTrustCert.subscriptionLink);
    validateCertProperties(this.sslTrustCert);
}
Also used : SslTrustCertificateState(com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState) Test(org.junit.Test)

Example 10 with SslTrustCertificateState

use of com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState in project photon-model by vmware.

the class SslTrustCertificateServiceTest method testPATCH.

@Test
public void testPATCH() 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.PATCH);
    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)

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