Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
aa1d8b6
Initial commit
pegerto Mar 21, 2019
d735e8e
Update README.md
pegerto Mar 21, 2019
904cbfd
Adds authorisation functionality for Cloud and Onprem (#1)
chbalzer Mar 26, 2019
aa4ee53
Read Zone Configuration, Wiremock
chbalzer Mar 28, 2019
12e860e
Merge branch 'current'
pmack24 Mar 28, 2019
68f1d07
Feature/registeruser (#1)
pegerto Mar 29, 2019
a8f7133
Search cloud certificates (#2)
pegerto Mar 29, 2019
362f7a6
Feature/generate cert (#3)
pmack24 Apr 3, 2019
b092240
Feature/generate cert (#6)
pmack24 Apr 4, 2019
a4a9301
Feature/retrieve cert (#7)
pmack24 Apr 4, 2019
74f657f
Feature/request certificate cloud (#8)
pmack24 Apr 4, 2019
c9f90e2
Fix merge errors (#9)
pmack24 Apr 4, 2019
912e023
Certificate revoke for TPP (#10)
pmack24 Apr 4, 2019
a699068
Ping tpp and cloud (#12)
pmack24 Apr 4, 2019
b606827
Import certificate for tpp (#13)
pmack24 Apr 4, 2019
2af7d4f
Feature/cloudrenew WIP (#11)
pegerto Apr 4, 2019
fa15492
Retrive certificate request
pegerto Apr 4, 2019
426fed3
Retrive certificate from cloud
pegerto Apr 4, 2019
a794cae
Clean fetch AT
pegerto Apr 5, 2019
cfd5fd4
Merge pull request #14 from opencredo/bug/retrive_certificate
pegerto Apr 5, 2019
fcb2d75
Delete user registration
pegerto Apr 5, 2019
fb229d1
Merge pull request #15 from opencredo/feature/delete_feature_registra…
pegerto Apr 5, 2019
e90cb4b
ZoneConfiguration Test (#16)
pegerto Apr 5, 2019
500442c
At acceptance test for retrieve certificate (#17)
pmack24 Apr 5, 2019
cf18e6a
VCertClient Implementation (#18)
pegerto Apr 8, 2019
aa8ce61
Register should not be tested as it have been removed (#19)
pegerto Apr 8, 2019
057c8ea
Include example in readme (#20)
pegerto Apr 8, 2019
bfe0fd0
TPP certificate renew (#22)
pegerto Apr 8, 2019
9182c2e
Acceptance tests for cloud connector (#21)
pmack24 Apr 8, 2019
d5aba64
Load configuration from file (#23)
pegerto Apr 9, 2019
bec1974
Feature/acceptance tests tpp (#24)
pegerto Apr 10, 2019
50c91ff
Include additional examples (#25)
pegerto May 7, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*


.idea/
*.iml
target/
145 changes: 143 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,143 @@
# vcert-java
Java library and SDK that simplifies integration with Venafi certificate services.
# VCert-Java

<img src="https://www.venafi.com/sites/default/files/content/body/Light_background_logo.png" width="330px" height="69px"/>

VCert is a Java library, SDK, designed to simplify key generation and enrollment of machine identities
(also known as SSL/TLS certificates and keys) that comply with enterprise security policy by using the
[Venafi Platform](https://www.venafi.com/platform/trust-protection-platform) or [Venafi Cloud](https://pki.venafi.com/venafi-cloud/).



## Installation

The current version of this library can be install using

```
mvn install
```


## Usage

A basic example of createing a certificate using the VCert java implementation.

```
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("Public");



// Generate a certificate
CertificateRequest certificateRequest = new CertificateRequest().subject(
new CertificateRequest.PKIXName()
.commonName("opencredo.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, "Default");


// 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("opencredo.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());


```

## Prerequisites for using with Trust Protection Platform

1. A user account that has been granted WebSDK Access
2. A folder (zone) where the user has been granted the following permissions: View, Read, Write, Create, Revoke (for the revoke action), and Private Key Read (for the pickup action when CSR is service generated)
3. Policy applied to the folder which specifies:
1. CA Template that Trust Protection Platform will use to enroll certificate requests submitted by VCert
2. Subject DN values for Organizational Unit (OU), Organization (O), City (L), State (ST) and Country (C)
3. Management Type not locked or locked to 'Enrollment'
4. Certificate Signing Request (CSR) Generation not locked or locked to 'Service Generated CSR'
5. Generate Key/CSR on Application not locked or locked to 'No'
6. (Recommended) Disable Automatic Renewal set to 'Yes'
7. (Recommended) Key Bit Strength set to 2048 or higher
8. (Recommended) Domain Whitelisting policy appropriately assigned

The requirement for the CA Template to be assigned by policy follows a long standing Venafi best practice which also met our design objective to keep the certificate request process simple for VCert users. If you require the abilty to specify the CA Template with the request you can use the TPP REST APIs but please be advised this goes against Venafi recommendations.

## Acceptance Tests

To run the acceptance tests the following environment variables must be set:

| NAME | NOTES |
|------|-------|
| VENAFI_USER | |
| VENAFI_PASSWORD | |
| VENAFI_TPP_URL | Only for TPP connector tests |
| VENAFI_API_KEY | Taken from account after logged in |
| VENAFI_CERT_COMMON_NAME | Used for cert creation, should match configured domains |
| VENAFI_CLOUD_URL | Only for cloud connector tests |
| VENAFI_ZONE | Only for cloud connector tests |

Acceptance test are executed with:
```
mvn "-Dtest=*AT" test
```


## Contributing to VCert

1. Fork it to your account (https://github.com/Venafi/vcert-java/fork)
2. Clone your fork (`git clone git@github.com:youracct/vcert-java.git`)
3. Create a feature branch (`git checkout -b your-branch-name`)
4. Implement and test your changes
5. Commit your changes (`git commit -am 'Added some cool functionality'`)
6. Push to the branch (`git push origin your-branch-name`)
7. Create a new Pull Request (https://github.com/youracct/vcert-java/pull/new/working-branch)


## License

Copyright &copy; Venafi, Inc. All rights reserved.

VCert is licensed under the Apache License, Version 2.0. See `LICENSE` for the full license text.

Please direct questions/comments to opensource@venafi.com.
2 changes: 2 additions & 0 deletions lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
config.stopBubbling = true
lombok.accessors.fluent=true
167 changes: 167 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.venafi.vcert.sdk</groupId>
<artifactId>venafi-vcert-java</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<lombok.version>1.18.6</lombok.version>
<bouncycastle.version>1.61</bouncycastle.version>
<feign.version>10.2.0</feign.version>
<guava.version>23.0</guava.version>
<log4j.version>2.11.2</log4j.version>
<junit.version>5.3.1</junit.version>
<mockito.version>2.25.1</mockito.version>
<wiremock.version>2.22.0</wiremock.version>
<wiremock-extension.version>0.4.0</wiremock-extension.version>
<assertj.version>3.12.2</assertj.version>
<ini4j.version>0.5.4</ini4j.version>
</properties>

<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>${bouncycastle.version}</version>
</dependency>

<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>${bouncycastle.version}</version>
</dependency>

<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-gson</artifactId>
<version>${feign.version}</version>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-slf4j</artifactId>
<version>${feign.version}</version>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8</artifactId>
<version>${wiremock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.JensPiegsa</groupId>
<artifactId>wiremock-extension</artifactId>
<version>${wiremock-extension.version}</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ini4j</groupId>
<artifactId>ini4j</artifactId>
<version>${ini4j.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>test</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

</project>
Loading