Search in sources :

Example 26 with ZoneConfiguration

use of com.venafi.vcert.sdk.connectors.ZoneConfiguration in project vcert-java by Venafi.

the class TppTokenConnectorCertAT method requestCertificate.

@Test
void requestCertificate() throws VCertException, SocketException, UnknownHostException {
    TppTokenConnector connector = connectorResource.connector();
    ZoneConfiguration zoneConfiguration = connectorResource.zoneConfiguration();
    CertificateRequest certificateRequest = connector.generateRequest(zoneConfiguration, connectorResource.certificateRequest());
    CertificateRequest csrRequestOnly = new CertificateRequest().csr(certificateRequest.csr());
    assertThat(connector.requestCertificate(csrRequestOnly, zoneConfiguration)).isNotNull();
}
Also used : ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest) Test(org.junit.jupiter.api.Test)

Example 27 with ZoneConfiguration

use of com.venafi.vcert.sdk.connectors.ZoneConfiguration in project vcert-java by Venafi.

the class TppTokenConnectorIT method readZoneConfiguration.

@Test
void readZoneConfiguration() throws VCertException {
    ZoneConfiguration zoneConfiguration = classUnderTest.readZoneConfiguration("tag");
    assertThat(zoneConfiguration).isNotNull();
    assertThat(zoneConfiguration.organization()).isNull();
    assertThat(zoneConfiguration.organizationalUnit()).isNotNull();
    assertThat(zoneConfiguration.organizationalUnit()).isEmpty();
    assertThat(zoneConfiguration.country()).isNull();
    assertThat(zoneConfiguration.province()).isNull();
    assertThat(zoneConfiguration.locality()).isNull();
    assertThat(zoneConfiguration.policy()).isNotNull();
    assertThat(zoneConfiguration.policy().subjectCNRegexes()).containsExactly(".*");
    assertThat(zoneConfiguration.policy().subjectORegexes()).containsExactly(".*");
    assertThat(zoneConfiguration.policy().subjectOURegexes()).containsExactly(".*");
    assertThat(zoneConfiguration.policy().subjectSTRegexes()).containsExactly(".*");
    assertThat(zoneConfiguration.policy().subjectLRegexes()).containsExactly(".*");
    assertThat(zoneConfiguration.policy().subjectCRegexes()).containsExactly(".*");
    assertThat(zoneConfiguration.policy().allowedKeyConfigurations()).isNotNull();
    assertThat(zoneConfiguration.policy().allowedKeyConfigurations()).hasSize(2);
    assertThat(zoneConfiguration.policy().allowedKeyConfigurations().get(0).keyType()).isEqualTo(RSA);
    assertThat(zoneConfiguration.policy().allowedKeyConfigurations().get(0).keySizes()).containsExactly(512, 1024, 2048, 4096, 8192);
    assertThat(zoneConfiguration.policy().allowedKeyConfigurations().get(0).keyCurves()).isNull();
    assertThat(zoneConfiguration.policy().allowedKeyConfigurations().get(1).keyType()).isEqualTo(ECDSA);
    assertThat(zoneConfiguration.policy().allowedKeyConfigurations().get(1).keySizes()).isNull();
    assertThat(zoneConfiguration.policy().allowedKeyConfigurations().get(1).keyCurves()).containsExactly(EllipticCurveP224, EllipticCurveP256, EllipticCurveP384, EllipticCurveP521);
    assertThat(zoneConfiguration.policy().dnsSanRegExs()).containsExactly(".*");
    assertThat(zoneConfiguration.policy().ipSanRegExs()).containsExactly(".*");
    assertThat(zoneConfiguration.policy().emailSanRegExs()).containsExactly(".*");
    assertThat(zoneConfiguration.policy().uriSanRegExs()).containsExactly(".*");
    assertThat(zoneConfiguration.policy().upnSanRegExs()).containsExactly(".*");
    assertThat(zoneConfiguration.policy().allowWildcards()).isTrue();
    assertThat(zoneConfiguration.policy().allowKeyReuse()).isFalse();
    assertThat(zoneConfiguration.hashAlgorithm()).isEqualTo(SHA256WithRSA);
    assertThat(zoneConfiguration.customAttributeValues()).isNotNull();
    assertThat(zoneConfiguration.customAttributeValues()).isEmpty();
}
Also used : ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) Test(org.junit.jupiter.api.Test)

Example 28 with ZoneConfiguration

use of com.venafi.vcert.sdk.connectors.ZoneConfiguration in project vcert-java by Venafi.

the class TppTokenConnectorTest method requestCertificate.

