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));
}
}
}
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;
}
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);
}
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));
}
}
}
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());
}
Aggregations