|
1 | | -# vcert-java |
2 | | -Java library and SDK that simplifies integration with Venafi certificate services. |
| 1 | +# VCert-Java |
| 2 | + |
| 3 | +<img src="https://www.venafi.com/sites/default/files/content/body/Light_background_logo.png" width="330px" height="69px"/> |
| 4 | + |
| 5 | +VCert is a Java library, SDK, designed to simplify key generation and enrollment of machine identities |
| 6 | +(also known as SSL/TLS certificates and keys) that comply with enterprise security policy by using the |
| 7 | +[Venafi Platform](https://www.venafi.com/platform/trust-protection-platform) or [Venafi Cloud](https://pki.venafi.com/venafi-cloud/). |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +The current version of this library can be install using |
| 14 | + |
| 15 | +``` |
| 16 | +mvn install |
| 17 | +``` |
| 18 | + |
| 19 | + |
| 20 | +## Usage |
| 21 | + |
| 22 | +A basic example of createing a certificate using the VCert java implementation. |
| 23 | + |
| 24 | +``` |
| 25 | + final Config config = Config.builder() |
| 26 | + .connectorType(ConnectorType.CLOUD) |
| 27 | + .zone("Default") |
| 28 | + .build(); |
| 29 | +
|
| 30 | + final VCertClient client = new VCertClient(config); |
| 31 | + final Authentication auth = Authentication.builder() |
| 32 | + .apiKey("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") |
| 33 | + .build(); |
| 34 | +
|
| 35 | + client.authenticate(auth); |
| 36 | + final ZoneConfiguration zoneConfiguration = client.readZoneConfiguration("Public"); |
| 37 | +
|
| 38 | +
|
| 39 | +
|
| 40 | + // Generate a certificate |
| 41 | + CertificateRequest certificateRequest = new CertificateRequest().subject( |
| 42 | + new CertificateRequest.PKIXName() |
| 43 | + .commonName("opencredo.test") |
| 44 | + .organization(Collections.singletonList("Venafi, Inc.")) |
| 45 | + .organizationalUnit(Arrays.asList("Engineering")) |
| 46 | + .country(Collections.singletonList("US")) |
| 47 | + .locality(Collections.singletonList("SLC")) |
| 48 | + .province(Collections.singletonList("Utah"))) |
| 49 | +
|
| 50 | + .keyType(KeyType.RSA); |
| 51 | + certificateRequest = client.generateRequest(zoneConfiguration, certificateRequest); |
| 52 | +
|
| 53 | +
|
| 54 | + // Submit the certificate request |
| 55 | + String newCertId = client.requestCertificate(certificateRequest, "Default"); |
| 56 | +
|
| 57 | +
|
| 58 | + // Retrieve PEM collection from Venafi |
| 59 | + final CertificateRequest pickupRequest = new CertificateRequest().pickupId(newCertId); |
| 60 | + PEMCollection pemCollection = client.retrieveCertificate(pickupRequest); |
| 61 | + System.out.println(pemCollection.certificate()); |
| 62 | +
|
| 63 | + // Renew the certificate |
| 64 | + X509Certificate cert = (X509Certificate) pemCollection.certificate(); |
| 65 | + String thumbprint = DigestUtils.sha1Hex(cert.getEncoded()).toUpperCase(); |
| 66 | + final CertificateRequest certificateRequestToRenew = new CertificateRequest().subject( |
| 67 | + new CertificateRequest.PKIXName() |
| 68 | + .commonName("opencredo.test") |
| 69 | + .organization(Collections.singletonList("Venafi, Inc.")) |
| 70 | + .organizationalUnit(Arrays.asList("Engineering")) |
| 71 | + .country(Collections.singletonList("US")) |
| 72 | + .locality(Collections.singletonList("SLC")) |
| 73 | + .province(Collections.singletonList("Utah"))); |
| 74 | +
|
| 75 | + client.generateRequest(zoneConfiguration, certificateRequestToRenew); |
| 76 | +
|
| 77 | + final RenewalRequest renewalRequest = new RenewalRequest() |
| 78 | + .thumbprint(thumbprint) |
| 79 | + .request(certificateRequestToRenew); |
| 80 | + final String renewedCertificate = client.renewCertificate(renewalRequest); |
| 81 | +
|
| 82 | + // Retrieve PEM collection from Venafi |
| 83 | + final CertificateRequest renewPickupRequest = new CertificateRequest().pickupId(renewedCertificate); |
| 84 | + PEMCollection pemCollectionRenewed = client.retrieveCertificate(pickupRequest); |
| 85 | + System.out.println(pemCollectionRenewed.certificate()); |
| 86 | +
|
| 87 | +
|
| 88 | +``` |
| 89 | + |
| 90 | +## Prerequisites for using with Trust Protection Platform |
| 91 | + |
| 92 | +1. A user account that has been granted WebSDK Access |
| 93 | +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) |
| 94 | +3. Policy applied to the folder which specifies: |
| 95 | + 1. CA Template that Trust Protection Platform will use to enroll certificate requests submitted by VCert |
| 96 | + 2. Subject DN values for Organizational Unit (OU), Organization (O), City (L), State (ST) and Country (C) |
| 97 | + 3. Management Type not locked or locked to 'Enrollment' |
| 98 | + 4. Certificate Signing Request (CSR) Generation not locked or locked to 'Service Generated CSR' |
| 99 | + 5. Generate Key/CSR on Application not locked or locked to 'No' |
| 100 | + 6. (Recommended) Disable Automatic Renewal set to 'Yes' |
| 101 | + 7. (Recommended) Key Bit Strength set to 2048 or higher |
| 102 | + 8. (Recommended) Domain Whitelisting policy appropriately assigned |
| 103 | + |
| 104 | +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. |
| 105 | + |
| 106 | +## Acceptance Tests |
| 107 | + |
| 108 | +To run the acceptance tests the following environment variables must be set: |
| 109 | + |
| 110 | +| NAME | NOTES | |
| 111 | +|------|-------| |
| 112 | +| VENAFI_USER | | |
| 113 | +| VENAFI_PASSWORD | | |
| 114 | +| VENAFI_TPP_URL | Only for TPP connector tests | |
| 115 | +| VENAFI_API_KEY | Taken from account after logged in | |
| 116 | +| VENAFI_CERT_COMMON_NAME | Used for cert creation, should match configured domains | |
| 117 | +| VENAFI_CLOUD_URL | Only for cloud connector tests | |
| 118 | +| VENAFI_ZONE | Only for cloud connector tests | |
| 119 | + |
| 120 | +Acceptance test are executed with: |
| 121 | +``` |
| 122 | +mvn "-Dtest=*AT" test |
| 123 | +``` |
| 124 | + |
| 125 | + |
| 126 | +## Contributing to VCert |
| 127 | + |
| 128 | +1. Fork it to your account (https://github.com/Venafi/vcert-java/fork) |
| 129 | +2. Clone your fork (`git clone git@github.com:youracct/vcert-java.git`) |
| 130 | +3. Create a feature branch (`git checkout -b your-branch-name`) |
| 131 | +4. Implement and test your changes |
| 132 | +5. Commit your changes (`git commit -am 'Added some cool functionality'`) |
| 133 | +6. Push to the branch (`git push origin your-branch-name`) |
| 134 | +7. Create a new Pull Request (https://github.com/youracct/vcert-java/pull/new/working-branch) |
| 135 | + |
| 136 | + |
| 137 | +## License |
| 138 | + |
| 139 | +Copyright © Venafi, Inc. All rights reserved. |
| 140 | + |
| 141 | +VCert is licensed under the Apache License, Version 2.0. See `LICENSE` for the full license text. |
| 142 | + |
| 143 | +Please direct questions/comments to opensource@venafi.com. |
0 commit comments