Search in sources :

Example 26 with VCertException

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

the class TppTokenConnectorTest method testExceptionValidatingPolicyKeySizesHasMoreThanOneValue.

@Test
@DisplayName("TPP - Testing Exception in Validation of Policy KeySizes that has more than one value")
public void testExceptionValidatingPolicyKeySizesHasMoreThanOneValue() throws VCertException {
    PolicySpecification policySpecification = TppTestUtils.getPolicySpecification();
    // setting the keysizes to a list of values which contains
    // more than on value to validate that the related VCertException is thrown
    policySpecification.policy().keyPair().rsaKeySizes(new Integer[] { 1024, 3072 });
    Exception exception = assertThrows(VCertException.class, () -> classUnderTest.setPolicy(TppTestUtils.getRandomZone(), policySpecification));
    Assertions.assertEquals(TppTestUtils.getVCertExceptionMessage(TPPPolicySpecificationValidator.ATTRIBUTE_HAS_MORE_THAN_ONE_VALUE_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_POLICY_KEYPAIR_RSA_KEY_SIZES), exception.getMessage());
}
Also used : PolicySpecification(com.venafi.vcert.sdk.policy.domain.PolicySpecification) CertificateDNOrThumbprintWasNotProvidedException(com.venafi.vcert.sdk.connectors.ConnectorException.CertificateDNOrThumbprintWasNotProvidedException) MoreThanOneCertificateWithSameThumbprintException(com.venafi.vcert.sdk.connectors.ConnectorException.MoreThanOneCertificateWithSameThumbprintException) CertificateNotFoundByThumbprintException(com.venafi.vcert.sdk.connectors.ConnectorException.CertificateNotFoundByThumbprintException) FeignException(feign.FeignException) VCertException(com.venafi.vcert.sdk.VCertException) FailedToRevokeTokenException(com.venafi.vcert.sdk.connectors.ConnectorException.FailedToRevokeTokenException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 27 with VCertException

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

the class TppTokenConnectorTest method testExceptionValidatingPolicyECHasMoreThanOneValue.

@Test
@DisplayName("TPP - Testing Exception in Validation of Policy EC that has more than one value")
public void testExceptionValidatingPolicyECHasMoreThanOneValue() throws VCertException {
    PolicySpecification policySpecification = TppTestUtils.getPolicySpecification();
    // setting the EC to a list of values which contains
    // more than on value to validate that the related VCertException is thrown
    policySpecification.policy().keyPair().ellipticCurves(new String[] { "P256", "P384" });
    Exception exception = assertThrows(VCertException.class, () -> classUnderTest.setPolicy(TppTestUtils.getRandomZone(), policySpecification));
    Assertions.assertEquals(TppTestUtils.getVCertExceptionMessage(TPPPolicySpecificationValidator.ATTRIBUTE_HAS_MORE_THAN_ONE_VALUE_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_POLICY_KEYPAIR_ELLIPTIC_CURVES), exception.getMessage());
}
Also used : PolicySpecification(com.venafi.vcert.sdk.policy.domain.PolicySpecification) CertificateDNOrThumbprintWasNotProvidedException(com.venafi.vcert.sdk.connectors.ConnectorException.CertificateDNOrThumbprintWasNotProvidedException) MoreThanOneCertificateWithSameThumbprintException(com.venafi.vcert.sdk.connectors.ConnectorException.MoreThanOneCertificateWithSameThumbprintException) CertificateNotFoundByThumbprintException(com.venafi.vcert.sdk.connectors.ConnectorException.CertificateNotFoundByThumbprintException) FeignException(feign.FeignException) VCertException(com.venafi.vcert.sdk.VCertException) FailedToRevokeTokenException(com.venafi.vcert.sdk.connectors.ConnectorException.FailedToRevokeTokenException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 28 with VCertException

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

the class TppTokenConnectorTest method testExceptionValidatingPolicyStates.

@Test
@DisplayName("TPP - Testing Exception in Validation of Policy States with more than one value")
public void testExceptionValidatingPolicyStates() throws VCertException {
    PolicySpecification policySpecification = TppTestUtils.getPolicySpecification();
    // setting the states to a list of more than 1 values
    // to validate that the related VCertException is thrown
    policySpecification.policy().subject().states(new String[] { "State1", "State2" });
    Exception exception = assertThrows(VCertException.class, () -> classUnderTest.setPolicy(TppTestUtils.getRandomZone(), policySpecification));
    Assertions.assertEquals(TppTestUtils.getVCertExceptionMessage(TPPPolicySpecificationValidator.ATTRIBUTE_HAS_MORE_THAN_ONE_VALUE_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_POLICY_SUBJECT_STATES), exception.getMessage());
}
Also used : PolicySpecification(com.venafi.vcert.sdk.policy.domain.PolicySpecification) CertificateDNOrThumbprintWasNotProvidedException(com.venafi.vcert.sdk.connectors.ConnectorException.CertificateDNOrThumbprintWasNotProvidedException) MoreThanOneCertificateWithSameThumbprintException(com.venafi.vcert.sdk.connectors.ConnectorException.MoreThanOneCertificateWithSameThumbprintException) CertificateNotFoundByThumbprintException(com.venafi.vcert.sdk.connectors.ConnectorException.CertificateNotFoundByThumbprintException) FeignException(feign.FeignException) VCertException(com.venafi.vcert.sdk.VCertException) FailedToRevokeTokenException(com.venafi.vcert.sdk.connectors.ConnectorException.FailedToRevokeTokenException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 29 with VCertException

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

the class CloudConnectorUtils method setCit.

public static void setCit(String policyName, CertificateIssuingTemplate cit, CloudPolicy.CAInfo caInfo, String apiKey, Cloud cloud) throws VCertException {
    CloudZone cloudZone = new CloudZone(policyName);
    cit.name(cloudZone.citAlias());
    // getting the CAProductOptionId
    CAAccountInfo caAccountInfo = CloudConnectorUtils.getCAAccountInfo(caInfo, apiKey, cloud);
    String caProductOptionId = caAccountInfo.productId;
    if (caProductOptionId == null)
        throw new VCertException("Specified CA doesn't exist");
    // Setting the CAProductOptionId to the parsed cit
    cit.certificateAuthorityProductOptionId(caProductOptionId);
    // setting the OrganizationId if the CA is DIGICERT
    if (caInfo.caType().equals(CloudConstants.DIGICERT_TYPE))
        if (caAccountInfo.organizationId != null)
            cit.product().organizationId(caAccountInfo.organizationId);
        else
            throw new VCertException("It was not possible to determine the Organization Id from the DIGICERT Product.");
    // Getting the cit from the server
    CertificateIssuingTemplate citFromServer = CloudConnectorUtils.getCIT(cit.name(), apiKey, cloud);
    // if cit already exists
    if (citFromServer != null) {
        // update it
        // the citId can't put directly in the cit because it is not part of the format of the body request that the endpoint is waiting
        cloud.updateCIT(cit, citFromServer.id(), apiKey);
        cit.id(citFromServer.id());
    } else {
        // create it
        // setting the citId resulting of the creation of the cit
        cit.id(createCIT(cit, apiKey, cloud));
    }
    setCitToApp(policyName, cit, apiKey, cloud);
}
Also used : VCertException(com.venafi.vcert.sdk.VCertException) CertificateIssuingTemplate(com.venafi.vcert.sdk.connectors.cloud.domain.CertificateIssuingTemplate) CloudZone(com.venafi.vcert.sdk.connectors.cloud.domain.CloudZone)

Example 30 with VCertException

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

the class CloudConnectorUtils method buildCsrAttributes.

public static CsrAttributes buildCsrAttributes(CertificateRequest request, PolicySpecification policySpecification) throws VCertException {
    CsrAttributes csrAttributes = new CsrAttributes();
    // computing the commonName
    String reqCN = request.subject() != null && isNotBlank(request.subject().commonName()) ? request.subject().commonName() : null;
    if (reqCN != null) {
        // validating that the request.subject.cn matches with the policy domains
        String[] policyDomains = Optional.ofNullable(policySpecification).map(ps -> ps.policy()).map(p -> p.domains()).orElse(null);
        if (policyDomains != null && !matchRegexes(reqCN, policyDomains))
            throw new PolicyMatchException("CN", reqCN, "domains", policyDomains);
        csrAttributes.commonName(reqCN);
    }
    // computing the organization
    List<String> reqOrganizations = Optional.ofNullable(request).map(req -> req.subject()).map(s -> s.organization()).orElse(null);
    if (reqOrganizations != null && reqOrganizations.size() > 0) {
        String[] reqOrgsArray = reqOrganizations.toArray(new String[0]);
        // validating that the req.subject.organization matches with the policy orgs
        String[] policyOrgs = Optional.ofNullable(policySpecification).map(ps -> ps.policy()).map(p -> p.subject()).map(s -> s.orgs()).orElse(null);
        if (policyOrgs != null && !matchRegexes(reqOrgsArray, policyOrgs))
            throw new PolicyMatchException("organization", reqOrgsArray, "organization", policyOrgs);
        csrAttributes.organization(reqOrgsArray[0]);
    } else {
        String defaultOrg = Optional.ofNullable(policySpecification).map(ps -> ps.defaults()).map(d -> d.subject()).map(s -> s.org()).orElse(null);
        if (isNotBlank(defaultOrg))
            csrAttributes.organization(defaultOrg);
    }
    // computing the organizational Units
    List<String> reqOrgUnits = Optional.ofNullable(request).map(req -> req.subject()).map(s -> s.organizationalUnit()).orElse(null);
    if (reqOrgUnits != null && reqOrgUnits.size() > 0) {
        String[] reqOrgUnitsArray = reqOrgUnits.toArray(new String[0]);
        // validating that the req.subject.organizationalUnit matches with the policy orgUnits
        String[] policyOrgUnits = Optional.ofNullable(policySpecification).map(ps -> ps.policy()).map(p -> p.subject()).map(s -> s.orgUnits()).orElse(null);
        if (policyOrgUnits != null && !matchRegexes(reqOrgUnitsArray, policyOrgUnits))
            throw new PolicyMatchException("org unit", reqOrgUnitsArray, "org unit", policyOrgUnits);
        csrAttributes.organizationalUnits(reqOrgUnitsArray);
    } else {
        String[] defaultOrgUnits = Optional.ofNullable(policySpecification).map(ps -> ps.defaults()).map(d -> d.subject()).map(s -> s.orgUnits()).orElse(null);
        if (defaultOrgUnits != null && defaultOrgUnits.length > 0)
            csrAttributes.organizationalUnits(defaultOrgUnits);
    }
    // computing the localities
    List<String> reqLocalities = Optional.ofNullable(request).map(req -> req.subject()).map(s -> s.locality()).orElse(null);
    if (reqLocalities != null && reqLocalities.size() > 0) {
        String[] reqLocalitiesArray = reqLocalities.toArray(new String[0]);
        // validating that the req.subject.locality matches with the policy localities
        String[] policyLocalities = Optional.ofNullable(policySpecification).map(ps -> ps.policy()).map(p -> p.subject()).map(s -> s.localities()).orElse(null);
        if (policyLocalities != null && !matchRegexes(reqLocalitiesArray, policyLocalities))
            throw new PolicyMatchException("locality", reqLocalitiesArray, "localities", policyLocalities);
        csrAttributes.locality(reqLocalitiesArray[0]);
    } else {
        String defaultLocality = Optional.ofNullable(policySpecification).map(ps -> ps.defaults()).map(d -> d.subject()).map(s -> s.locality()).orElse(null);
        if (isNotBlank(defaultLocality))
            csrAttributes.locality(defaultLocality);
    }
    // computing the province
    List<String> reqProvince = Optional.ofNullable(request).map(req -> req.subject()).map(s -> s.province()).orElse(null);
    if (reqProvince != null && reqProvince.size() > 0) {
        String[] reqProvinceArray = reqProvince.toArray(new String[0]);
        // validating that the req.subject.province matches with the policy states
        String[] policyStates = Optional.ofNullable(policySpecification).map(ps -> ps.policy()).map(p -> p.subject()).map(s -> s.states()).orElse(null);
        if (policyStates != null && !matchRegexes(reqProvinceArray, policyStates))
            throw new PolicyMatchException("state", reqProvinceArray, "states", policyStates);
        csrAttributes.state(reqProvinceArray[0]);
    } else {
        String defaultState = Optional.ofNullable(policySpecification).map(ps -> ps.defaults()).map(d -> d.subject()).map(s -> s.state()).orElse(null);
        if (isNotBlank(defaultState))
            csrAttributes.state(defaultState);
    }
    // computing the country
    List<String> reqCountries = Optional.ofNullable(request).map(req -> req.subject()).map(s -> s.country()).orElse(null);
    if (reqCountries != null && reqCountries.size() > 0) {
        String[] reqCountriesArray = reqCountries.toArray(new String[0]);
        // validating that the req.subject.country matches with the policy countries
        String[] policyCountries = Optional.ofNullable(policySpecification).map(ps -> ps.policy()).map(p -> p.subject()).map(s -> s.countries()).orElse(null);
        if (policyCountries != null && !matchRegexes(reqCountriesArray, policyCountries))
            throw new PolicyMatchException("state", reqCountriesArray, "states", policyCountries);
        csrAttributes.country(reqCountriesArray[0]);
    } else {
        String defaultCountry = Optional.ofNullable(policySpecification).map(ps -> ps.defaults()).map(d -> d.subject()).map(s -> s.country()).orElse(null);
        if (isNotBlank(defaultCountry))
            csrAttributes.country(defaultCountry);
    }
    if (request.dnsNames() != null && request.dnsNames().size() > 0) {
        SubjectAlternativeNamesByType subjectAlternativeNamesByType = new SubjectAlternativeNamesByType().dnsNames(request.dnsNames().toArray(new String[0]));
        csrAttributes.subjectAlternativeNamesByType(subjectAlternativeNamesByType);
    }
    return csrAttributes;
}
Also used : java.util(java.util) ZipInputStream(java.util.zip.ZipInputStream) ProductOption(com.venafi.vcert.sdk.connectors.cloud.endpoint.CAAccount.ProductOption) PEMCollection(com.venafi.vcert.sdk.certificate.PEMCollection) CertificateIssuingTemplate(com.venafi.vcert.sdk.connectors.cloud.domain.CertificateIssuingTemplate) KeyStoreZipCompressionRatioExceeded(com.venafi.vcert.sdk.connectors.ConnectorException.KeyStoreZipCompressionRatioExceeded) SubjectAlternativeNamesByType(com.venafi.vcert.sdk.connectors.cloud.CloudConnector.SubjectAlternativeNamesByType) UserDetails(com.venafi.vcert.sdk.connectors.cloud.domain.UserDetails) PolicyMatchException(com.venafi.vcert.sdk.connectors.ConnectorException.PolicyMatchException) com.venafi.vcert.sdk.connectors.cloud.endpoint(com.venafi.vcert.sdk.connectors.cloud.endpoint) CsrAttributes(com.venafi.vcert.sdk.connectors.cloud.CloudConnector.CsrAttributes) ZipEntry(java.util.zip.ZipEntry) FeignException(feign.FeignException) CloudZone(com.venafi.vcert.sdk.connectors.cloud.domain.CloudZone) PEMParser(org.bouncycastle.openssl.PEMParser) IOException(java.io.IOException) VCertException(com.venafi.vcert.sdk.VCertException) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest) KeyStoreZipEntriesExceeded(com.venafi.vcert.sdk.connectors.ConnectorException.KeyStoreZipEntriesExceeded) CloudPolicy(com.venafi.vcert.sdk.policy.api.domain.CloudPolicy) DataFormat(com.venafi.vcert.sdk.certificate.DataFormat) PolicySpecification(com.venafi.vcert.sdk.policy.domain.PolicySpecification) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) StringReader(java.io.StringReader) PrivateKey(java.security.PrivateKey) ChainOption(com.venafi.vcert.sdk.certificate.ChainOption) Data(lombok.Data) KeyStoreUnzipedFilesBytesSizeExceeded(com.venafi.vcert.sdk.connectors.ConnectorException.KeyStoreUnzipedFilesBytesSizeExceeded) Pattern(java.util.regex.Pattern) AllArgsConstructor(lombok.AllArgsConstructor) Application(com.venafi.vcert.sdk.connectors.cloud.domain.Application) InputStream(java.io.InputStream) CsrAttributes(com.venafi.vcert.sdk.connectors.cloud.CloudConnector.CsrAttributes) PolicyMatchException(com.venafi.vcert.sdk.connectors.ConnectorException.PolicyMatchException) SubjectAlternativeNamesByType(com.venafi.vcert.sdk.connectors.cloud.CloudConnector.SubjectAlternativeNamesByType)

Aggregations

VCertException (com.venafi.vcert.sdk.VCertException)68 PolicySpecification (com.venafi.vcert.sdk.policy.domain.PolicySpecification)49 DisplayName (org.junit.jupiter.api.DisplayName)48 Test (org.junit.jupiter.api.Test)48 IOException (java.io.IOException)34 CertificateNotFoundByThumbprintException (com.venafi.vcert.sdk.connectors.ConnectorException.CertificateNotFoundByThumbprintException)26 CertificateDNOrThumbprintWasNotProvidedException (com.venafi.vcert.sdk.connectors.ConnectorException.CertificateDNOrThumbprintWasNotProvidedException)25 MoreThanOneCertificateWithSameThumbprintException (com.venafi.vcert.sdk.connectors.ConnectorException.MoreThanOneCertificateWithSameThumbprintException)25 FeignException (feign.FeignException)25 FailedToRevokeTokenException (com.venafi.vcert.sdk.connectors.ConnectorException.FailedToRevokeTokenException)23 Authentication (com.venafi.vcert.sdk.endpoint.Authentication)23 StringReader (java.io.StringReader)7 CertificateRequest (com.venafi.vcert.sdk.certificate.CertificateRequest)5 PEMCollection (com.venafi.vcert.sdk.certificate.PEMCollection)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 CsrOriginOption (com.venafi.vcert.sdk.certificate.CsrOriginOption)4 DataFormat (com.venafi.vcert.sdk.certificate.DataFormat)4 ImportResponse (com.venafi.vcert.sdk.certificate.ImportResponse)4 RenewalRequest (com.venafi.vcert.sdk.certificate.RenewalRequest)4 RevocationRequest (com.venafi.vcert.sdk.certificate.RevocationRequest)4