use of com.amazon.dataprepper.plugins.certificate.model.Certificate in project data-prepper by opensearch-project.
the class FileCertificateProvider method getCertificate.
public Certificate getCertificate() {
try {
final Path certFilePath = new File(certificateFilePath).toPath();
final Path pkFilePath = new File(privateKeyFilePath).toPath();
final byte[] certFileBytes = Files.readAllBytes(certFilePath);
final byte[] pkFileBytes = Files.readAllBytes(pkFilePath);
final String certAsString = new String(certFileBytes);
final String privateKeyAsString = new String(pkFileBytes);
return new Certificate(certAsString, privateKeyAsString);
} catch (final Exception ex) {
LOG.error("Error encountered while reading the certificate.", ex);
throw new RuntimeException(ex);
}
}
use of com.amazon.dataprepper.plugins.certificate.model.Certificate in project data-prepper by opensearch-project.
the class S3CertificateProvider method getCertificate.
public Certificate getCertificate() {
try {
final URI certificateFileUri = new URI(certificateFile);
final URI privateKeyFileUri = new URI(privateKeyFile);
final String certificate = getObjectWithKey(certificateFileUri.getHost(), certificateFileUri.getPath().substring(1));
final String privateKey = getObjectWithKey(privateKeyFileUri.getHost(), privateKeyFileUri.getPath().substring(1));
return new Certificate(certificate, privateKey);
} catch (URISyntaxException ex) {
LOG.error("Error encountered while parsing the certificate's Amazon S3 URI.", ex);
throw new RuntimeException(ex);
}
}
use of com.amazon.dataprepper.plugins.certificate.model.Certificate in project data-prepper by opensearch-project.
the class ACMCertificateProviderTest method getACMCertificateWithEncryptedPrivateKeySuccess.
@Test
public void getACMCertificateWithEncryptedPrivateKeySuccess() throws IOException {
final Path certFilePath = Path.of("data/certificate/test_cert.crt");
final Path encryptedKeyFilePath = Path.of("data/certificate/test_encrypted_key.key");
final Path decryptedKeyFilePath = Path.of("data/certificate/test_decrypted_key.key");
final String certAsString = Files.readString(certFilePath);
final String encryptedKeyAsString = Files.readString(encryptedKeyFilePath);
final String decryptedKeyAsString = Files.readString(decryptedKeyFilePath);
when(exportCertificateResponse.certificate()).thenReturn(certAsString);
when(exportCertificateResponse.privateKey()).thenReturn(encryptedKeyAsString);
when(acmClient.exportCertificate(any(ExportCertificateRequest.class))).thenReturn(exportCertificateResponse);
final Certificate certificate = acmCertificateProvider.getCertificate();
assertThat(certificate.getCertificate(), is(certAsString));
assertThat(certificate.getPrivateKey(), is(decryptedKeyAsString));
}
use of com.amazon.dataprepper.plugins.certificate.model.Certificate in project data-prepper by opensearch-project.
the class ACMCertificateProviderTest method getACMCertificateWithUnencryptedPrivateKeySuccess.
@Test
public void getACMCertificateWithUnencryptedPrivateKeySuccess() throws IOException {
final Path certFilePath = Path.of("data/certificate/test_cert.crt");
final Path decryptedKeyFilePath = Path.of("data/certificate/test_decrypted_key.key");
final String certAsString = Files.readString(certFilePath);
final String decryptedKeyAsString = Files.readString(decryptedKeyFilePath);
when(exportCertificateResponse.certificate()).thenReturn(certAsString);
when(exportCertificateResponse.privateKey()).thenReturn(decryptedKeyAsString);
when(acmClient.exportCertificate(any(ExportCertificateRequest.class))).thenReturn(exportCertificateResponse);
final Certificate certificate = acmCertificateProvider.getCertificate();
assertThat(certificate.getCertificate(), is(certAsString));
assertThat(certificate.getPrivateKey(), is(decryptedKeyAsString));
}
use of com.amazon.dataprepper.plugins.certificate.model.Certificate in project data-prepper by opensearch-project.
the class S3CertificateProviderTest method getCertificateValidKeyPathSuccess.
@Test
public void getCertificateValidKeyPathSuccess() {
final String certificateContent = UUID.randomUUID().toString();
final String privateKeyContent = UUID.randomUUID().toString();
final String bucketName = UUID.randomUUID().toString();
final String certificatePath = UUID.randomUUID().toString();
final String privateKeyPath = UUID.randomUUID().toString();
final String s3SslKeyCertChainFile = String.format("s3://%s/%s", bucketName, certificatePath);
final String s3SslKeyFile = String.format("s3://%s/%s", bucketName, privateKeyPath);
final InputStream certObjectStream = IOUtils.toInputStream(certificateContent, StandardCharsets.UTF_8);
final ResponseInputStream certResponseInputStream = new ResponseInputStream<>(GetObjectResponse.builder().build(), AbortableInputStream.create(certObjectStream));
final InputStream privateKeyObjectStream = IOUtils.toInputStream(privateKeyContent, StandardCharsets.UTF_8);
final ResponseInputStream<GetObjectResponse> privateKeyResponseInputStream = new ResponseInputStream<>(GetObjectResponse.builder().build(), AbortableInputStream.create(privateKeyObjectStream));
final GetObjectRequest certRequest = GetObjectRequest.builder().bucket(bucketName).key(certificatePath).build();
when(s3Client.getObject(certRequest)).thenReturn(certResponseInputStream);
final GetObjectRequest keyRequest = GetObjectRequest.builder().bucket(bucketName).key(privateKeyPath).build();
when(s3Client.getObject(keyRequest)).thenReturn(privateKeyResponseInputStream);
s3CertificateProvider = new S3CertificateProvider(s3Client, s3SslKeyCertChainFile, s3SslKeyFile);
final Certificate certificate = s3CertificateProvider.getCertificate();
assertThat(certificate.getCertificate(), is(certificateContent));
assertThat(certificate.getPrivateKey(), is(privateKeyContent));
}
Aggregations