Search in sources :

Example 21 with ZoneConfiguration

use of com.venafi.vcert.sdk.connectors.ZoneConfiguration in project vcert-java by Venafi.

the class CloudClient method main.

public static void main(String[] args) throws VCertException, CertificateEncodingException, NoSuchAlgorithmException, KeyManagementException {
    String url = System.getenv("CLOUDURL");
    String zone = System.getenv("CLOUDZONE");
    String appInfo = System.getenv("PRODUCT");
    String apiKey = System.getenv("APIKEY");
    if (zone == null) {
        // or by ID "38992cc0-0177-11ea-a3f0-2b5db8116980";
        zone = "My Project\\My Zone";
    }
    if (appInfo == null)
        appInfo = "My Application 1.0.0.0";
    if (apiKey == null)
        apiKey = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
    Config config = Config.builder().connectorType(ConnectorType.CLOUD).baseUrl(url).appInfo(appInfo).build();
    Authentication auth = Authentication.builder().apiKey(apiKey).build();
    VCertClient client = new VCertClient(config);
    client.authenticate(auth);
    ZoneConfiguration zoneConfiguration = client.readZoneConfiguration(zone);
    // Generate a certificate
    CertificateRequest certificateRequest = new CertificateRequest().subject(new CertificateRequest.PKIXName().commonName("vcert-java.venafi.example").organization(Collections.singletonList("Venafi, Inc.")).organizationalUnit(Arrays.asList("Product Management")).country(Collections.singletonList("US")).locality(Collections.singletonList("Salt Lake City")).province(Collections.singletonList("Utah"))).keyType(KeyType.RSA).keyLength(2048);
    certificateRequest = client.generateRequest(zoneConfiguration, certificateRequest);
    // Submit the certificate request
    client.requestCertificate(certificateRequest, zoneConfiguration);
    // Retrieve PEM collection from Venafi
    PEMCollection pemCollection = client.retrieveCertificate(certificateRequest);
    System.out.println(pemCollection.certificate());
}
Also used : PEMCollection(com.venafi.vcert.sdk.certificate.PEMCollection) Config(com.venafi.vcert.sdk.Config) Authentication(com.venafi.vcert.sdk.endpoint.Authentication) VCertClient(com.venafi.vcert.sdk.VCertClient) ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest)

Example 22 with ZoneConfiguration

use of com.venafi.vcert.sdk.connectors.ZoneConfiguration in project vcert-java by Venafi.

the class Examples method main.

public static void main(String... args) throws VCertException, CertificateEncodingException {
    final Config config = Config.builder().connectorType(ConnectorType.CLOUD).zone("Default").build();
    final VCertClient client = new VCertClient(config);
    final Authentication auth = Authentication.builder().apiKey("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx").build();
    client.authenticate(auth);
    final ZoneConfiguration zoneConfiguration = client.readZoneConfiguration("My Project\\My Zone");
    // Generate a certificate
    CertificateRequest certificateRequest = new CertificateRequest().subject(new CertificateRequest.PKIXName().commonName("cert.test").organization(Collections.singletonList("Venafi, Inc.")).organizationalUnit(Arrays.asList("Engineering")).country(Collections.singletonList("US")).locality(Collections.singletonList("SLC")).province(Collections.singletonList("Utah"))).keyType(KeyType.RSA);
    certificateRequest = client.generateRequest(zoneConfiguration, certificateRequest);
    // Submit the certificate request
    String newCertId = client.requestCertificate(certificateRequest, zoneConfiguration);
    // Retrieve PEM collection from Venafi
    final CertificateRequest pickupRequest = new CertificateRequest().pickupId(newCertId);
    PEMCollection pemCollection = client.retrieveCertificate(pickupRequest);
    System.out.println(pemCollection.certificate());
    // Renew the certificate
    X509Certificate cert = (X509Certificate) pemCollection.certificate();
    String thumbprint = DigestUtils.sha1Hex(cert.getEncoded()).toUpperCase();
    final CertificateRequest certificateRequestToRenew = new CertificateRequest().subject(new CertificateRequest.PKIXName().commonName("cert.test").organization(Collections.singletonList("Venafi, Inc.")).organizationalUnit(Arrays.asList("Engineering")).country(Collections.singletonList("US")).locality(Collections.singletonList("SLC")).province(Collections.singletonList("Utah")));
    client.generateRequest(zoneConfiguration, certificateRequestToRenew);
    final RenewalRequest renewalRequest = new RenewalRequest().thumbprint(thumbprint).request(certificateRequestToRenew);
    final String renewedCertificate = client.renewCertificate(renewalRequest);
    // Retrieve PEM collection from Venafi
    final CertificateRequest renewPickupRequest = new CertificateRequest().pickupId(renewedCertificate);
    PEMCollection pemCollectionRenewed = client.retrieveCertificate(pickupRequest);
    System.out.println(pemCollectionRenewed.certificate());
}
Also used : PEMCollection(com.venafi.vcert.sdk.certificate.PEMCollection) RenewalRequest(com.venafi.vcert.sdk.certificate.RenewalRequest) Authentication(com.venafi.vcert.sdk.endpoint.Authentication) ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest) X509Certificate(java.security.cert.X509Certificate)

