use of com.venafi.vcert.sdk.VCertException in project vcert-java by Venafi.
the class CloudConnectorTest method testExceptionValidatingMaxValidDays.
@Test
@DisplayName("Cloud - Testing Exception in Validation of MaxValidDays")
public void testExceptionValidatingMaxValidDays() throws VCertException {
classUnderTest.authenticate(new Authentication(null, null, "12345678-1234-1234-1234-123456789012"));
PolicySpecification policySpecification = CloudTestUtils.getPolicySpecification();
// setting the maxValidDays to null to validate that the related VCertException is thrown
policySpecification.policy().maxValidDays(-10);
Exception exception = assertThrows(VCertException.class, () -> classUnderTest.setPolicy(CloudTestUtils.getRandomZone(), policySpecification));
assertEquals(CloudTestUtils.getVCertExceptionMessage(CloudPolicySpecificationValidator.MAX_VALID_DAYS_EXCEPTION_MESSAGE), exception.getMessage());
}
use of com.venafi.vcert.sdk.VCertException in project vcert-java by Venafi.
the class CloudConnectorTest method testExceptionValidatingPolicyKeyTypeContainsInvalidValue.
@Test
@DisplayName("Cloud - Testing Exception in Validation of Policy KeyType")
public void testExceptionValidatingPolicyKeyTypeContainsInvalidValue() throws VCertException {
classUnderTest.authenticate(new Authentication(null, null, "12345678-1234-1234-1234-123456789012"));
PolicySpecification policySpecification = CloudTestUtils.getPolicySpecification();
// setting the keypair to a list of values which contains not only "RSA" to validate that the related VCertException is thrown
policySpecification.policy().keyPair().keyTypes(new String[] { "RSA", "ECDSA" });
Exception exception = assertThrows(VCertException.class, () -> classUnderTest.setPolicy(CloudTestUtils.getRandomZone(), policySpecification));
assertEquals(CloudTestUtils.getVCertExceptionMessage(CloudPolicySpecificationValidator.ATTRIBUTE_DOESNT_MATCH_WITH_ACCEPTED_VALUES_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_POLICY_KEYPAIR_KEY_TYPES), exception.getMessage());
}
use of com.venafi.vcert.sdk.VCertException in project vcert-java by Venafi.
the class TppConnectorCertAT method privateKeyPKCSTest.
@Test
void privateKeyPKCSTest() throws VCertException, UnknownHostException, IOException {
TppConnector connector = connectorResource.connector();
ZoneConfiguration zoneConfiguration = connectorResource.zoneConfiguration();
// By default the DataFormat of the CertificateRequest is PKCS8
CertificateRequest certificateRequest = connectorResource.certificateRequest().csrOrigin(CsrOriginOption.ServiceGeneratedCSR).keyPassword(TestUtils.KEY_PASSWORD);
certificateRequest = connector.generateRequest(zoneConfiguration, certificateRequest);
String pickupId = connector.requestCertificate(certificateRequest, zoneConfiguration);
assertThat(pickupId).isNotNull();
// Retrieving the PemCollection
PEMCollection pemCollectionRSAPrivateKeyPKCS8 = connector.retrieveCertificate(certificateRequest);
// getting the PrivateKey as PEM which should be a RSA Private Key in PKCS8 Encrypted
String privateKeyPKCS8AsEncryptedPem = pemCollectionRSAPrivateKeyPKCS8.pemPrivateKey();
PemObject privateKeyPKCS8AsPemObject = new PemReader(new StringReader(privateKeyPKCS8AsEncryptedPem)).readPemObject();
// evaluating that the private Key is in PKCS8 Encrypted
assertThat(pemCollectionRSAPrivateKeyPKCS8.privateKey()).isNotNull();
assertTrue(privateKeyPKCS8AsPemObject.getType().equals(TestUtils.PEM_HEADER_PKCS8_ENCRYPTED));
// changing to data format Legacy in order to get the PrivateKey in PKCS1
certificateRequest.dataFormat(DataFormat.LEGACY);
// Retrieving the PemCollection
PEMCollection pemCollectionRSAPrivateKey = connector.retrieveCertificate(certificateRequest);
// getting the PrivateKey as PEM which should be a RSA Private Key Encrypted
String privateKeyRSAAsEncryptedPem = pemCollectionRSAPrivateKey.pemPrivateKey();
PemObject privateKeyRSAAsPemObject = new PemReader(new StringReader(privateKeyRSAAsEncryptedPem)).readPemObject();
// evaluating that the private Key is in PKCS1 Encrypted
assertThat(pemCollectionRSAPrivateKey.privateKey()).isNotNull();
assertTrue(privateKeyRSAAsPemObject.getHeaders().stream().anyMatch(header -> TestUtils.PEM_RSA_PRIVATE_KEY_ENCRYPTED_HEADER_VALUE.equals(((PemHeader) header).getValue())));
}
use of com.venafi.vcert.sdk.VCertException in project vcert-java by Venafi.
the class TppTokenConnectorCertAT method privateKeyPKCSTest.
@Test
void privateKeyPKCSTest() throws VCertException, UnknownHostException, IOException {
TppTokenConnector connector = connectorResource.connector();
ZoneConfiguration zoneConfiguration = connectorResource.zoneConfiguration();
// By default the DataFormat of the CertificateRequest is PKCS8
CertificateRequest certificateRequest = connectorResource.certificateRequest().csrOrigin(CsrOriginOption.ServiceGeneratedCSR).keyPassword(TestUtils.KEY_PASSWORD);
certificateRequest = connector.generateRequest(zoneConfiguration, certificateRequest);
String pickupId = connector.requestCertificate(certificateRequest, zoneConfiguration);
assertThat(pickupId).isNotNull();
// Retrieving the PemCollection
PEMCollection pemCollectionRSAPrivateKeyPKCS8 = connector.retrieveCertificate(certificateRequest);
// getting the PrivateKey as PEM which should be a RSA Private Key in PKCS8 Encrypted
String privateKeyPKCS8AsEncryptedPem = pemCollectionRSAPrivateKeyPKCS8.pemPrivateKey();
PemObject privateKeyPKCS8AsPemObject = new PemReader(new StringReader(privateKeyPKCS8AsEncryptedPem)).readPemObject();
// evaluating that the private Key is in PKCS8 Encrypted
assertThat(pemCollectionRSAPrivateKeyPKCS8.privateKey()).isNotNull();
assertTrue(privateKeyPKCS8AsPemObject.getType().equals(TestUtils.PEM_HEADER_PKCS8_ENCRYPTED));
// changing to data format Legacy in order to get the PrivateKey in PKCS1
certificateRequest.dataFormat(DataFormat.LEGACY);
// Retrieving the PemCollection
PEMCollection pemCollectionRSAPrivateKey = connector.retrieveCertificate(certificateRequest);
// getting the PrivateKey as PEM which should be a RSA Private Key Encrypted
String privateKeyRSAAsEncryptedPem = pemCollectionRSAPrivateKey.pemPrivateKey();
PemObject privateKeyRSAAsPemObject = new PemReader(new StringReader(privateKeyRSAAsEncryptedPem)).readPemObject();
// evaluating that the private Key is in PKCS1 Encrypted
assertThat(pemCollectionRSAPrivateKey.privateKey()).isNotNull();
assertTrue(privateKeyRSAAsPemObject.getHeaders().stream().anyMatch(header -> TestUtils.PEM_RSA_PRIVATE_KEY_ENCRYPTED_HEADER_VALUE.equals(((PemHeader) header).getValue())));
}
use of com.venafi.vcert.sdk.VCertException in project vcert-java by Venafi.
the class CloudConnectorTest method testExceptionValidatingDefaultKeySizeDoesntMatchWithPolicyKeySizes.
@Test
@DisplayName("Cloud - Testing Exception in Validation of Default KeySize with a value not matching with the Policy KeySizes")
public void testExceptionValidatingDefaultKeySizeDoesntMatchWithPolicyKeySizes() throws VCertException {
classUnderTest.authenticate(new Authentication(null, null, "12345678-1234-1234-1234-123456789012"));
PolicySpecification policySpecification = CloudTestUtils.getPolicySpecification();
// setting the default keysize to a value which is not matching with
// the Policy KeySizes to validate that the related VCertException is thrown
policySpecification.defaults().keyPair().rsaKeySize(4096);
Exception exception = assertThrows(VCertException.class, () -> classUnderTest.setPolicy(CloudTestUtils.getRandomZone(), policySpecification));
assertEquals(CloudTestUtils.getVCertExceptionMessage(CloudPolicySpecificationValidator.DEFAULT_ATTRIBUTE_DOESNT_MATCH_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_DEFAULTS_KEYPAIR_RSA_KEY_SIZE, PolicySpecificationConst.ATT_POLICY_KEYPAIR_RSA_KEY_SIZES), exception.getMessage());
}
Aggregations