Search in sources :

Example 46 with ZoneConfiguration

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

the class CloudConnectorCertAT method requestCertificateUnrestricted.

@Test
void requestCertificateUnrestricted() throws VCertException, UnknownHostException {
    CloudConnector connector = connectorResource.connector();
    ZoneConfiguration zoneConfiguration = connectorResource.zoneConfiguration();
    CertificateRequest certificateRequest = connectorResource.certificateRequest().keyType(KeyType.RSA).keyLength(2048);
    certificateRequest = connector.generateRequest(zoneConfiguration, certificateRequest);
    String certificateId = connector.requestCertificate(certificateRequest, zoneConfiguration);
    assertThat(certificateId).isNotNull();
}
Also used : ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest) Test(org.junit.jupiter.api.Test)

Example 47 with ZoneConfiguration

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

the class ZoneConfigurationTest method validateCertificateRequest.

@Test
@DisplayName("Validate a policy match")
void validateCertificateRequest() throws VCertException {
    final ZoneConfiguration zoneConfiguration = getBaseZoneConfiguration();
    zoneConfiguration.validateCertificateRequest(getDefaultCertificateRequest());
}
Also used : ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 48 with ZoneConfiguration

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

the class ZoneConfigurationTest method invalidCNMatch.

@Test
@DisplayName("Expect CN not to match with a termination")
void invalidCNMatch() throws VCertException {
    final ZoneConfiguration zoneConfiguration = getBaseZoneConfiguration();
    final CertificateRequest certificateRequest = getDefaultCertificateRequest();
    certificateRequest.subject().commonName("vcert.text.vfidev.com.example");
    final Throwable exception = assertThrows(VCertException.class, () -> zoneConfiguration.validateCertificateRequest(certificateRequest));
    assertThat(exception.getMessage()).contains("CN does not match any of the allowed CN");
}
Also used : ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 49 with ZoneConfiguration

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

the class TppClient method main.

public static void main(String[] args) throws VCertException, CertificateEncodingException, NoSuchAlgorithmException, KeyManagementException {
    String url = System.getenv("TPPURL");
    String zone = System.getenv("TPPZONE");
    String appInfo = System.getenv("PRODUCT");
    String tpp_user = System.getenv("TPPUSER");
    String tpp_passwd = System.getenv("TPPPASSWORD");
    if (tpp_user == null)
        tpp_user = "local:admin";
    if (tpp_passwd == null)
        tpp_passwd = "password";
    if (url == null)
        url = "https://tpp.venafi.example/vedsdk";
    if (zone == null)
        zone = "Certificates\\vcert\\";
    if (appInfo == null)
        appInfo = "CompanyName AppName";
    // Configuration
    Config config = Config.builder().connectorType(ConnectorType.TPP).baseUrl(url).appInfo(appInfo).build();
    Authentication auth = Authentication.builder().user(tpp_user).password(tpp_passwd).build();
    VCertClient client = new VCertClient(config);
    client.authenticate(auth);
    ZoneConfiguration zoneConfiguration = client.readZoneConfiguration(zone);
    // Generate a certificate
    CertificateRequest certificateRequest = new CertificateRequest().subject(new CertificateRequest.PKIXName().commonName("vcert-java.venafi.example").organization(Collections.singletonList("Venafi, Inc.")).organizationalUnit(Arrays.asList("Product Management")).country(Collections.singletonList("US")).locality(Collections.singletonList("Salt Lake City")).province(Collections.singletonList("Utah"))).keyType(KeyType.RSA).keyLength(2048);
    certificateRequest = client.generateRequest(zoneConfiguration, certificateRequest);
    // Submit the certificate request
    client.requestCertificate(certificateRequest, zoneConfiguration);
    // Retrieve PEM collection from Venafi
    PEMCollection pemCollection = client.retrieveCertificate(certificateRequest);
    System.out.println(pemCollection.certificate());
}
Also used : PEMCollection(com.venafi.vcert.sdk.certificate.PEMCollection) Config(com.venafi.vcert.sdk.Config) Authentication(com.venafi.vcert.sdk.endpoint.Authentication) VCertClient(com.venafi.vcert.sdk.VCertClient) ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest)

Example 50 with ZoneConfiguration

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

the class TppTokenClient method main.

public static void main(String[] args) throws VCertException, CertificateEncodingException, NoSuchAlgorithmException, KeyManagementException {
    String url = System.getenv("TPP_TOKEN_URL");
    String zone = System.getenv("TPPZONE");
    String appInfo = System.getenv("PRODUCT");
    String tpp_user = System.getenv("TPPUSER");
    String tpp_passwd = System.getenv("TPPPASSWORD");
    if (tpp_user == null)
        tpp_user = "local:admin";
    if (tpp_passwd == null)
        tpp_passwd = "password";
    if (url == null)
        url = "https://tpp.venafi.example/vedsdk";
    if (zone == null)
        zone = "Certificates\\vcert\\";
    if (appInfo == null)
        appInfo = "CompanyName AppName";
    // Configuration
    Config config = Config.builder().connectorType(ConnectorType.TPP_TOKEN).baseUrl(url).appInfo(appInfo).build();
    Authentication auth = Authentication.builder().user(tpp_user).password(tpp_passwd).build();
    VCertTknClient client = new VCertTknClient(config);
    TokenInfo tknInfo = client.getAccessToken(auth);
    ZoneConfiguration zoneConfiguration = client.readZoneConfiguration(zone);
    // Generate a certificate
    CertificateRequest certificateRequest = new CertificateRequest().subject(new CertificateRequest.PKIXName().commonName("vcert-java.venafi.example").organization(Collections.singletonList("Venafi, Inc.")).organizationalUnit(Arrays.asList("Product Management")).country(Collections.singletonList("US")).locality(Collections.singletonList("Salt Lake City")).province(Collections.singletonList("Utah"))).keyType(KeyType.RSA).keyLength(2048);
    certificateRequest = client.generateRequest(zoneConfiguration, certificateRequest);
    // Submit the certificate request
    client.requestCertificate(certificateRequest, zoneConfiguration);
    // Retrieve PEM collection from Venafi
    PEMCollection pemCollection = client.retrieveCertificate(certificateRequest);
    System.out.println(pemCollection.certificate());
}
Also used : VCertTknClient(com.venafi.vcert.sdk.VCertTknClient) PEMCollection(com.venafi.vcert.sdk.certificate.PEMCollection) Config(com.venafi.vcert.sdk.Config) Authentication(com.venafi.vcert.sdk.endpoint.Authentication) ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest) TokenInfo(com.venafi.vcert.sdk.connectors.tpp.TokenInfo)

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