Search in sources :

Example 41 with VCertException

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

the class TPPPolicySpecificationValidator method validateDefaultKeyPair.

private void validateDefaultKeyPair(DefaultsKeyPair defaultsKeyPair, KeyPair policyKeyPair) throws VCertException {
    if (defaultsKeyPair != null) {
        String defaultKeyType = defaultsKeyPair.keyType();
        if (defaultKeyType != null && !defaultKeyType.equals("")) {
            if (!SupportedKeyPairs.TPP.containsKeyType(defaultKeyType))
                throw new VCertException(String.format(DEFAULT_ATTRIBUTE_DOESNT_MATCH_WITH_ACCEPTED_VALUES_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_DEFAULTS_KEYPAIR_KEY_TYPE));
            if (policyKeyPair != null) {
                String[] policyKeyTypes = policyKeyPair.keyTypes();
                if (policyKeyTypes != null && policyKeyTypes.length == 1 && !policyKeyTypes[0].equals("") && !policyKeyTypes[0].equals(defaultKeyType))
                    throw new VCertException(String.format(DEFAULT_ATTRIBUTE_DOESNT_MATCH_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_DEFAULTS_KEYPAIR_KEY_TYPE, PolicySpecificationConst.ATT_POLICY_KEYPAIR_KEY_TYPES));
            }
        }
        Integer defaultRsaKeySize = defaultsKeyPair.rsaKeySize();
        if (defaultRsaKeySize != null) {
            if (!SupportedRSAKeySizes.TPP.containsRsaKeySize(defaultRsaKeySize))
                throw new VCertException(String.format(DEFAULT_ATTRIBUTE_DOESNT_MATCH_WITH_ACCEPTED_VALUES_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_DEFAULTS_KEYPAIR_RSA_KEY_SIZE));
            if (policyKeyPair != null) {
                Integer[] policyRsaKeySizes = policyKeyPair.rsaKeySizes();
                if (policyRsaKeySizes != null && policyRsaKeySizes.length == 1 && !policyRsaKeySizes[0].equals(defaultRsaKeySize))
                    throw new VCertException(String.format(DEFAULT_ATTRIBUTE_DOESNT_MATCH_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_DEFAULTS_KEYPAIR_RSA_KEY_SIZE, PolicySpecificationConst.ATT_POLICY_KEYPAIR_RSA_KEY_SIZES));
            }
        }
        String defaultEC = defaultsKeyPair.ellipticCurve();
        if (defaultEC != null && !defaultEC.equals("")) {
            if (!SupportedECCKeys.TPP.containsEllipticCurve(defaultEC))
                throw new VCertException(String.format(DEFAULT_ATTRIBUTE_DOESNT_MATCH_WITH_ACCEPTED_VALUES_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_DEFAULTS_KEYPAIR_ELLIPTIC_CURVE));
            if (policyKeyPair != null) {
                String[] policyEC = policyKeyPair.ellipticCurves();
                if (policyEC != null && policyEC.length == 1 && !policyEC[0].equals("") && !policyEC[0].equals(defaultEC))
                    throw new VCertException(String.format(DEFAULT_ATTRIBUTE_DOESNT_MATCH_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_DEFAULTS_KEYPAIR_ELLIPTIC_CURVE, PolicySpecificationConst.ATT_POLICY_KEYPAIR_ELLIPTIC_CURVES));
            }
        }
        if (policyKeyPair != null && policyKeyPair.serviceGenerated() != null && defaultsKeyPair.serviceGenerated() != null && !policyKeyPair.serviceGenerated().equals(defaultsKeyPair.serviceGenerated())) {
            throw new VCertException(String.format(DEFAULT_ATTRIBUTE_DOESNT_MATCH_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_DEFAULTS_KEYPAIR_SERVICE_GENERATED_TYPE, PolicySpecificationConst.ATT_POLICY_KEYPAIR_SERVICE_GENERATED_TYPE));
        }
    }
}
Also used : VCertException(com.venafi.vcert.sdk.VCertException)

Example 42 with VCertException

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

the class AbstractTppConnector method requestTppSshCertificate.

protected TppSshCertRequestResponse requestTppSshCertificate(SshCertificateRequest sshCertificateRequest) throws VCertException {
    TppSshCertRequest tppSshCertRequest = TppConnectorUtils.convertToTppSshCertReq(sshCertificateRequest);
    TppSshCertRequestResponse requestResponse;
    try {
        requestResponse = tppAPI.requestSshCertificate(tppSshCertRequest);
    } catch (Exception e) {
        throw new VCertException(e);
    }
    if (!requestResponse.response().success())
        throw new RequestCertificateException(requestResponse.response().errorCode(), requestResponse.response().errorMessage());
    return requestResponse;
}
Also used : TppSshCertRequestResponse(com.venafi.vcert.sdk.connectors.tpp.endpoint.ssh.TppSshCertRequestResponse) VCertException(com.venafi.vcert.sdk.VCertException) TppSshCertRequest(com.venafi.vcert.sdk.connectors.tpp.endpoint.ssh.TppSshCertRequest) VCertException(com.venafi.vcert.sdk.VCertException) ConnectorException(com.venafi.vcert.sdk.connectors.ConnectorException)

