Unable to decrypt ACM exported private key
- [x] I've gone though the User Guide and the API reference
- [x] I've searched for previous similar issues and didn't find any solution
Describe the bug
When exporting an ACM private certificate via aws acm export-certificate, I am unable to decrypt the private key using the provided instructions.
SDK version number
aws-cli/2.0.27 Python/3.7.4 Darwin/19.4.0 botocore/2.0.0dev31
aws-cli/1.18.93 Python/2.7.16 Darwin/19.4.0 botocore/1.17.16
Platform/OS/Hardware/Device
macOS Catalina 10.15.4
To Reproduce (observed behavior) The exact commands are in the logs below, but the steps are to:
- export the certificate's private key to a file via
aws acm export-certificate ... - decode the file with
openssl rsa ...
Expected behavior Able to decrypt the private key with openssl rsa per instructions:
openssl rsa -in private_key_enc.txt -out private_key.txt
Enter pass phrase for private_key_enc.txt: (testing123)
writing RSA key
Logs/output
$ aws acm export-certificate --certificate-arn arn:aws:acm:us-east-1:...:certificate/... --passphrase $(openssl base64 -e <<< 'testing123') --debug | jq -r '.PrivateKey' > private_key_enc.txt
2020-07-03 11:08:46,605 - MainThread - awscli.clidriver - DEBUG - CLI version: aws-cli/2.0.27 Python/3.7.4 Darwin/19.4.0 botocore/2.0.0dev31
2020-07-03 11:08:46,605 - MainThread - awscli.clidriver - DEBUG - Arguments entered to CLI: ['acm', 'export-certificate', '--certificate-arn', 'arn:aws:acm:us-east-1:...:certificate/...', '--passphrase', 'dGVzdGluZzEyMwo=', '--debug']
2020-07-03 11:08:46,605 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function add_timestamp_parser at 0x7fee008267a0>
2020-07-03 11:08:46,605 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function register_uri_param_handler at 0x7fede8121ef0>
2020-07-03 11:08:46,606 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function add_binary_formatter at 0x7fee008763b0>
2020-07-03 11:08:46,606 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function inject_assume_role_provider_cache at 0x7fede82e2e60>
2020-07-03 11:08:46,609 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function attach_history_handler at 0x7fedc03f08c0>
2020-07-03 11:08:46,610 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function inject_json_file_cache at 0x7fedc0393e60>
2020-07-03 11:08:46,625 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/local/aws-cli/botocore/data/acm/2015-12-08/service-2.json
2020-07-03 11:08:46,627 - MainThread - botocore.hooks - DEBUG - Event building-command-table.acm: calling handler <function add_waiters at 0x7fee00835440>
2020-07-03 11:08:46,642 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/local/aws-cli/botocore/data/acm/2015-12-08/waiters-2.json
2020-07-03 11:08:46,643 - MainThread - awscli.clidriver - DEBUG - OrderedDict([('certificate-arn', <awscli.arguments.CLIArgument object at 0x7fede025ee10>), ('passphrase', <awscli.arguments.CLIArgument object at 0x7fede02600d0>)])
2020-07-03 11:08:46,644 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.acm.export-certificate: calling handler <function add_streaming_output_arg at 0x7fee00829950>
2020-07-03 11:08:46,644 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.acm.export-certificate: calling handler <function add_cli_input_json at 0x7fede82e98c0>
2020-07-03 11:08:46,644 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.acm.export-certificate: calling handler <function add_cli_input_yaml at 0x7fede82e9b00>
2020-07-03 11:08:46,644 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.acm.export-certificate: calling handler <function unify_paging_params at 0x7fedc03afb90>
2020-07-03 11:08:46,660 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/local/aws-cli/botocore/data/acm/2015-12-08/paginators-1.json
2020-07-03 11:08:46,660 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.acm.export-certificate: calling handler <function add_generate_skeleton at 0x7fee00784ef0>
2020-07-03 11:08:46,661 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.acm.export-certificate: calling handler <function add_auto_prompt at 0x7fee00873560>
2020-07-03 11:08:46,661 - MainThread - botocore.hooks - DEBUG - Event before-building-argument-table-parser.acm.export-certificate: calling handler <bound method OverrideRequiredArgsArgument.override_required_args of <awscli.customizations.cliinput.CliInputJSONArgument object at 0x7fede0260150>>
2020-07-03 11:08:46,661 - MainThread - botocore.hooks - DEBUG - Event before-building-argument-table-parser.acm.export-certificate: calling handler <bound method OverrideRequiredArgsArgument.override_required_args of <awscli.customizations.cliinput.CliInputYAMLArgument object at 0x7fede0260290>>
2020-07-03 11:08:46,661 - MainThread - botocore.hooks - DEBUG - Event before-building-argument-table-parser.acm.export-certificate: calling handler <bound method GenerateCliSkeletonArgument.override_required_args of <awscli.customizations.generatecliskeleton.GenerateCliSkeletonArgument object at 0x7fede0261d50>>
2020-07-03 11:08:46,661 - MainThread - botocore.hooks - DEBUG - Event before-building-argument-table-parser.acm.export-certificate: calling handler <bound method AutoPromptArgument.override_required_args of <awscli.customizations.autoprompt.AutoPromptArgument object at 0x7fede026dc50>>
2020-07-03 11:08:46,662 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.acm.export-certificate.certificate-arn: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7fedb002dfd0>
2020-07-03 11:08:46,662 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.acm.export-certificate: calling handler <awscli.argprocess.ParamShorthandParser object at 0x7fede82aba10>
2020-07-03 11:08:46,662 - MainThread - awscli.arguments - DEBUG - Unpacked value of 'arn:aws:acm:us-east-1:...:certificate/...' for parameter "certificate_arn": 'arn:aws:acm:us-east-1:...:certificate/...'
2020-07-03 11:08:46,662 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.acm.export-certificate.passphrase: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7fedb002dfd0>
2020-07-03 11:08:46,662 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.acm.export-certificate: calling handler <awscli.argprocess.ParamShorthandParser object at 0x7fede82aba10>
2020-07-03 11:08:46,662 - MainThread - awscli.arguments - DEBUG - Unpacked value of 'dGVzdGluZzEyMwo=' for parameter "passphrase": 'dGVzdGluZzEyMwo='
2020-07-03 11:08:46,662 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.acm.export-certificate.cli-input-json: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7fedb002dfd0>
2020-07-03 11:08:46,662 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.acm.export-certificate.cli-input-yaml: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7fedb002dfd0>
2020-07-03 11:08:46,662 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.acm.export-certificate.generate-cli-skeleton: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7fedb002dfd0>
2020-07-03 11:08:46,662 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.acm.export-certificate.cli-auto-prompt: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7fedb002dfd0>
2020-07-03 11:08:46,662 - MainThread - botocore.hooks - DEBUG - Event calling-command.acm.export-certificate: calling handler <bound method CliInputArgument.add_to_call_parameters of <awscli.customizations.cliinput.CliInputJSONArgument object at 0x7fede0260150>>
2020-07-03 11:08:46,662 - MainThread - botocore.hooks - DEBUG - Event calling-command.acm.export-certificate: calling handler <bound method CliInputArgument.add_to_call_parameters of <awscli.customizations.cliinput.CliInputYAMLArgument object at 0x7fede0260290>>
2020-07-03 11:08:46,662 - MainThread - botocore.hooks - DEBUG - Event calling-command.acm.export-certificate: calling handler <bound method GenerateCliSkeletonArgument.generate_skeleton of <awscli.customizations.generatecliskeleton.GenerateCliSkeletonArgument object at 0x7fede0261d50>>
2020-07-03 11:08:46,662 - MainThread - botocore.hooks - DEBUG - Event calling-command.acm.export-certificate: calling handler <bound method AutoPromptArgument.auto_prompt_arguments of <awscli.customizations.autoprompt.AutoPromptArgument object at 0x7fede026dc50>>
2020-07-03 11:08:46,662 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: env
2020-07-03 11:08:46,662 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: assume-role
2020-07-03 11:08:46,662 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: assume-role-with-web-identity
2020-07-03 11:08:46,662 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: sso
2020-07-03 11:08:46,662 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: shared-credentials-file
2020-07-03 11:08:46,663 - MainThread - botocore.credentials - INFO - Found credentials in shared credentials file: ~/.aws/credentials
2020-07-03 11:08:46,663 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/local/aws-cli/botocore/data/endpoints.json
2020-07-03 11:08:46,667 - MainThread - botocore.hooks - DEBUG - Event choose-service-name: calling handler <function handle_service_name_alias at 0x7fee005cc200>
2020-07-03 11:08:46,668 - MainThread - botocore.hooks - DEBUG - Event creating-client-class.acm: calling handler <function add_generate_presigned_url at 0x7fee0057b200>
2020-07-03 11:08:46,670 - MainThread - botocore.endpoint - DEBUG - Setting acm timeout as (60, 60)
2020-07-03 11:08:46,671 - MainThread - botocore.hooks - DEBUG - Event provide-client-params.acm.ExportCertificate: calling handler <function base64_decode_input_blobs at 0x7fee00876440>
2020-07-03 11:08:46,671 - MainThread - botocore.hooks - DEBUG - Event before-parameter-build.acm.ExportCertificate: calling handler <function generate_idempotent_uuid at 0x7fee005d0e60>
2020-07-03 11:08:46,671 - MainThread - botocore.hooks - DEBUG - Event before-call.acm.ExportCertificate: calling handler <function inject_api_version_header_if_needed at 0x7fee005d4710>
2020-07-03 11:08:46,671 - MainThread - botocore.endpoint - DEBUG - Making request for OperationModel(name=ExportCertificate) with params: {'url_path': '/', 'query_string': '', 'method': 'POST', 'headers': {'X-Amz-Target': 'CertificateManager.ExportCertificate', 'Content-Type': 'application/x-amz-json-1.1', 'User-Agent': 'aws-cli/2.0.27 Python/3.7.4 Darwin/19.4.0 botocore/2.0.0dev31'}, 'body': b'{"CertificateArn": "arn:aws:acm:us-east-1:...:certificate/...", "Passphrase": "dGVzdGluZzEyMwo="}', 'url': 'https://acm.us-east-1.amazonaws.com/', 'context': {'client_region': 'us-east-1', 'client_config': <botocore.config.Config object at 0x7fede86c4710>, 'has_streaming_input': False, 'auth_type': None}}
2020-07-03 11:08:46,671 - MainThread - botocore.hooks - DEBUG - Event request-created.acm.ExportCertificate: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x7fede86c4650>>
2020-07-03 11:08:46,671 - MainThread - botocore.hooks - DEBUG - Event choose-signer.acm.ExportCertificate: calling handler <function set_operation_specific_signer at 0x7fee005c1ef0>
2020-07-03 11:08:46,671 - MainThread - botocore.auth - DEBUG - Calculating signature using v4 auth.
2020-07-03 11:08:46,671 - MainThread - botocore.auth - DEBUG - CanonicalRequest:
POST
/
content-type:application/x-amz-json-1.1
host:acm.us-east-1.amazonaws.com
x-amz-date:20200703T150846Z
x-amz-security-token:...
x-amz-target:CertificateManager.ExportCertificate
content-type;host;x-amz-date;x-amz-security-token;x-amz-target...
2020-07-03 11:08:46,672 - MainThread - botocore.auth - DEBUG - StringToSign:
AWS4-HMAC-SHA256
20200703T150846Z
20200703/us-east-1/acm/aws4_request
234bb7f55154882f423248fe8ebab87ceec5494a4e4a0145e1fdbc806f8fe56d
2020-07-03 11:08:46,672 - MainThread - botocore.auth - DEBUG - Signature:
3314dcebd73eed613a4b3b51a51f3abdbcf87d6a99295c498c7a1974a22ce420
2020-07-03 11:08:46,672 - MainThread - botocore.endpoint - DEBUG - Sending http request: <AWSPreparedRequest stream_output=False, method=POST, url=https://acm.us-east-1.amazonaws.com/, headers={'X-Amz-Target': b'CertificateManager.ExportCertificate', 'Content-Type': b'application/x-amz-json-1.1', 'User-Agent': b'aws-cli/2.0.27 Python/3.7.4 Darwin/19.4.0 botocore/2.0.0dev31', 'X-Amz-Date': b'20200703T150846Z', 'X-Amz-Security-Token': b'...', 'Authorization': b'AWS4-HMAC-SHA256 Credential=.../.../us-east-1/acm/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-security-token;x-amz-target, Signature=...', 'Content-Length': '139'}>
2020-07-03 11:08:46,672 - MainThread - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): acm.us-east-1.amazonaws.com:443
2020-07-03 11:08:47,101 - MainThread - urllib3.connectionpool - DEBUG - https://acm.us-east-1.amazonaws.com:443 "POST / HTTP/1.1" 200 4724
2020-07-03 11:08:47,101 - MainThread - botocore.parsers - DEBUG - Response headers: {'x-amzn-RequestId': '22bcc268-f604-4b5b-99bb-0eb516d44793', 'Content-Type': 'application/x-amz-json-1.1', 'Content-Length': '4724', 'Date': 'Fri, 03 Jul 2020 15:08:46 GMT'}
2020-07-03 11:08:47,101 - MainThread - botocore.parsers - DEBUG - Response body:
b'{"Certificate":"-----BEGIN CERTIFICATE-----\\n...\\n-----END ENCRYPTED PRIVATE KEY-----\\n"}'
2020-07-03 11:08:47,102 - MainThread - botocore.hooks - DEBUG - Event needs-retry.acm.ExportCertificate: calling handler <bound method RetryHandler.needs_retry of <botocore.retries.standard.RetryHandler object at 0x7fede86c4ed0>>
2020-07-03 11:08:47,102 - MainThread - botocore.retries.standard - DEBUG - Not retrying request.
2020-07-03 11:08:47,103 - MainThread - botocore.hooks - DEBUG - Event after-call.acm.ExportCertificate: calling handler <bound method RetryQuotaChecker.release_retry_quota of <botocore.retries.standard.RetryQuotaChecker object at 0x7fede86c4a90>>
2020-07-03 11:08:47,103 - MainThread - awscli.formatter - DEBUG - RequestId: 22bcc268-f604-4b5b-99bb-0eb516d44793
$ openssl rsa -in private_key_enc.txt -out private_key.txt
Enter pass phrase for private_key_enc.txt: (testing123)
unable to load Private Key
4533018220:error:06FFF064:digital envelope routines:CRYPTO_internal:bad decrypt:/AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-47.100.4/libressl-2.8/crypto/evp/evp_enc.c:526:
4533018220:error:23FFF074:PKCS12 routines:func(4095):pkcs12 cipherfinal error:/AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-47.100.4/libressl-2.8/crypto/pkcs12/p12_decr.c:103:
4533018220:error:23FFF075:PKCS12 routines:func(4095):pkcs12 pbe crypt error:/AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-47.100.4/libressl-2.8/crypto/pkcs12/p12_decr.c:133:
4533018220:error:09FFF00D:PEM routines:CRYPTO_internal:ASN1 lib:/AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-47.100.4/libressl-2.8/crypto/pem/pem_pkey.c:143:
Additional context
I was able to successfully export the certificate via the UI with the same passcode, save the encoded key to a file, and run openssl rsa with the same inputs.
Hi @motzyball,
I'm not very familiar with the ACM. I note that it looks like you are following the examples from here:
https://docs.aws.amazon.com/acm/latest/userguide/gs-acm-export-private.html
I only note that your jq processing is different - the example shows how to generate a PEM file. Can you confirm that this method also does not work?
aws acm export-certificate \
--certificate-arn arn:aws:acm:region:account:certificate/12345678-1234-1234-1234-123456789012 \
--passphrase file://path-to-passphrase-file \
| jq -r '"\(.Certificate)\(.CertificateChain)\(.PrivateKey)"'
I have exactly the same issue, bug is reproducible - either with the commandline from aws docs or like motzyball did. No difference.
aws-cli/2.0.8 Python/3.7.4 Darwin/19.6.0 botocore/2.0.0dev12 OSX 10.15.6
+1. This made me have a very sad day
Not alone, Jeff. All of us are the same.
Possibly worthwhile: isolation of R value via decryption white protocol for 5-I encryption and AWS private keys only.
Hang in there.
R.
On 19 Aug 2020, at 6:46 AM, Jeff Webb [email protected] wrote:
+1. This made me have a very sad day
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.
Hi @motzyball, @jwebb-upc - I was able to reproduce both on Mac and Ubuntu with the same error. I'm going to have to check with the ACM team. I can't give you an ETA on when I'll get a response.
README for 2.0.8o range of Python states offline sup'port for 3.7.4 Darwin OSo will be maintained for 18-months. It seems the CABi .NET CAD forces the tools to split segments of board independent of the motherboard, mainframe, and logics.
The README seems to be quite poorly written and rushed. Uniting the split segments and installing new tools could be possible if updatEd script sent to installer(s).
R.
Sent from my iPhone
On 19 Aug 2020, at 8:57 AM, Kenneth Daily [email protected] wrote:
Hi @motzyball, @jwebb-upc - I was able to reproduce both on Mac and Ubuntu with the same error. I'm going to have to check with the ACM team. I can't give you an ETA on when I'll get a response.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
Workaround: Do not use special characters in private key password
After fighting these same openssl errors, I narrowed it down to an issue with the characters used for the password to protect the private key. When I set the private key password to: aaaa, I was able to successfully decrypt the private key using the supplied command (openssl rsa -in private_key.txt -out private_key.out). 20-character alphanumeric strings also worked for me, so I proceeded to include symbols.
# was a show-stopper, resulting in the same errors posted by @motzyball , and I doubt it's the only problematic special character.
Thanks for the added detail, @sc2pyro!
Hi @motzyball @sc2pyro @jwebb-upc,
This one made my head hurt too. After conferring with a number of folks, I think that it's an issue with how the openssl is writing out after encrypting. I could get it to work with this simple change:
--passphrase $(echo -n 'abcd1234' | openssl base64 -e)
or even more simply:
--passphrase $(echo -n 'abcd1234' | base64)
So, the full command is:
aws2 acm export-certificate --certificate-arn arn:aws:acm:us-west-2:968989450063:certificate/b093a45a-4f9d-47f0-80f6-ba02b6b828ae --passphrase $(echo -n 'abcd1234' | openssl base64 -e) | jq -r '"\(.PrivateKey)"' > export.txt
I could reproduce this error by (accidentally, of course) introducing new lines into a passphrase file and then passing it in as a file:// parameter to --passphrase. I suppose something similar is going on here, using echo -n suppresses new lines.
One thing to take care with the AWS CLI v2 is the change for handling blobs. Read more here:
https://docs.aws.amazon.com/cli/latest/userguide/cliv2-migration.html#cliv2-migration-binaryparam
I created a passphrase file:
$cat /etc/pki/tls/private/server.passphrase
abcd1234
I exported the certificate using the following approaches:
$aws acm export-certificate --certificate-arn arn:aws:acm:ca-central-1:REDACTED:certificate/REDACTED --passphrase fileb:///etc/pki/tls/private/server.passphrase | jq -r '"\(.Certificate)\(.CertificateChain)\(.PrivateKey)"' > /tmp/cert.pem
$aws acm export-certificate --certificate-arn arn:aws:acm:ca-central-1:REDACTED:certificate/REDACTED --passphrase file:///etc/pki/tls/private/server.passphrase | jq -r '"\(.Certificate)\(.CertificateChain)\(.PrivateKey)"' > /tmp/cert2.pem
$aws acm export-certificate --certificate-arn arn:aws:acm:ca-central-1:REDACTED:certificate/REDACTED --passphrase $(cat /etc/pki/tls/private/server.passphrase) | jq -r '"\(.Certificate)\(.CertificateChain)\(.PrivateKey)"' > /tmp/cert3.pem
It seems that the last method is the only one that works
$openssl rsa -in /tmp/cert.pem -passin file:/etc/pki/tls/private/server.passphrase
unable to load Private Key
139811980765088:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:evp_enc.c:592:
139811980765088:error:23077074:PKCS12 routines:PKCS12_pbe_crypt:pkcs12 cipherfinal error:p12_decr.c:108:
139811980765088:error:2306A075:PKCS12 routines:PKCS12_item_decrypt_d2i:pkcs12 pbe crypt error:p12_decr.c:139:
139811980765088:error:0907B00D:PEM routines:PEM_READ_BIO_PRIVATEKEY:ASN1 lib:pem_pkey.c:141:
$openssl rsa -in /tmp/cert2.pem -passin file:/etc/pki/tls/private/server.passphrase
unable to load Private Key
140003483088800:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:evp_enc.c:592:
140003483088800:error:23077074:PKCS12 routines:PKCS12_pbe_crypt:pkcs12 cipherfinal error:p12_decr.c:108:
140003483088800:error:2306A075:PKCS12 routines:PKCS12_item_decrypt_d2i:pkcs12 pbe crypt error:p12_decr.c:139:
140003483088800:error:0907B00D:PEM routines:PEM_READ_BIO_PRIVATEKEY:ASN1 lib:pem_pkey.c:141:
$openssl rsa -in /tmp/cert3.pem -passin file:/etc/pki/tls/private/server.passphrase
writing RSA key
-----BEGIN RSA PRIVATE KEY-----
REDACTED
-----END RSA PRIVATE KEY-----
It would seem that providing the passphrase using either "file://" or "fileb://" is not working as intended. Maybe I'm providing the passphrase incorrectly in the file but there is no guidance on how it should be stored. I tried passphrase files with a trailing new line and without a trailing new line.
@IyadKandalaft,
Here's what I did to use a file:
$ echo -n 'abcd1234' > /tmp/passphrase.txt
$ cat /tmp/passphrase.txt
abcd1234%
$ aws2 acm export-certificate --certificate-arn arn:aws:acm:us-west-2:ZZZZZZZZZZZZZ:certificate/ZZZZZZZZZ-8ae --passphrase fileb:///tmp/passphrase.txt | jq -r '"\(.Certificate)\(.CertificateChain)\(.PrivateKey)"' > export.txt
$ openssl rsa -in export.txt -out decr_private_key.txt
Enter pass phrase for export.txt:
writing RSA key
Note the % printing out to the console when I cated the file - opening this in vi shows that it has no EOL, and this is key.
@kdaily I don't think my files had a new lines but I'll double-check. I'm fairly sure I tried with and without newlines. I wasn't using echo to generate the files either but rather reading 20 chars from it and. I even tried manually using vim to create a passphrase file.
What version of the CLI are you running if you don't mind me asking.
@IyadKandalaft
aws2 --version
aws-cli/2.0.45 Python/3.7.4 Darwin/19.6.0 exe/x86_64
Another way to check:
$ file -k /tmp/passphrase.txt
/tmp/passphrase.txt: ASCII text, with no line terminators
Greetings! It looks like this issue hasn’t been active in longer than a week. We encourage you to check if this is still an issue in the latest release. Because it has been longer than a week since the last update on this, and in the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or add an upvote to prevent automatic closure, or if the issue is already closed, please feel free to open a new one.
This looks like it's still an issue, I'm seeing it on mac when using brew's latest openssl and going through apples libraries. This is part of our iac which is run in a docker container (ubuntu) which did work running on the exact same box, also worked on aws ec2 instance. So may be a mac issue and the above CRYPTO_internal:bad decrypt:/AppleInternal/BuildRoot/Library were identical. This was using our referencing our AWS CA building keys for a envoy ssl sidecar
certificate_arn=`aws ssm get-parameter --name "/blah/iac/{{ stack_env }}/certificate/blah.blah.local/arn" | jq '.Parameter.Value' -r`
passphrase=`openssl rand -base64 32`
aws acm export-certificate --certificate-arn "${certificate_arn}" --passphrase ${passphrase} | jq '"\(.Certificate)\(.CertificateChain)"' -r > cert.pem
aws acm export-certificate --certificate-arn "${certificate_arn}" --passphrase ${passphrase} | jq '.PrivateKey' -r > encrypted_key.pem
openssl rsa -in encrypted_key.pem -out key.pem -passin pass:${passphrase}
This is still an issue and confirmed by AWS premium support.
This is K. again from AWS premium support. I did run a few tests on my end and ran in to similar error message while trying to decrypt the key using CLI while on MAC terminal. I tried running the same commands from an EC2 instance and was able to successfully decrypt the encrypted private key.
Please reopen the ticket.
I got to work this way:
passphrase=$(uuidgen)
aws acm export-certificate --certificate-arn [CERTIFICATE_ARN] --passphrase $(echo -n $passphrase | base64) | jq -r .Certificate > certificate.pem
aws acm export-certificate --certificate-arn [CERTIFICATE_ARN] --passphrase $(echo -n $passphrase | base64) | jq -r .PrivateKey > private.pem
openssl rsa -in private.pem -out private.key -passin pass:$passphrase
I received some help from AWS support on this one and and got it to work by adding --cli-binary-format raw-in-base64-out:
aws acm export-certificate --certificate-arn [CERTIFICATE_ARN] --passphrase $passphrase --cli-binary-format raw-in-base64-out | jq -r .PrivateKey > private.pem
You can also add this flag to your profile to resolve other AWS CLI v2 breaking changes globally without requiring the flag, e.g.:
[some_profile]
cli_binary_format = raw-in-base64-out
--cli-binary-format doesn't work for me, at least not with a fileb passphrase source.