@@ -501,7 +501,7 @@ Resources:
501501
502502 self._hash_algo = 'sha256'
503503 self._other_extensions = {}
504- self._kms_signature_algo = 'RSASSA_PSS_SHA_256 '
504+ self._kms_signature_algo = 'RSASSA_PKCS1_V1_5_SHA_256 '
505505
506506 @_writer
507507 def subject(self, value):
@@ -895,7 +895,7 @@ Resources:
895895
896896 # Check if Root Cert ARN & ICA Cert ARN are present, if not, import them
897897 if not APC_ROOT_KEY_ARN:
898- APC_ROOT_KEY_ARN = import_public_key_to_payment_crypto(root_cert, ica_cert)
898+ APC_ROOT_KEY_ARN, APC_ICA_KEY_ARN = import_public_key_to_payment_crypto(root_cert, ica_cert)
899899 else:
900900 print("Root Key ARN already found:", APC_ROOT_KEY_ARN)
901901
@@ -925,7 +925,7 @@ Resources:
925925 public_key = cert.public_key()
926926
927927 # Export AES_KEY1 using RSA-OAEP with RSA_KEY1 as the wrapping key
928- enc_aes_key1 = export_aes_key(APC_KEY_ARN, cert_contents, APC_ROOT_KEY_ARN )
928+ enc_aes_key1 = export_aes_key(APC_KEY_ARN, cert_contents, APC_ICA_KEY_ARN )
929929
930930 # Prepend the appropriate key block header to ENC_AES_KEY1
931931 enc_aes_key1_with_header = prepend_key_block_header(enc_aes_key1, DATA_TYPE)
@@ -940,23 +940,27 @@ Resources:
940940 'APC_ROOT_KEY_ARN': APC_ROOT_KEY_ARN,
941941 'KMS_KEY_ARN': KMS_KEY_ARN,
942942 'APC_KEY_ARN': APC_KEY_ARN,
943- 'enc_aes_key1': enc_aes_key1, # This is already a string
944- 'kcv': kcv, # Assume this is already in the correct format
943+ 'enc_aes_key1': enc_aes_key1,
944+ 'kcv': kcv,
945945 'signature': hex_signature
946946 }
947947
948-
949948 # Optionally store results in S3
950949 if S3_BUCKET:
951950 s3_locations = store_results_in_s3(result, S3_BUCKET, S3_PREFIX)
952951 result['s3_locations'] = s3_locations
953-
952+
953+ response_body = {
954+ 'message': 'All operations completed successfully',
955+ 'result': result
956+ }
957+
954958 return {
955959 'statusCode': 200,
956- 'body': json.dumps({
957- 'message ': 'All operations completed successfully',
958- 'result ': result
959- })
960+ 'body': response_body,
961+ 'headers ': {
962+ 'Content-Type ': 'application/json'
963+ }
960964 }
961965 except Exception as e:
962966 # Get the full traceback
@@ -1173,7 +1177,7 @@ Resources:
11731177
11741178 intermediateARN = response['Key']['KeyArn']
11751179
1176- return intermediateARN
1180+ return rootARN, intermediateARN
11771181
11781182 except ClientError as e:
11791183 error_code = e.response['Error']['Code']
@@ -1289,10 +1293,11 @@ Resources:
12891293
12901294 def sign_with_kms(data_to_sign, key_arn):
12911295 kms_client = boto3.client('kms')
1296+ message_bytes = bytes.fromhex(data_to_sign)
12921297
12931298 response = kms_client.sign(
12941299 KeyId=key_arn,
1295- Message=data_to_sign.encode() ,
1300+ Message=message_bytes ,
12961301 MessageType='RAW',
12971302 SigningAlgorithm='RSASSA_PKCS1_V1_5_SHA_256'
12981303 )
@@ -1303,15 +1308,37 @@ Resources:
13031308 s3_client = boto3.client('s3')
13041309 s3_locations = {}
13051310
1311+ # Combine the three key ARNs into one file
1312+ key_arns = [
1313+ f"KMS Key ARN: {result['KMS_KEY_ARN']}",
1314+ f"APC Root Key ARN: {result['APC_ROOT_KEY_ARN']}",
1315+ f"APC Key ARN: {result['APC_KEY_ARN']}"
1316+ ]
1317+ key_arns_content = "\n".join(key_arns)
1318+
1319+ file_key = f"{prefix}KEY_ARNS.txt"
1320+ try:
1321+ s3_client.put_object(
1322+ Bucket=bucket,
1323+ Key=file_key,
1324+ Body=key_arns_content.encode('utf-8')
1325+ )
1326+ s3_locations['KEY_ARNS'] = f"s3://{bucket}/{file_key}"
1327+ except ClientError as e:
1328+ print(f"Error storing KEY_ARNS in S3: {e}")
1329+ raise
1330+
1331+ # Store the remaining files
13061332 for key, value in result.items():
1333+ if key in ['KMS_KEY_ARN', 'APC_ROOT_KEY_ARN', 'APC_KEY_ARN']:
1334+ # Skip these keys as they are already combined
1335+ continue
1336+
13071337 if value is None:
13081338 print(f"Skipping storing {key} in S3 as the value is None.")
13091339 continue
13101340
1311- if key in ['APC_ROOT_KEY_ARN', 'KMS_KEY_ARN', 'APC_KEY_ARN']:
1312- # These are not files, just store them as text
1313- content = str(value)
1314- elif key in ['enc_aes_key1', 'kcv']:
1341+ if key in ['enc_aes_key1', 'kcv']:
13151342 # These are already in hex format, store as is
13161343 content = str(value)
13171344 elif key == 'signature':
@@ -1334,7 +1361,10 @@ Resources:
13341361 except ClientError as e:
13351362 print(f"Error storing {key} in S3: {e}")
13361363 raise
1364+
13371365 return s3_locations
1366+
1367+
13381368 Environment :
13391369 Variables :
13401370 CERTIFICATE_S3_URI : !Ref CertificateS3URI
0 commit comments