1- # VCert- Java
1+ # VCert Java
22
33<img src =" https://www.venafi.com/sites/default/files/content/body/Light_background_logo.png " width =" 330px " height =" 69px " />
44
55VCert is a Java library, SDK, designed to simplify key generation and enrollment of machine identities
66(also known as SSL/TLS certificates and keys) that comply with enterprise security policy by using the
77[ Venafi Platform] ( https://www.venafi.com/platform/trust-protection-platform ) or [ Venafi Cloud] ( https://pki.venafi.com/venafi-cloud/ ) .
88
9-
9+ #### Compatibility
10+ VCert releases are tested using the latest version of Trust Protection Platform. The [ latest VCert release] ( ../../releases/latest ) should be compatible with Trust Protection Platform 17.3 or higher based on the subset of API methods it consumes.
1011
1112
1213## Installation
@@ -20,71 +21,103 @@ mvn install
2021
2122## Usage
2223
23- A basic example of createing a certificate using the VCert java implementation.
24+ A basic example of creating a certificate using VCert Java:
2425
2526```
26- final Config config = Config.builder()
27- .connectorType(ConnectorType.CLOUD)
28- .zone("Default")
29- .build();
30-
31- final VCertClient client = new VCertClient(config);
32- final Authentication auth = Authentication.builder()
33- .apiKey("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
34- .build();
35-
36- client.authenticate(auth);
37- final ZoneConfiguration zoneConfiguration = client.readZoneConfiguration("Public");
38-
39-
40-
41- // Generate a certificate
42- CertificateRequest certificateRequest = new CertificateRequest().subject(
43- new CertificateRequest.PKIXName()
44- .commonName("opencredo.test")
45- .organization(Collections.singletonList("Venafi, Inc."))
46- .organizationalUnit(Arrays.asList("Engineering"))
47- .country(Collections.singletonList("US"))
48- .locality(Collections.singletonList("SLC"))
49- .province(Collections.singletonList("Utah")))
50-
51- .keyType(KeyType.RSA);
52- certificateRequest = client.generateRequest(zoneConfiguration, certificateRequest);
53-
54-
55- // Submit the certificate request
56- String newCertId = client.requestCertificate(certificateRequest, "Default");
57-
58-
59- // Retrieve PEM collection from Venafi
60- final CertificateRequest pickupRequest = new CertificateRequest().pickupId(newCertId);
61- PEMCollection pemCollection = client.retrieveCertificate(pickupRequest);
62- System.out.println(pemCollection.certificate());
63-
64- // Renew the certificate
65- X509Certificate cert = (X509Certificate) pemCollection.certificate();
66- String thumbprint = DigestUtils.sha1Hex(cert.getEncoded()).toUpperCase();
67- final CertificateRequest certificateRequestToRenew = new CertificateRequest().subject(
68- new CertificateRequest.PKIXName()
69- .commonName("opencredo.test")
70- .organization(Collections.singletonList("Venafi, Inc."))
71- .organizationalUnit(Arrays.asList("Engineering"))
72- .country(Collections.singletonList("US"))
73- .locality(Collections.singletonList("SLC"))
74- .province(Collections.singletonList("Utah")));
75-
76- client.generateRequest(zoneConfiguration, certificateRequestToRenew);
77-
78- final RenewalRequest renewalRequest = new RenewalRequest()
79- .thumbprint(thumbprint)
80- .request(certificateRequestToRenew);
81- final String renewedCertificate = client.renewCertificate(renewalRequest);
82-
83- // Retrieve PEM collection from Venafi
84- final CertificateRequest renewPickupRequest = new CertificateRequest().pickupId(renewedCertificate);
85- PEMCollection pemCollectionRenewed = client.retrieveCertificate(pickupRequest);
86- System.out.println(pemCollectionRenewed.certificate());
87-
27+ final Config config = Config.builder()
28+ .connectorType(ConnectorType.TPP)
29+ .baseUrl("https://tpp.venafi.example/vedsdk")
30+ .build();
31+
32+ /* or for Venafi Cloud
33+ final Config config = Config.builder()
34+ .connectorType(ConnectorType.CLOUD)
35+ .build();
36+ */
37+
38+ final VCertClient client = new VCertClient(config);
39+
40+ final Authentication auth = Authentication.builder()
41+ .user("local:apiuser")
42+ .password("password")
43+ .build();
44+
45+ /* or for Venafi Cloud
46+ final Authentication auth = Authentication.builder()
47+ .apiKey("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")
48+ .build();
49+ */
50+
51+ client.authenticate(auth);
52+
53+ //////////////////////////////////////
54+ ///// Local Generated CSR - RSA //////
55+ //////////////////////////////////////
56+
57+ // Generate a key pair and certificate signing request
58+ CertificateRequest certificateRequest = new CertificateRequest().subject(
59+ new CertificateRequest.PKIXName()
60+ .commonName("vcert-java.venafi.example")
61+ .organization(Collections.singletonList("Example Company"))
62+ .organizationalUnit(Arrays.asList("Example Division"))
63+ .country(Collections.singletonList("US"))
64+ .locality(Collections.singletonList("Salt Lake City"))
65+ .province(Collections.singletonList("Utah")))
66+ .dnsNames(Arrays.asList("alfa.venafi.example", "bravo.venafi.example", "charlie.venafi.example"))
67+ .ipAddresses(Arrays.asList(InetAddress.getByName("10.20.30.40"),InetAddress.getByName("172.16.172.16")))
68+ .emailAddresses(Arrays.asList("larry@venafi.example", "moe@venafi.example", "curly@venafi.example"))
69+ .keyType(KeyType.RSA);
70+
71+ ZoneConfiguration zoneConfiguration = client.readZoneConfiguration("Certificates\\VCert");
72+ certificateRequest = client.generateRequest(zoneConfiguration, certificateRequest);
73+
74+ // Submit the certificate request
75+ client.requestCertificate(certificateRequest, "Certificates\\VCert");
76+
77+ // Retrieve PEM collection from Venafi
78+ PEMCollection pemCollection = client.retrieveCertificate(certificateRequest);
79+
80+ System.out.println(pemCollection.pemPrivateKey());
81+ System.out.println(pemCollection.pemCertificate());
82+ System.out.println(pemCollection.pemCertificateChain());
83+
84+ /////////////////////////////
85+ ///// User Provided CSR /////
86+ /////////////////////////////
87+
88+ String csr = "-----BEGIN CERTIFICATE REQUEST-----\n" +
89+ "MIIC8DCCAdgCAQAwgY4xCzAJBgNVBAYTAlVTMQ0wCwYDVQQIEwRVdGFoMRcwFQYD\n" +
90+ "VQQHEw5TYWx0IExha2UgQ2l0eTEYMBYGA1UEChMPRXhhbXBsZSBDb21wYW55MRkw\n" +
91+ "FwYDVQQLExBFeGFtcGxlIERpdmlzaW9uMSIwIAYDVQQDExl2Y2VydC1qYXZhLnZl\n" +
92+ "bmFmaS5leGFtcGxlMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA9PHk\n" +
93+ "bR5i0pV6M08XXi+Z0tAJkIU3TLG0Hr0n5tY6JIcP3Sc8wrodgMN66WUP6oLV/yqR\n" +
94+ "2lKom+dc9dIN9iaVUfnpPwhjyuIMyd0svmU2hnZj3InG5kvqnMnzQvRfWx0OKmMB\n" +
95+ "c652qZsgR3d6I+YufhIsuMxkWMev2njXGZAnThGVMv/iD9dLTO+0lTwwSbvM1lxw\n" +
96+ "YxAwdVFX1+vl0ORyOs4OUqUFv3i6qvS/U/RI45TrgR+XA2/8xPlo5gfGrnFfiyJJ\n" +
97+ "jMctOak2mOVrR/2kXYcOw+37zkpJEADSZBgm/YzqdYtrI8t/M4uClkn9WQgTijC1\n" +
98+ "eN4hFKyTGeOGIqKI/QIDAQABoBwwGgYJKoZIhvcNAQkOMQ0wCzAJBgNVHRMEAjAA\n" +
99+ "MA0GCSqGSIb3DQEBCwUAA4IBAQDOxsP3fFsx/UOLudVm6MAuAFZfZxm7P1sZrYhb\n" +
100+ "tgshSXDlruiO7/ovb8rDrRrKJjAx4+tXlQRsDfxIpvuNcAd7//WCjjIfAoNlGRW4\n" +
101+ "cMtWfvCN1p7XsVer+JJHtM5UZ+oKS06hdPppDP4rfjyhTM5Y0M8JAgMcGsm7lrWU\n" +
102+ "w1ly6k8k5NzadWGOZwvz75qrn0ufHuI96sPsL5wmqty34BfnBy4iMddU3m/Y1qQb\n" +
103+ "VfKV2CRWybwV/QeCtogXvI7Nou2LZQDWI57498Nzif1Zvfy0/ab8XBkX2vMUXcnm\n" +
104+ "1A7/9ezwgYTZvy1rbBSKBSjAx/MAOPUM93OcjT6tKtEeEnI8\n" +
105+ "-----END CERTIFICATE REQUEST-----";
106+
107+ certificateRequest = new CertificateRequest().csr(csr.getBytes())
108+ .csrOrigin(com.venafi.vcert.sdk.certificate.CsrOriginOption.UserProvidedCSR)
109+ .dnsNames(Arrays.asList("alfa.venafi.example", "bravo.venafi.example", "charlie.venafi.example"))
110+ .ipAddresses(Arrays.asList(InetAddress.getByName("10.20.30.40"),InetAddress.getByName("172.16.172.16")))
111+ .emailAddresses(Arrays.asList("larry@venafi.example", "moe@venafi.example", "curly@venafi.example"));
112+
113+ // Submit the certificate request
114+ client.requestCertificate(certificateRequest, "Certificates\\VCert");
115+
116+ // Retrieve PEM collection from Venafi
117+ pemCollection = client.retrieveCertificate(certificateRequest);
118+
119+ System.out.println(pemCollection.pemCertificate());
120+ System.out.println(pemCollection.pemCertificateChain());
88121
89122```
90123
@@ -132,7 +165,7 @@ mvn "-Dtest=*AT" test
1321654 . Implement and test your changes
1331665 . Commit your changes (` git commit -am 'Added some cool functionality' ` )
1341676 . Push to the branch (` git push origin your-branch-name ` )
135- 7 . Create a new Pull Request (https://github.com/youracct/vcert-java/pull/new/working -branch )
168+ 7 . Create a new Pull Request (https://github.com/youracct/vcert-java/pull/new/your -branch-name )
136169
137170
138171## License
0 commit comments