Example 43 with VCertException

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

the class AbstractTppConnector method setPolicy.

public void setPolicy(String policyName, TPPPolicy tppPolicy) throws VCertException {
    // ensuring that the policy name starts with the tpp_root_path
    if (!policyName.startsWith(TppPolicyConstants.TPP_ROOT_PATH))
        policyName = TppPolicyConstants.TPP_ROOT_PATH + policyName;
    tppPolicy.policyName(policyName);
    // if the policy doesn't exist
    if (!TppConnectorUtils.dnExist(policyName, tppAPI)) {
        // verifying that the policy's parent exists
        String parentName = tppPolicy.getParentName();
        if (!parentName.equals(TppPolicyConstants.TPP_ROOT_PATH) && !TppConnectorUtils.dnExist(parentName, tppAPI))
            throw new VCertException(String.format("The policy's parent %s doesn't exist", parentName));
        // creating the policy
        TppConnectorUtils.createPolicy(policyName, tppAPI);
    } else
        TppConnectorUtils.resetAttributes(policyName, tppAPI);
    // creating policy's attributes.
    TppConnectorUtils.setPolicyAttributes(tppPolicy, tppAPI);
}
Also used : VCertException(com.venafi.vcert.sdk.VCertException)

Example 44 with VCertException

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

the class CloudPolicySpecificationValidator method validateDefaultKeyPair.

private void validateDefaultKeyPair(DefaultsKeyPair defaultsKeyPair, KeyPair policyKeyPair) throws VCertException {
    if (defaultsKeyPair != null) {
        String defaultKeyType = defaultsKeyPair.keyType();
        if (defaultKeyType != null && !defaultKeyType.equals("")) {
            if (!SupportedKeyPairs.VAAS.containsKeyType(defaultKeyType))
                throw new VCertException(String.format(DEFAULT_ATTRIBUTE_DOESNT_MATCH_WITH_ACCEPTED_VALUES_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_DEFAULTS_KEYPAIR_KEY_TYPE));
            if (policyKeyPair != null) {
                String[] policyKeyTypes = policyKeyPair.keyTypes();
                if (policyKeyTypes != null && policyKeyTypes.length == 1 && !policyKeyTypes[0].equals("") && !policyKeyTypes[0].equals(defaultKeyType))
                    throw new VCertException(String.format(DEFAULT_ATTRIBUTE_DOESNT_MATCH_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_DEFAULTS_KEYPAIR_KEY_TYPE, PolicySpecificationConst.ATT_POLICY_KEYPAIR_KEY_TYPES));
            }
        }
        Integer defaultRsaKeySize = defaultsKeyPair.rsaKeySize();
        if (defaultRsaKeySize != null) {
            if (!SupportedRSAKeySizes.VAAS.containsRsaKeySize(defaultRsaKeySize))
                throw new VCertException(String.format(DEFAULT_ATTRIBUTE_DOESNT_MATCH_WITH_ACCEPTED_VALUES_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_DEFAULTS_KEYPAIR_RSA_KEY_SIZE));
            if (policyKeyPair != null && !Arrays.stream(policyKeyPair.rsaKeySizes()).anyMatch(defaultRsaKeySize::equals))
                throw new VCertException(String.format(DEFAULT_ATTRIBUTE_DOESNT_MATCH_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_DEFAULTS_KEYPAIR_RSA_KEY_SIZE, PolicySpecificationConst.ATT_POLICY_KEYPAIR_RSA_KEY_SIZES));
        }
    }
}
Also used : VCertException(com.venafi.vcert.sdk.VCertException)

Example 45 with VCertException

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

the class TppTokenConnectorTest method testExceptionValidatingDefaultCountryWithNot2Characters.

@Test
@DisplayName("TPP - Testing Exception in Validation of Defaults Country with not 2 char values")
public void testExceptionValidatingDefaultCountryWithNot2Characters() throws VCertException {
    PolicySpecification policySpecification = TppTestUtils.getPolicySpecification();
    // setting the Country to a value which contains a string with more than 2 chars
    // to validate that the related VCertException is thrown
    policySpecification.policy(null);
    policySpecification.defaults().subject().country("MEX");
    Exception exception = assertThrows(VCertException.class, () -> classUnderTest.setPolicy(TppTestUtils.getRandomZone(), policySpecification));
    Assertions.assertEquals(TppTestUtils.getVCertExceptionMessage(TPPPolicySpecificationValidator.ATTRIBUTE_HAS_NOT_A_TWO_CHAR_STRING_VALUE_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_DEFAULTS_SUBJECT_COUNTRY), 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)

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