Search in sources :

Example 51 with CertificateRequest

use of com.venafi.vcert.sdk.certificate.CertificateRequest in project vcert-java by Venafi.

the class ZoneConfigurationTest method getDefaultCertificateRequest.

private CertificateRequest getDefaultCertificateRequest() {
    getBaseZoneConfiguration();
    final CertificateRequest request = new CertificateRequest();
    final CertificateRequest.PKIXName subject = new CertificateRequest.PKIXName();
    subject.commonName("vcert.text.vfidev.com");
    subject.organization(singletonList("Venafi, Inc."));
    subject.organizationalUnit(Arrays.asList("Engineering"));
    subject.locality(singletonList("Las Vegas"));
    subject.province(singletonList("Nevada"));
    subject.country(singletonList("US"));
    request.subject(subject);
    request.dnsNames(emptyList());
    request.keyType(KeyType.defaultKeyType());
    return request;
}
Also used : CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest)

Example 52 with CertificateRequest

use of com.venafi.vcert.sdk.certificate.CertificateRequest 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 53 with CertificateRequest

use of com.venafi.vcert.sdk.certificate.CertificateRequest 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

CertificateRequest (com.venafi.vcert.sdk.certificate.CertificateRequest)53 Test (org.junit.jupiter.api.Test)44 ZoneConfiguration (com.venafi.vcert.sdk.connectors.ZoneConfiguration)43 DisplayName (org.junit.jupiter.api.DisplayName)24 PEMCollection (com.venafi.vcert.sdk.certificate.PEMCollection)20 RenewalRequest (com.venafi.vcert.sdk.certificate.RenewalRequest)9 Authentication (com.venafi.vcert.sdk.endpoint.Authentication)8 StringReader (java.io.StringReader)8 FeignException (feign.FeignException)7 X509Certificate (java.security.cert.X509Certificate)7 RevocationRequest (com.venafi.vcert.sdk.certificate.RevocationRequest)6 VCertException (com.venafi.vcert.sdk.VCertException)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 PEMParser (org.bouncycastle.openssl.PEMParser)5 CsrOriginOption (com.venafi.vcert.sdk.certificate.CsrOriginOption)4 DataFormat (com.venafi.vcert.sdk.certificate.DataFormat)4 Instant (java.time.Instant)4 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)4 PKCS10CertificationRequest (org.bouncycastle.pkcs.PKCS10CertificationRequest)4