use of com.venafi.vcert.sdk.certificate.PEMCollection 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.certificate.PEMCollection 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.certificate.PEMCollection in project vcert-java by Venafi.
the class TppConnectorCertAT method createCertificateValidateValidityHours.
@Test
@DisplayName("Create a cerfiticate and validate specified validity hours - TPP")
void createCertificateValidateValidityHours() throws UnknownHostException, VCertException {
TppConnector connector = connectorResource.connector();
ZoneConfiguration zoneConfiguration = connectorResource.zoneConfiguration();
CertificateRequest cr = connectorResource.certificateRequest().validityHours(TestUtils.VALID_HOURS).issuerHint("MICROSOFT");
cr = connector.generateRequest(zoneConfiguration, cr);
// Submit the certificate request
connector.requestCertificate(cr, zoneConfiguration);
// Retrieve PEM collection from Venafi
PEMCollection pemCollection = connector.retrieveCertificate(cr);
Date notAfter = pemCollection.certificate().getNotAfter();
LocalDate notAfterDate = notAfter.toInstant().atOffset(ZoneOffset.UTC).toLocalDate();
Instant now = Instant.now();
LocalDateTime utcDateTime = LocalDateTime.ofInstant(now, ZoneOffset.UTC);
int validityDays = VCertUtils.getValidityDays(TestUtils.VALID_HOURS);
utcDateTime = utcDateTime.plusDays(validityDays);
LocalDate nowDateInUTC = utcDateTime.toLocalDate();
// Dates should be equals if not then it will fail
assertTrue(notAfterDate.compareTo(nowDateInUTC) == 0);
}
use of com.venafi.vcert.sdk.certificate.PEMCollection in project vcert-java by Venafi.
the class TppConnectorCertAT method renewCertificate.
@Test
void renewCertificate() throws VCertException, UnknownHostException, SocketException, CertificateException, NoSuchAlgorithmException {
TppConnector connector = connectorResource.connector();
ZoneConfiguration zoneConfiguration = connectorResource.zoneConfiguration();
CertificateRequest certificateRequest = connector.generateRequest(zoneConfiguration, connectorResource.certificateRequest());
certificateRequest = connector.generateRequest(zoneConfiguration, certificateRequest);
String certificateId = connector.requestCertificate(certificateRequest, zoneConfiguration);
assertThat(certificateId).isNotNull();
PEMCollection pemCollection = connector.retrieveCertificate(certificateRequest);
X509Certificate cert = (X509Certificate) pemCollection.certificate();
String thumbprint = DigestUtils.sha1Hex(cert.getEncoded()).toUpperCase();
CertificateRequest certificateRequestToRenew = new CertificateRequest().subject(certificateRequest.subject()).dnsNames(certificateRequest.dnsNames()).ipAddresses(certificateRequest.ipAddresses()).keyType(certificateRequest.keyType()).keyLength(certificateRequest.keyLength());
connector.generateRequest(zoneConfiguration, certificateRequestToRenew);
String renewRequestId = connector.renewCertificate(new RenewalRequest().request(certificateRequestToRenew).thumbprint(thumbprint));
assertThat(renewRequestId).isNotNull();
}
use of com.venafi.vcert.sdk.certificate.PEMCollection in project vcert-java by Venafi.
the class TppTokenConnectorCertAT method renewCertificate.
@Test
void renewCertificate() throws VCertException, UnknownHostException, SocketException, CertificateException, NoSuchAlgorithmException {
TppTokenConnector connector = connectorResource.connector();
ZoneConfiguration zoneConfiguration = connectorResource.zoneConfiguration();
CertificateRequest certificateRequest = connector.generateRequest(zoneConfiguration, connectorResource.certificateRequest());
String certificateId = connector.requestCertificate(certificateRequest, zoneConfiguration);
assertThat(certificateId).isNotNull();
PEMCollection pemCollection = connector.retrieveCertificate(certificateRequest);
X509Certificate cert = (X509Certificate) pemCollection.certificate();
String thumbprint = DigestUtils.sha1Hex(cert.getEncoded()).toUpperCase();
CertificateRequest certificateRequestToRenew = new CertificateRequest().subject(certificateRequest.subject()).dnsNames(certificateRequest.dnsNames()).ipAddresses(certificateRequest.ipAddresses()).keyType(certificateRequest.keyType()).keyLength(certificateRequest.keyLength());
connector.generateRequest(zoneConfiguration, certificateRequestToRenew);
String renewRequestId = connector.renewCertificate(new RenewalRequest().request(certificateRequestToRenew).thumbprint(thumbprint));
assertThat(renewRequestId).isNotNull();
}
Aggregations