Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 16fd063

Browse files
committed
Added sample TPP client code
1 parent b7475fb commit 16fd063

2 files changed

Lines changed: 77 additions & 5 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ VCert releases are tested using the latest version of Trust Protection Platform.
1212

1313
## Installation
1414

15-
The current version of this library can be install using
15+
The current version of this library can be installed using Maven:
1616

1717
```
1818
mvn install
@@ -143,13 +143,13 @@ To run the acceptance tests the following environment variables must be set:
143143

144144
| NAME | NOTES |
145145
|------|-------|
146-
| VENAFI_USER | |
147-
| VENAFI_PASSWORD | |
146+
| VENAFI_USER | Only for TPP connector tests |
147+
| VENAFI_PASSWORD | Only for TPP connector tests |
148148
| VENAFI_TPP_URL | Only for TPP connector tests |
149-
| VENAFI_API_KEY | Taken from account after logged in |
149+
| VENAFI_API_KEY | Taken from account after logged into TPP |
150150
| VENAFI_CERT_COMMON_NAME | Used for cert creation, should match configured domains |
151151
| VENAFI_CLOUD_URL | Only for cloud connector tests |
152-
| VENAFI_ZONE | Only for cloud connector tests |
152+
| VENAFI_ZONE | Policy folder for TPP |
153153

154154
Acceptance test are executed with:
155155
```

examples/TppClient.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import com.venafi.vcert.sdk.Config;
2+
import com.venafi.vcert.sdk.VCertException;
3+
import com.venafi.vcert.sdk.VCertClient;
4+
5+
import com.venafi.vcert.sdk.certificate.CertificateRequest;
6+
import com.venafi.vcert.sdk.certificate.KeyType;
7+
import com.venafi.vcert.sdk.certificate.PEMCollection;
8+
import com.venafi.vcert.sdk.certificate.RenewalRequest;
9+
import com.venafi.vcert.sdk.connectors.tpp.ZoneConfiguration;
10+
import com.venafi.vcert.sdk.endpoint.Authentication;
11+
import com.venafi.vcert.sdk.endpoint.ConnectorType;
12+
import org.apache.commons.codec.digest.DigestUtils;
13+
14+
import java.security.cert.CertificateEncodingException;
15+
import java.security.cert.X509Certificate;
16+
import java.util.Arrays;
17+
import java.util.Collections;
18+
19+
public class TppClient
20+
{
21+
public static void main(String ... args) throws VCertException, CertificateEncodingException
22+
{
23+
String tpp_user = System.getenv("TPP_USER");
24+
String tpp_passwd = System.getenv("TPP_PASSWORD");
25+
String url = System.getenv("VENAFI_URL");
26+
String zone = System.getenv("VENAFI_ZONE");
27+
28+
if ( tpp_user == null ) tpp_user = "local:admin";
29+
if ( tpp_passwd == null ) tpp_passwd = "Passw0rd";
30+
if ( url == null ) url = "https://tpp.venafi.example/vedsdk";
31+
if ( zone == null ) zone = "Default";
32+
33+
final Config config = Config.builder()
34+
.connectorType(ConnectorType.TPP)
35+
.baseUrl(url)
36+
.build();
37+
38+
final VCertClient client = new VCertClient(config);
39+
40+
final Authentication auth = Authentication.builder()
41+
.user(tpp_user)
42+
.password(tpp_passwd)
43+
.build();
44+
45+
client.authenticate(auth);
46+
47+
final ZoneConfiguration zoneConfiguration = client.readZoneConfiguration(zone);
48+
49+
// Generate a certificate
50+
CertificateRequest certificateRequest = new CertificateRequest().subject(
51+
new CertificateRequest.PKIXName()
52+
.commonName("vcert-java.venafi.example")
53+
.organization(Collections.singletonList("Venafi, Inc."))
54+
.organizationalUnit(Arrays.asList("Product Management"))
55+
.country(Collections.singletonList("US"))
56+
.locality(Collections.singletonList("Salt Lake City"))
57+
.province(Collections.singletonList("Utah")))
58+
59+
.keyType(KeyType.RSA)
60+
.keyLength(2048);
61+
62+
certificateRequest = client.generateRequest(zoneConfiguration, certificateRequest);
63+
64+
// Submit the certificate request
65+
String newCertId = client.requestCertificate(certificateRequest, zone);
66+
67+
// Retrieve PEM collection from Venafi
68+
final CertificateRequest pickupRequest = new CertificateRequest().pickupId(newCertId);
69+
PEMCollection pemCollection = client.retrieveCertificate(pickupRequest);
70+
System.out.println(pemCollection.certificate());
71+
}
72+
}

0 commit comments

Comments
 (0)