Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openssl_pkcs12: Add idempotency checks #54633

Merged
merged 10 commits into from
Apr 10, 2019

Conversation

Shaps
Copy link
Contributor

@Shaps Shaps commented Mar 30, 2019

SUMMARY

Adds idempotency checks to the openssl_pkcs12 module and related tests.
Also decoupled parse and generate from the file write, as they are now used for multiple stuff that don't require the file to be written to disk.
Fixes #53221

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

openssl_pkcs12

@ansibot
Copy link
Contributor

ansibot commented Mar 30, 2019

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. community_review In order to be merged, this PR must follow the community review workflow. crypto Crypto community (ACME, openssl, letsencrypt) module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. test This PR relates to tests. labels Mar 30, 2019
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. needs_triage Needs a first human triage before being processed. labels Mar 30, 2019
@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Mar 30, 2019
@Shaps Shaps force-pushed the openssl_pkcs12_idempotency branch from a43b1fe to 910f4bb Compare March 30, 2019 19:41
if (pkcs12_other_certificates is not None) and (self.ca_certificates is not None):
expected_ca_certs = [crypto.dump_certificate(crypto.FILETYPE_PEM,
ca_cert) for ca_cert in self.pkcs12.get_ca_certificates()]
expected_ca_certs.append(crypto.dump_certificate(crypto.FILETYPE_PEM, self.pkcs12.get_certificate()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you include the current certificate in the set of CA certs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same reason as above

elif bool(pkcs12_other_certificates) != bool(self.ca_certificates):
return False

if not pkcs12_other_certificates:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this if for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that if the pkcs12 file has additional certs, the get_friendlyname method ( from parse ) returns None, making this fail unnecessarily. That said, I guess I could/should change this to be

not pkcs12_other_certificates and not pkcs12_friendly_name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that's even more strange. I'd say outright terrible :)

I've looked at the pyOpenSSL implementation of encoding and decoding PKCS12 files, it is essentially calling the OpenSSL functions from the other comment. The friendly name comes from the main cert extracted from the PKCS12 file, i.e. when the order is f**ked up, I would expect friendly_name to also be wrong.

@felixfontein
Copy link
Contributor

Also, you need a changelog fragment :)

@Shaps
Copy link
Contributor Author

Shaps commented Mar 30, 2019

YES :D

Also, you need a changelog fragment :)

@ansibot ansibot added stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. and removed stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Apr 8, 2019
Also decoupled the 'parse' and 'generate' function from the file write
as they are now used in different places that do not need the file to be
written to disk.
Also adds a new test for pkcs12 files with multiple certificates
ca_certificates is left as an alias to other_certificates;
friendlyname depends on private key, so it will be ignored while
checking for idempotency if the pkey is not set;
idempotency check only checks for correct certs in the stack
@Shaps Shaps force-pushed the openssl_pkcs12_idempotency branch from b171709 to c45f8d5 Compare April 10, 2019 08:58
@ansibot
Copy link
Contributor

ansibot commented Apr 10, 2019

@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. docs This issue/PR relates to or includes documentation. support:core This issue/PR relates to code supported by the Ansible Engineering Team. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Apr 10, 2019
Copy link
Contributor

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shipit

(sorry for using wrong account...)

@ansibot ansibot added shipit This PR is ready to be merged by Core and removed core_review In order to be merged, this PR must follow the core review workflow. labels Apr 10, 2019
@gundalow gundalow merged commit 0303ea2 into ansible:devel Apr 10, 2019
@gundalow
Copy link
Contributor

Thanks all!

@felixfontein
Copy link
Contributor

@Shaps thanks a lot for implementing this!!!
@gundalow thanks for merging!

@ansible ansible locked and limited conversation to collaborators Jul 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. crypto Crypto community (ACME, openssl, letsencrypt) docs This issue/PR relates to or includes documentation. module This issue/PR relates to a module. shipit This PR is ready to be merged by Core support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

openssl_pkcs12: idempotency check is not working
5 participants