Example 23 with ZoneConfiguration

use of com.venafi.vcert.sdk.connectors.ZoneConfiguration in project vcert-java by Venafi.

the class VCertClientTest method generateRequestWithServerError.

@Test
@DisplayName("Generate request with server error")
void generateRequestWithServerError() throws VCertException {
    final ZoneConfiguration zoneConfiguration = mock(ZoneConfiguration.class);
    final CertificateRequest certificateRequest = mock(CertificateRequest.class);
    doThrow(new FeignException.InternalServerError("Error", request, "".getBytes())).when(connector).generateRequest(zoneConfiguration, certificateRequest);
    assertThrows(VCertException.class, () -> classUnderTest.generateRequest(zoneConfiguration, certificateRequest));
}
Also used : ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) FeignException(feign.FeignException) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 24 with ZoneConfiguration

use of com.venafi.vcert.sdk.connectors.ZoneConfiguration in project vcert-java by Venafi.

the class VCertClientTest method requestCertificate.

@Test
@DisplayName("Request certificate")
void requestCertificate() throws VCertException {
    final CertificateRequest certificateRequest = mock(CertificateRequest.class);
    final ZoneConfiguration zoneConfiguration = mock(ZoneConfiguration.class);
    zoneConfiguration.zoneId("test_zone");
    classUnderTest.requestCertificate(certificateRequest, zoneConfiguration);
    verify(connector).requestCertificate(certificateRequest, zoneConfiguration);
}
Also used : ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 25 with ZoneConfiguration

use of com.venafi.vcert.sdk.connectors.ZoneConfiguration in project vcert-java by Venafi.

the class VCertClientTest method generateRequest.

@Test
@DisplayName("Generate request")
void generateRequest() throws VCertException {
    final ZoneConfiguration zoneConfiguration = mock(ZoneConfiguration.class);
    final CertificateRequest certificateRequest = mock(CertificateRequest.class);
    classUnderTest.generateRequest(zoneConfiguration, certificateRequest);
    verify(connector).generateRequest(zoneConfiguration, certificateRequest);
}
Also used : ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

ZoneConfiguration (com.venafi.vcert.sdk.connectors.ZoneConfiguration)50 CertificateRequest (com.venafi.vcert.sdk.certificate.CertificateRequest)42 Test (org.junit.jupiter.api.Test)42 DisplayName (org.junit.jupiter.api.DisplayName)20 PEMCollection (com.venafi.vcert.sdk.certificate.PEMCollection)17 RenewalRequest (com.venafi.vcert.sdk.certificate.RenewalRequest)7 StringReader (java.io.StringReader)7 X509Certificate (java.security.cert.X509Certificate)7 RevocationRequest (com.venafi.vcert.sdk.certificate.RevocationRequest)5 Authentication (com.venafi.vcert.sdk.endpoint.Authentication)5 PEMParser (org.bouncycastle.openssl.PEMParser)4 PKCS10CertificationRequest (org.bouncycastle.pkcs.PKCS10CertificationRequest)4 Config (com.venafi.vcert.sdk.Config)3 TestUtils (com.venafi.vcert.sdk.TestUtils)3 VCertException (com.venafi.vcert.sdk.VCertException)3 CsrOriginOption (com.venafi.vcert.sdk.certificate.CsrOriginOption)3 DataFormat (com.venafi.vcert.sdk.certificate.DataFormat)3 ServerPolicy (com.venafi.vcert.sdk.connectors.ServerPolicy)3 FeignException (feign.FeignException)3 IOException (java.io.IOException)3