use of com.venafi.vcert.sdk.certificate.CertificateRequest in project vcert-java by Venafi.
the class CloudConnectorTest method requestCertificate.
@Test
void requestCertificate() throws VCertException {
Security.addProvider(new BouncyCastleProvider());
String apiKey = "12345678-1234-1234-1234-123456789012";
CertificateIssuingTemplate cit = new CertificateIssuingTemplate();
cit.id("15c7e3f0-ff0a-11e9-a3f0-2b5db8116980");
cit.keyTypes(Arrays.asList(new AllowedKeyType("RSA", Arrays.asList(2048))));
cit.keyReuse(true);
cit.subjectCNRegexes(Arrays.asList("^random name$", "^.*.example.com$", "^.*.example.org$", "^.*.example.net$", "^.*.invalid$", "^.*.local$", "^.*.localhost$", "^.*.test$"));
cit.subjectORegexes(Arrays.asList("^.*$"));
cit.subjectOURegexes(Arrays.asList("^.*$"));
cit.subjectSTRegexes(Arrays.asList());
cit.subjectLRegexes(Arrays.asList());
cit.subjectCValues(Arrays.asList());
cit.sanDnsNameRegexes(Arrays.asList());
Application application = new Application();
application.id("d3d7e270-545b-11eb-a494-893c4e1e4fad");
when(cloud.applicationByName(eq("test_app"), eq(apiKey))).thenReturn(application);
when(cloud.certificateIssuingTemplateByAppNameAndCitAlias(eq("test_app"), eq("test_zone"), eq(apiKey))).thenReturn(cit);
// todo:
when(cloud.certificateRequest(eq(apiKey), any(CloudConnector.CertificateRequestsPayload.class))).thenReturn(new CloudConnector.CertificateRequestsResponse().certificateRequests(singletonList(new CloudConnector.CertificateRequestsResponseData().id("jackpot"))));
CertificateRequest request = new CertificateRequest().subject(new CertificateRequest.PKIXName().commonName("random name").organization(singletonList("Venafi, Inc.")).organizationalUnit(singletonList("Automated Tests")));
final Authentication auth = new Authentication(null, null, apiKey);
classUnderTest.authenticate(auth);
ZoneConfiguration zoneConfig = classUnderTest.readZoneConfiguration("test_app\\test_zone");
classUnderTest.generateRequest(zoneConfig, request);
String actual = classUnderTest.requestCertificate(request, zoneConfig);
assertThat(actual).isEqualTo("jackpot");
}
use of com.venafi.vcert.sdk.certificate.CertificateRequest in project vcert-java by Venafi.
the class CloudConnectorTest method retrieveCertificate.
@Test
void retrieveCertificate() throws VCertException, IOException {
Security.addProvider(new BouncyCastleProvider());
String apiKey = "12345678-1234-1234-1234-123456789012";
final Authentication auth = new Authentication(null, null, apiKey);
classUnderTest.authenticate(auth);
String body = readResourceAsString("certificates/certWithKey.pem");
PEMCollection pemCollection = PEMCollection.fromStringPEMCollection(body, ChainOption.ChainOptionIgnore, null, null);
CertificateRequest request = new CertificateRequest().subject(new CertificateRequest.PKIXName().commonName("random name").organization(singletonList("Venafi, Inc.")).organizationalUnit(singletonList("Automated Tests")));
request.pickupId("jackpot").keyType(KeyType.RSA).keyPair(new KeyPair(pemCollection.certificate().getPublicKey(), pemCollection.privateKey())).keyPassword(KEY_SECRET);
List<String> list = new ArrayList<String>();
list.add("jackpot");
CertificateStatus status = new CertificateStatus().status("ISSUED").certificateIds(list);
CertificateDetails certificateDetails = new CertificateDetails().dekHash("12345");
EdgeEncryptionKey edgeEncryptionKey = new EdgeEncryptionKey();
cloud.certificateDetails(eq("jackpot"), eq(apiKey));
when(cloud.certificateStatus(eq("jackpot"), eq(apiKey))).thenReturn(status);
when(cloud.retrieveCertificate(eq("jackpot"), eq(apiKey), eq("ROOT_FIRST"))).thenReturn(Response.builder().request(Request.create(Request.HttpMethod.GET, "http://localhost", new HashMap<String, Collection<String>>(), null, null)).status(200).body(body, Charset.forName("UTF-8")).build());
when(cloud.certificateDetails(eq("jackpot"), eq(apiKey))).thenReturn(certificateDetails);
when(cloud.retrieveEdgeEncryptionKey(eq("12345"), eq(apiKey))).thenReturn(edgeEncryptionKey);
PEMCollection pemCollection2 = classUnderTest.retrieveCertificate(request);
assertThat(pemCollection2).isNotNull();
assertThat(pemCollection2.certificate()).isNotNull();
assertThat(pemCollection2.privateKey()).isNotNull();
assertThat(pemCollection2.privateKeyPassword()).isEqualTo(KEY_SECRET);
}
use of com.venafi.vcert.sdk.certificate.CertificateRequest in project vcert-java by Venafi.
the class TppConnectorAT method generateRequest.
@Test
void generateRequest() throws VCertException, IOException {
String commonName = TestUtils.randomCN();
ZoneConfiguration zoneConfiguration = connectorResource.connector().readZoneConfiguration(TestUtils.TPP_ZONE);
CertificateRequest certificateRequest = new CertificateRequest().subject(new CertificateRequest.PKIXName().commonName(commonName).organization(Collections.singletonList("Venafi, Inc.")).organizationalUnit(Arrays.asList("Engineering", "Automated Tests")).country(Collections.singletonList("US")).locality(Collections.singletonList("SLC")).province(Collections.singletonList("Utah"))).dnsNames(Collections.singletonList(InetAddress.getLocalHost().getHostName())).ipAddresses(getTestIps()).keyType(KeyType.RSA).keyLength(2048);
certificateRequest = connectorResource.connector().generateRequest(zoneConfiguration, certificateRequest);
assertThat(certificateRequest.csr()).isNotEmpty();
PKCS10CertificationRequest request = (PKCS10CertificationRequest) new PEMParser(new StringReader(new String(certificateRequest.csr()))).readObject();
// Values overridden by policy which is why they don't match the above values
String subject = request.getSubject().toString();
assertThat(subject).contains(format("CN=%s", commonName));
}
use of com.venafi.vcert.sdk.certificate.CertificateRequest in project vcert-java by Venafi.
the class TppConnectorCertAT method revokeCertificate.
@Test
void revokeCertificate() throws VCertException, SocketException, UnknownHostException {
TppConnector connector = connectorResource.connector();
ZoneConfiguration zoneConfiguration = connectorResource.zoneConfiguration();
CertificateRequest certificateRequest = connectorResource.certificateRequest();
certificateRequest = connector.generateRequest(zoneConfiguration, certificateRequest);
String certificateId = connector.requestCertificate(certificateRequest, zoneConfiguration);
assertThat(certificateId).isNotNull();
// just wait for the certificate issuance
connector.retrieveCertificate(certificateRequest);
RevocationRequest revocationRequest = new RevocationRequest();
revocationRequest.reason("key-compromise");
revocationRequest.certificateDN(certificateRequest.pickupId());
connector.revokeCertificate(revocationRequest);
}
use of com.venafi.vcert.sdk.certificate.CertificateRequest in project vcert-java by Venafi.
the class CloudConnectorAT method generateRequest.
@Test
void generateRequest() throws VCertException, IOException {
String commonName = TestUtils.randomCN();
CloudConnector connector = connectorResource.connector();
ZoneConfiguration zoneConfiguration = connector.readZoneConfiguration(TestUtils.CLOUD_ZONE);
CertificateRequest certificateRequest = new CertificateRequest().subject(new CertificateRequest.PKIXName().commonName(commonName).organization(Collections.singletonList("Venafi, Inc.")).organizationalUnit(Arrays.asList("Engineering", "Automated Tests")).country(Collections.singletonList("US")).locality(Collections.singletonList("SLC")).province(Collections.singletonList("Utah"))).dnsNames(Collections.singletonList(InetAddress.getLocalHost().getHostName())).keyType(KeyType.RSA);
certificateRequest = connector.generateRequest(zoneConfiguration, certificateRequest);
assertThat(certificateRequest.csr()).isNotEmpty();
PKCS10CertificationRequest request = (PKCS10CertificationRequest) new PEMParser(new StringReader(Strings.fromByteArray(certificateRequest.csr()))).readObject();
String subject = request.getSubject().toString();
assertThat(subject).contains(String.format("CN=%s", commonName));
assertThat(subject).contains("O=Venafi\\, Inc.");
assertThat(subject).contains("OU=Engineering");
assertThat(subject).contains("OU=Automated Tests");
assertThat(subject).contains("C=US");
assertThat(subject).contains("L=SLC");
assertThat(subject).contains("ST=Utah");
}
Aggregations