@Test
@DisplayName("Request a certificate from TPP")
void requestCertificate() throws VCertException {
    Security.addProvider(new BouncyCastleProvider());
    TppTokenConnector.ReadZoneConfigurationRequest expectedRZCRequest = new TppTokenConnector.ReadZoneConfigurationRequest("\\VED\\Policy\\myZone");
    when(tpp.readZoneConfigurationToken(eq(expectedRZCRequest), eq(HEADER_AUTHORIZATION))).thenReturn(new TppTokenConnector.ReadZoneConfigurationResponse().policy(new ServerPolicy().subject(new ServerPolicy.Subject().organizationalUnit(new LockableValues<String>(false, Collections.singletonList("OU"))).state(new LockableValue<>(false, "state")).city(new LockableValue<>(false, "city")).country(new LockableValue<>(false, "country")).organization(new LockableValue<>(false, "organization"))).keyPair(new ServerPolicy.KeyPair(new LockableValue<>(false, "keyAlgo"), new LockableValue<>(false, 1024), null))));
    when(tpp.requestCertificateToken(any(TppTokenConnector.CertificateRequestsPayload.class), eq(HEADER_AUTHORIZATION))).thenReturn(new Tpp.CertificateRequestResponse().certificateDN("reqId"));
    String zoneTag = "myZone";
    ZoneConfiguration zoneConfig = classUnderTest.readZoneConfiguration(classUnderTest.getPolicyDN(zoneTag));
    String cn = String.format("t%d-%s.venafi.xample.com", Instant.now().getEpochSecond(), RandomStringUtils.randomAlphabetic(4).toLowerCase());
    CertificateRequest request = new CertificateRequest().subject(new CertificateRequest.PKIXName().commonName(cn).organization(Collections.singletonList("Venafi, Inc.")).organizationalUnit(Collections.singletonList("Automated Tests")).locality(Collections.singletonList("Las Vegas")).province(Collections.singletonList("Nevada")).country(Collections.singletonList("US"))).friendlyName(cn).keyLength(512);
    classUnderTest.generateRequest(zoneConfig, request);
    logger.info("getPolicyDN(ZoneTag) = %s", classUnderTest.getPolicyDN(zoneTag));
    ZoneConfiguration zoneConfiguration = new ZoneConfiguration();
    zoneConfiguration.zoneId(classUnderTest.getPolicyDN(zoneTag));
    String requestId = classUnderTest.requestCertificate(request, zoneConfiguration);
    assertEquals("reqId", requestId);
}
Also used : ServerPolicy(com.venafi.vcert.sdk.connectors.ServerPolicy) ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) LockableValue(com.venafi.vcert.sdk.connectors.LockableValue) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 29 with ZoneConfiguration

use of com.venafi.vcert.sdk.connectors.ZoneConfiguration in project vcert-java by Venafi.

the class TppConnectorCertAT method requestCertificate.

@Test
void requestCertificate() throws VCertException, SocketException, UnknownHostException {
    TppConnector connector = connectorResource.connector();
    ZoneConfiguration zoneConfiguration = connectorResource.zoneConfiguration();
    CertificateRequest certificateRequest = connectorResource.certificateRequest();
    certificateRequest = connector.generateRequest(zoneConfiguration, certificateRequest);
    CertificateRequest csrRequestOnly = new CertificateRequest().csr(certificateRequest.csr());
    assertThat(connector.requestCertificate(csrRequestOnly, zoneConfiguration)).isNotNull();
}
Also used : ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest) Test(org.junit.jupiter.api.Test)

Example 30 with ZoneConfiguration

use of com.venafi.vcert.sdk.connectors.ZoneConfiguration in project vcert-java by Venafi.

the class TppConnectorCertAT method createCertificateValidateValidityHours.

@Test
@DisplayName("Create a cerfiticate and validate specified validity hours - TPP")
void createCertificateValidateValidityHours() throws UnknownHostException, VCertException {
    TppConnector connector = connectorResource.connector();
    ZoneConfiguration zoneConfiguration = connectorResource.zoneConfiguration();
    CertificateRequest cr = connectorResource.certificateRequest().validityHours(TestUtils.VALID_HOURS).issuerHint("MICROSOFT");
    cr = connector.generateRequest(zoneConfiguration, cr);
    // Submit the certificate request
    connector.requestCertificate(cr, zoneConfiguration);
    // Retrieve PEM collection from Venafi
    PEMCollection pemCollection = connector.retrieveCertificate(cr);
    Date notAfter = pemCollection.certificate().getNotAfter();
    LocalDate notAfterDate = notAfter.toInstant().atOffset(ZoneOffset.UTC).toLocalDate();
    Instant now = Instant.now();
    LocalDateTime utcDateTime = LocalDateTime.ofInstant(now, ZoneOffset.UTC);
    int validityDays = VCertUtils.getValidityDays(TestUtils.VALID_HOURS);
    utcDateTime = utcDateTime.plusDays(validityDays);
    LocalDate nowDateInUTC = utcDateTime.toLocalDate();
    // Dates should be equals if not then it will fail
    assertTrue(notAfterDate.compareTo(nowDateInUTC) == 0);
}
Also used : LocalDateTime(java.time.LocalDateTime) PEMCollection(com.venafi.vcert.sdk.certificate.PEMCollection) Instant(java.time.Instant) ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest) LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

ZoneConfiguration (com.venafi.vcert.sdk.connectors.ZoneConfiguration)50 CertificateRequest (com.venafi.vcert.sdk.certificate.CertificateRequest)42 Test (org.junit.jupiter.api.Test)42 DisplayName (org.junit.jupiter.api.DisplayName)20 PEMCollection (com.venafi.vcert.sdk.certificate.PEMCollection)17 RenewalRequest (com.venafi.vcert.sdk.certificate.RenewalRequest)7 StringReader (java.io.StringReader)7 X509Certificate (java.security.cert.X509Certificate)7 RevocationRequest (com.venafi.vcert.sdk.certificate.RevocationRequest)5 Authentication (com.venafi.vcert.sdk.endpoint.Authentication)5 PEMParser (org.bouncycastle.openssl.PEMParser)4 PKCS10CertificationRequest (org.bouncycastle.pkcs.PKCS10CertificationRequest)4 Config (com.venafi.vcert.sdk.Config)3 TestUtils (com.venafi.vcert.sdk.TestUtils)3 VCertException (com.venafi.vcert.sdk.VCertException)3 CsrOriginOption (com.venafi.vcert.sdk.certificate.CsrOriginOption)3 DataFormat (com.venafi.vcert.sdk.certificate.DataFormat)3 ServerPolicy (com.venafi.vcert.sdk.connectors.ServerPolicy)3 FeignException (feign.FeignException)3 IOException (java.io.IOException)3