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());
}
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());
}
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));
}
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);
}
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);
}
Aggregations