use of com.venafi.vcert.sdk.connectors.ZoneConfiguration 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.connectors.ZoneConfiguration in project vcert-java by Venafi.
the class TppConnectorCertAT method retrieveCertificate.
@Test
void retrieveCertificate() throws VCertException, SocketException, UnknownHostException {
TppConnector connector = connectorResource.connector();
ZoneConfiguration zoneConfiguration = connectorResource.zoneConfiguration();
CertificateRequest certificateRequest = connectorResource.certificateRequest();
certificateRequest = connector.generateRequest(zoneConfiguration, certificateRequest);
String certificateId = connector.requestCertificate(certificateRequest, zoneConfiguration);
assertThat(certificateId).isNotNull();
PEMCollection pemCollection = connector.retrieveCertificate(certificateRequest);
assertThat(pemCollection.certificate()).isNotNull();
assertThat(pemCollection.privateKey()).isNotNull();
}
use of com.venafi.vcert.sdk.connectors.ZoneConfiguration in project vcert-java by Venafi.
the class TppConnectorIT method readZoneConfiguration.
@Test
void readZoneConfiguration() throws VCertException {
ZoneConfiguration zoneConfiguration = classUnderTest.readZoneConfiguration("tag");
assertThat(zoneConfiguration).isNotNull();
assertThat(zoneConfiguration.organization()).isNull();
assertThat(zoneConfiguration.organizationalUnit()).isNotNull();
assertThat(zoneConfiguration.organizationalUnit()).isEmpty();
assertThat(zoneConfiguration.country()).isNull();
assertThat(zoneConfiguration.province()).isNull();
assertThat(zoneConfiguration.locality()).isNull();
assertThat(zoneConfiguration.policy()).isNotNull();
assertThat(zoneConfiguration.policy().subjectCNRegexes()).containsExactly(".*");
assertThat(zoneConfiguration.policy().subjectORegexes()).containsExactly(".*");
assertThat(zoneConfiguration.policy().subjectOURegexes()).containsExactly(".*");
assertThat(zoneConfiguration.policy().subjectSTRegexes()).containsExactly(".*");
assertThat(zoneConfiguration.policy().subjectLRegexes()).containsExactly(".*");
assertThat(zoneConfiguration.policy().subjectCRegexes()).containsExactly(".*");
assertThat(zoneConfiguration.policy().allowedKeyConfigurations()).isNotNull();
assertThat(zoneConfiguration.policy().allowedKeyConfigurations()).hasSize(2);
assertThat(zoneConfiguration.policy().allowedKeyConfigurations().get(0).keyType()).isEqualTo(RSA);
assertThat(zoneConfiguration.policy().allowedKeyConfigurations().get(0).keySizes()).containsExactly(512, 1024, 2048, 4096, 8192);
assertThat(zoneConfiguration.policy().allowedKeyConfigurations().get(0).keyCurves()).isNull();
assertThat(zoneConfiguration.policy().allowedKeyConfigurations().get(1).keyType()).isEqualTo(ECDSA);
assertThat(zoneConfiguration.policy().allowedKeyConfigurations().get(1).keySizes()).isNull();
assertThat(zoneConfiguration.policy().allowedKeyConfigurations().get(1).keyCurves()).containsExactly(EllipticCurveP224, EllipticCurveP256, EllipticCurveP384, EllipticCurveP521);
assertThat(zoneConfiguration.policy().dnsSanRegExs()).containsExactly(".*");
assertThat(zoneConfiguration.policy().ipSanRegExs()).containsExactly(".*");
assertThat(zoneConfiguration.policy().emailSanRegExs()).containsExactly(".*");
assertThat(zoneConfiguration.policy().uriSanRegExs()).containsExactly(".*");
assertThat(zoneConfiguration.policy().upnSanRegExs()).containsExactly(".*");
assertThat(zoneConfiguration.policy().allowWildcards()).isTrue();
assertThat(zoneConfiguration.policy().allowKeyReuse()).isFalse();
assertThat(zoneConfiguration.hashAlgorithm()).isEqualTo(SHA256WithRSA);
assertThat(zoneConfiguration.customAttributeValues()).isNotNull();
assertThat(zoneConfiguration.customAttributeValues()).isEmpty();
}
use of com.venafi.vcert.sdk.connectors.ZoneConfiguration in project vcert-java by Venafi.
the class TppTokenConnectorAT method generateRequest.
@Test
void generateRequest() throws VCertException, IOException {
String commonName = TestUtils.randomCN();
ZoneConfiguration zoneConfiguration = connectorResource.connector().readZoneConfiguration(TestUtils.TPP_ZONE);
CertificateRequest certificateRequest = new CertificateRequest().subject(new CertificateRequest.PKIXName().commonName(commonName).organization(Collections.singletonList("Venafi, Inc.")).organizationalUnit(Arrays.asList("Engineering", "Automated Tests")).country(Collections.singletonList("US")).locality(Collections.singletonList("SLC")).province(Collections.singletonList("Utah"))).dnsNames(Collections.singletonList(InetAddress.getLocalHost().getHostName())).ipAddresses(getTestIps()).keyType(KeyType.RSA).keyLength(2048);
certificateRequest = connectorResource.connector().generateRequest(zoneConfiguration, certificateRequest);
assertThat(certificateRequest.csr()).isNotEmpty();
PKCS10CertificationRequest request = (PKCS10CertificationRequest) new PEMParser(new StringReader(new String(certificateRequest.csr()))).readObject();
// Values overridden by policy which is why they don't match the above values
String subject = request.getSubject().toString();
assertThat(subject).contains(format("CN=%s", commonName));
}
use of com.venafi.vcert.sdk.connectors.ZoneConfiguration 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())));
}
Aggregations