AWS code-library documentation change
Summary
Updated certificate import example to use S3 for certificate storage instead of local files. Changed parameters to accept S3 bucket and object keys, added S3 client integration, and modified error handling for S3 operations.
Security assessment
The changes demonstrate moving certificate storage to S3 but don't explicitly address a security vulnerability or add security features. While certificate management is security-related, the diff shows a workflow change rather than a direct security fix or new security capability documentation.
Diff
diff --git a/code-library/latest/ug/acm_example_acm_ImportCertificate_section.md b/code-library/latest/ug/acm_example_acm_ImportCertificate_section.md index 7d65597bc..2a71032f6 100644 --- a//code-library/latest/ug/acm_example_acm_ImportCertificate_section.md +++ b//code-library/latest/ug/acm_example_acm_ImportCertificate_section.md @@ -159,2 +158 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - - Usage: <certificatePath> <privateKeyPath> + Usage: <bucketName> <certificateKey> <privateKeyKey> @@ -163,2 +161,3 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - certificatePath - the path to the SSL/TLS certificate file. - privateKeyPath - the path to the private key file associated with the SSL/TLS certificate. + bucketName - The name of the S3 bucket containing the certificate and private key. + certificateKey - The object key for the SSL/TLS certificate file in S3. + privateKeyKey - The object key for the private key file in S3. @@ -167,4 +166,4 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - if (args.length != 2) { - System.out.println(usage); - return; - } + //if (args.length != 3) { + // System.out.println(usage); + // return; + // } @@ -172,3 +171,5 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - String certificatePath = args[0]; - String privateKeyPath = args[1]; - String certificateArn = importCertificate(certificatePath, privateKeyPath); + String bucketName = "certbucket100" ; //args[0]; + String certificateKey = "certificate.pem" ; // args[1]; + String privateKeyKey = "private_key.pem" ; //args[2]; + + String certificateArn = importCertificate(bucketName, certificateKey, privateKeyKey); @@ -179,2 +180 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - * Imports an SSL/TLS certificate and private key into AWS Certificate Manager (ACM) for use with - * AWS services. + * Imports an SSL/TLS certificate and private key from S3 into AWS Certificate Manager (ACM). @@ -182,3 +182,4 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - * @param certificatePath the file path to the SSL/TLS certificate - * @param privateKeyPath the file path to the private key associated with the certificate - * @throws IOException if there is an error reading the certificate or private key files + * @param bucketName The name of the S3 bucket. + * @param certificateKey The key for the SSL/TLS certificate file in S3. + * @param privateKeyKey The key for the private key file in S3. + * @return The ARN of the imported certificate. @@ -186 +187 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - public static String importCertificate(String certificatePath, String privateKeyPath) { + public static String importCertificate(String bucketName, String certificateKey, String privateKeyKey) { @@ -187,0 +189,2 @@ There's more on GitHub. Find the complete example and learn how to set up and ru + S3Client s3Client = S3Client.create(); + @@ -189,2 +192,2 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - byte[] certificateBytes = readFileBytes(certificatePath); - byte[] privateKeyBytes = readFileBytes(privateKeyPath); + byte[] certificateBytes = downloadFileFromS3(s3Client, bucketName, certificateKey); + byte[] privateKeyBytes = downloadFileFromS3(s3Client, bucketName, privateKeyKey); @@ -198,2 +201,2 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - String certificateArn = response.certificateArn(); - return certificateArn; + return response.certificateArn(); + @@ -201 +204,3 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - System.err.println("Error reading certificate or private key file: " + e.getMessage()); + System.err.println("Error downloading certificate or private key from S3: " + e.getMessage()); + } catch (S3Exception e) { + System.err.println("S3 error: " + e.awsErrorDetails().errorMessage()); @@ -206,3 +211,19 @@ There's more on GitHub. Find the complete example and learn how to set up and ru - private static byte[] readFileBytes(String filePath) throws IOException { - try (InputStream inputStream = new FileInputStream(filePath)) { - return IoUtils.toByteArray(inputStream); + /** + * Downloads a file from Amazon S3 and returns its contents as a byte array. + * + * @param s3Client The S3 client. + * @param bucketName The name of the S3 bucket. + * @param objectKey The key of the object in S3. + * @return The file contents as a byte array. + * @throws IOException If an I/O error occurs. + */ + private static byte[] downloadFileFromS3(S3Client s3Client, String bucketName, String objectKey) throws IOException { + GetObjectRequest getObjectRequest = GetObjectRequest.builder() + .bucket(bucketName) + .key(objectKey) + .build(); + + try (ResponseInputStream<GetObjectResponse> s3Object = s3Client.getObject(getObjectRequest); + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) { + IoUtils.copy(s3Object, byteArrayOutputStream); + return byteArrayOutputStream.toByteArray();