Bug 876423 - Incorrect X509 Extension parsing results in "TypeError: argument of type 'NoneType' is not iterable" in _is_valid_download_url()
Summary: Incorrect X509 Extension parsing results in "TypeError: argument of type 'Non...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Update Infrastructure for Cloud Providers
Classification: Red Hat
Component: RHUA
Version: 2.1
Hardware: Unspecified
OS: Unspecified
high
high
Target Milestone: ---
: 2.1.1
Assignee: James Slagle
QA Contact: mkovacik
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-11-14 04:26 UTC by Nigel Jones
Modified: 2018-12-01 17:49 UTC (History)
8 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Incorrect parsing logic removed valid data from entitlement certificate's OID values and caused the import of entitlement certificates to fail with traceback errors. This patch prevents the removal of valid data. Certificates now import without issue.
Clone Of:
Environment:
Last Closed: 2013-02-27 16:59:59 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
Reproducer screen log (3.94 KB, text/plain)
2013-02-04 15:52 UTC, mkovacik
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2013:0571 0 normal SHIPPED_LIVE Red Hat Update Infrastructure 2.1.1 bug fix update 2013-02-27 21:58:22 UTC

Description Nigel Jones 2012-11-14 04:26:17 UTC
Description of problem:
Parsing of customer's X509 candlepin certificates in RHUI's /usr/lib/python2.6/site-packages/rhui/common/certificate.py Extensions class results in the traceback/errors in rhui.log:

Unexpected error caught at the shell level
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/rhui/tools/shell.py", line 86, in safe_listen
    self.listen(clear=first_run)
  File "/usr/lib/python2.6/site-packages/rhui/tools/shell.py", line 112, in listen
    Shell.listen(self)
  File "/usr/lib/python2.6/site-packages/rhui/common/shell.py", line 186, in listen
    item.func(*args, **item.kwargs)
  File "/usr/lib/python2.6/site-packages/rhui/tools/screens/entitlements.py", line 104, in new_certificate
    self.cert_manager.add_certificate(cert_filename)
  File "/usr/lib/python2.6/site-packages/rhui/tools/cert_manager.py", line 276, in add_certificate
    if not _is_valid_download_url(e.download_url):
  File "/usr/lib/python2.6/site-packages/rhui/tools/cert_manager.py", line 301, in _is_valid_download_url
    if valid_url in download_url:
TypeError: argument of type 'NoneType' is not iterable

Version-Release number of selected component (if applicable):
rh-rhui-tools-2.1.13-1.el6_3.noarch

How reproducible:
100% with affected certs

Steps to Reproduce:
1. Generate a certificate from RH Customer Portal
2. Check if the certificate will be affected by the bug - "openssl x509 -in <path to .pem> -text -noout" - look for OID values which are solely '..' - x509.as_text() will show it has the value '..\n'.
3. Attempt to 'upload' the certificate to RHUA
  
Actual results:
Failure with above traceback

Expected results:
Successful import

Additional info:
The issue comes down to the __ext function in the Extensions class which reads:

    def __ext(self, x509):
        # get extensions substring
        text = x509.as_text()
        start = text.find('extensions:')
        end = text.rfind('Signature Algorithm:')
        text = text[start:end]
        text = text.replace('.\n', '..')
        return [s.strip() for s in text.split('\n')]

Since both '.\n\n' and '..\n' are valid  OID values, we have an issue, because the text.replace('.\n', '..') matches both instances, and makes the latter '...\n', this creates an issue in that the next OID may merge into the value for the previous OID.

By changing it on the customer's RHUI to text.replace(' .\n', ' ..'), we have worked around the issue for now.

Comment 2 James Slagle 2012-11-14 14:19:23 UTC
aligned against our 2.1.1 release

Comment 3 James Slagle 2012-11-29 21:08:38 UTC
patch looks good to me, i can't think of a better way to do it.  Thanks for the detailed work debugging this issue.

commit cc0c060c832e2f04390196d496690b3e5d1ca07a

Comment 4 mkovacik 2012-12-13 10:37:59 UTC
Hi,

I'm not sure about the test automation here; generating a custom certificate in candlepin is outside of the scope for us and keeping the customer certificate as a test case data doesn't seem appropriate either. Any suggestions?

Thanks,
milan

Comment 5 James Slagle 2012-12-13 14:17:05 UTC
Does the automation test case need to actually verify that the certificate is valid, or just that it will parse correctly?  If it doesn't need to be verified, just modify an existing test certificate as this bug describes to exhibit the problem.  The certificate won't pass signature validation, but that's not really what needs to be tested here.

Other than that, I'm not sure how else to test this via automation.  I could probably add a unit test for the __ext method that tests the fix if needed.

Comment 6 mkovacik 2012-12-13 15:02:02 UTC
OK(In reply to comment #5)
> Does the automation test case need to actually verify that the certificate
> is valid, or just that it will parse correctly?  If it doesn't need to be
> verified, just modify an existing test certificate as this bug describes to
> exhibit the problem.  The certificate won't pass signature validation, but
> that's not really what needs to be tested here.
> 
> Other than that, I'm not sure how else to test this via automation.  I could
> probably add a unit test for the __ext method that tests the fix if needed.

I'll try to reproduce with a fabricated cert. If it "works" and I get the same stack as in report, no problem automating...

Thanks,
milan

Comment 7 Vitaly Kuznetsov 2013-02-04 15:49:09 UTC
[root@rhua ~]# rpm -q rh-rhui-tools
rh-rhui-tools-2.1.15-1.el6_3.noarch

[root@rhua ~]# rhui-manager cert upload --cert /root/bug876423_testcert.pem
The given certificate contains one or more entitlements that are
not compatible with the RHUI. For questions, please visit:
https://access.redhat.com/support/contact/customerService.html

Comment 8 mkovacik 2013-02-04 15:52:45 UTC
Created attachment 692849 [details]
Reproducer screen log

Attaching a reproducer (RHUI 2.1)

Comment 10 errata-xmlrpc 2013-02-27 16:59:59 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHBA-2013-0571.html


Note You need to log in before you can comment on or make changes to this bug.