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
Add options to write lightweight CA cert or chain to file #177
Add options to write lightweight CA cert or chain to file #177
Conversation
0804716
to
6c938c6
Compare
|
The original review thread is available at: https://www.redhat.com/archives/freeipa-devel/2016-October/msg00578.html |
|
Bump for review |
6c938c6
to
0706cef
Compare
|
pylint fails: |
|
|
||
| """ | ||
| cmd = [ | ||
| paths.OPENSSL, "pkcs7", "-print_certs", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you forgot to add from ipaplatform.paths import paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, the import was removed in a refactoring commit and didn't notice because patch rebased cleanly :) fixed in latest update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import was removed for a reason, putting it back will break the ipalib package on PyPI.
Now that we require pyasn1_modules, we can use PyASN1 to do the parsing instead:
if datatype == PEM:
match = re.search(r'-----BEGIN PKCS7-----(.*?)-----END PKCS7-----', data, re.DOTALL)
if not match:
raise ValueError()
data = base64.b64decode(match.group(1))
ci, _rest = decoder.decode(data, rfc2315.ContentInfo())
if ci['contentType'] != rfc2315.ContentType('1.2.840.113549.1.7.2'):
raise ValueError()
data = str(ci['content'])
sd, _rest = decoder.decode(data, rfc2315.SignedData())
certs = [encoder.encode(c['certificate']) for c in sd['certificates']]
return certs| @@ -290,7 +285,7 @@ def import_files(self, files, db_password_filename, import_keys=False, | |||
| filename, line, e) | |||
| continue | |||
| else: | |||
| extracted_certs += result.output + '\n' | |||
| extracted_certs += '\n'.join(certs) + '\n' | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line is ugly. Please convert extracted_certs to a list, append/extend the list and perform '\n\.join(extracted_certs) at the end of the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a separate commit for this refactor.
| subid += 1 | ||
| for cert in certlist: | ||
| try: | ||
| (chain_fd, chain_name) = tempfile.mkstemp() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor style nit-pick: The parenthesis are unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in latest update.
0706cef
to
ea4b283
Compare
|
Please update the xmlrpc tests to reflect the extra certificate attributes (~12 failed tests in There are also a couple tests failing with ACIError: ACIError: Insufficient access: Principal 'srv/santest-host-1...' is not permitted to use CA 'default-profile-subca' with profile 'caIPAserviceCert' for certificate issuance. I also found the |
|
@tomaskrizek thanks for reviewing. Updated tests and change the |
ea4b283
to
e574e55
Compare
|
To continue the discussion from the mailing list:
What I actually meant is that
This does not scale well - if a new unrelated attribute is added to the CA LDAP entry, or if a new param is added to the CA object,
Pythonistas, I believe :) |
e574e55
to
f049751
Compare
|
@jcholast thanks for review. PR updated. No longer inheriting |
|
Never mind... my |
f049751
to
104e7f3
Compare
|
@jcholast OK there we go. I'd forgotten to remove the |
104e7f3
to
38973fc
Compare
| 'chain', | ||
| default=False, | ||
| doc=_('Include certificate chain in output'), | ||
| ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we get rid of this copy-pasta? Maybe like this:
_chain_flag = Flag(
'chain',
doc=_('Include certificate chain in output'),
)
...
takes_options = LDAPCreate.takes_options + (
_chain_flag,
)(Also note that all flags implicitly have default value of False.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meet you halfway: yes to de-dup; no to deferring to default value. Explicit is better than implicit :)
|
Could you make Also see inline comments. |
38973fc
to
fad6ebe
Compare
|
@jcholast returning cert and chain in |
|
@frasertweedale, yep, I'm aware of that - |
|
@jcholast updated PR to include |
fad6ebe
to
eb4a4b1
Compare
|
@frasertweedale, thanks. What about this? |
|
On Sun, Dec 11, 2016 at 10:36:27PM -0800, Jan Cholasta wrote:
@frasertweedale, thanks. What about [this](https://github.com/freeipa/freeipa/pull/177/files#r91243228)?
It is a worthwhile change (thank you for reminding me).
Let's address any remaining issues for this feature and get it
merged. The proposed PKCS #7 refactoring can be tacked separately.
I filed a ticket https://fedorahosted.org/freeipa/ticket/6550
Thanks.
… --
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#177 (comment)
|
|
@frasertweedale, I'm afraid we can't do that. As I said in the comment, you cannot unconditionally import from try:
from ipaplatform.paths import paths
except ImportError:
OPENSSL = '/usr/bin/openssl'
else:
OPENSSL = paths.OPENSSL |
Add a single function for extracting X.509 certs in PEM format from a PKCS freeipa#7 object. Refactor sites that execute ``openssl pkcs7`` to use the new function. Part of: https://fedorahosted.org/freeipa/ticket/6178
certdb.NSSDatabase.import_files currently accumulates certificates extracted from input files as a string, which is ugly. Accumulate a list of PEMs instead, and join() them just in time for PKCS freeipa#12 creation. Part of: https://fedorahosted.org/freeipa/ticket/6178
Administrators need a way to retrieve the certificate or certificate chain of an IPA-managed lightweight CA. Add params to the `ca' object for carrying the CA certificate and chain (as multiple DER values). Add the `--chain' flag for including the chain in the result (chain is also included with `--all'). Add the `--certificate-out' option for writing the certificate to a file (or the chain, if `--chain' was given). Fixes: https://fedorahosted.org/freeipa/ticket/6178
eb4a4b1
to
9364b5d
Compare
|
@jcholast right you are. PR updated with conditional import. Thanks. |
|
@jcholast @frasertweedale I hope you did notice those failures in Travis CI before acking/pushing... |
Administrators need a way to retrieve the certificate or certificate
chain of an IPA-managed lightweight CA. Add params to the
ca' object for carrying the CA certificate and chain (as multiple DER values), and add the--certificate-out' option and `--chain' flagas client-side options for writing one or the other to a file.
Fixes: https://fedorahosted.org/freeipa/ticket/6178