Add OpenSSL.crypto.verify_cert method.

This change adds support for verifying a certificate or a certificate
chain. This implementation uses OpenSSL's underlying X509_STORE_CTX_*
class of functions to accomplish this.

This change also adds an intermediate signing certificate/key and a
service certificate/key signed with the intermediate signing
certificate, to make testing the OpenSSL.crypto.verify_chain method
easier to test. I figured I would add it to the top level module so
other people can use an intermediate signing certificate in their own
tests.

Issue: https://github.com/pyca/pyopenssl/issues/154
That is almost certainly the unittest module covering up an `ImportError`;
I suspect `test_crypto` imports `X509StoreContextType`.

On Tue, Sep 23, 2014 at 9:34 PM, Stephen Holsapple <notifications@github.com
> wrote:

> In OpenSSL/crypto.py:
>
> > @@ -1357,6 +1359,18 @@ def add_cert(self, cert):
> >
> >
> >
> > +class X509StoreContext(object):
> > +
> > +    def __init__(self, store, cert):
> > +        store_ctx = _lib.X509_STORE_CTX_new()
> > +        self._store_ctx = _ffi.gc(store_ctx, _lib.X509_STORE_CTX_free)
> > +        _lib.X509_STORE_CTX_init(store_ctx, store._store, cert._x509, _ffi.NULL)
> > +
> > +
> > +X509StoreContextType = X509StoreContext
>
> I'm not entirely sure why yet, but when I remove this, the following
> explosions happen. I'm going to leave this in here for now unless you know
> of a way to fix it.
>
> $ python setup.py test
> running test
> running egg_info
> writing dependency_links to pyOpenSSL.egg-info/dependency_links.txt
> writing requirements to pyOpenSSL.egg-info/requires.txt
> writing pyOpenSSL.egg-info/PKG-INFO
> writing top-level names to pyOpenSSL.egg-info/top_level.txt
> reading manifest file 'pyOpenSSL.egg-info/SOURCES.txt'
> reading manifest template 'MANIFEST.in'
> warning: no files found matching 'README'
> warning: no previously-included files matching '*.pyc' found anywhere in distribution
> no previously-included directories found matching 'doc/_build'
> writing manifest file 'pyOpenSSL.egg-info/SOURCES.txt'
> running build_ext
> Traceback (most recent call last):
>   File "setup.py", line 75, in <module>
>     test_suite="OpenSSL")
>   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 152, in setup
>     dist.run_commands()
>   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands
>     self.run_command(cmd)
>   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
>     cmd_obj.run()
>   File "/Users/sholsapp/.virtualenvs/pyopenssl/lib/python2.7/site-packages/setuptools/command/test.py", line 138, in run
>     self.with_project_on_sys_path(self.run_tests)
>   File "/Users/sholsapp/.virtualenvs/pyopenssl/lib/python2.7/site-packages/setuptools/command/test.py", line 118, in with_project_on_sys_path
>     func()
>   File "/Users/sholsapp/.virtualenvs/pyopenssl/lib/python2.7/site-packages/setuptools/command/test.py", line 164, in run_tests
>     testLoader = cks
>   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/main.py", line 94, in __init__
>     self.parseArgs(argv)
>   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/main.py", line 149, in parseArgs
>     self.createTests()
>   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/main.py", line 158, in createTests
>     self.module)
>   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 128, in loadTestsFromNames
>     suites = [self.loadTestsFromName(name, module) for name in names]
>   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 103, in loadTestsFromName
>     return self.loadTestsFromModule(obj)
>   File "/Users/sholsapp/.virtualenvs/pyopenssl/lib/python2.7/site-packages/setuptools/command/test.py", line 35, in loadTestsFromModule
>     tests.append(self.loadTestsFromName(submodule))
>   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 103, in loadTestsFromName
>     return self.loadTestsFromModule(obj)
>   File "/Users/sholsapp/.virtualenvs/pyopenssl/lib/python2.7/site-packages/setuptools/command/test.py", line 35, in loadTestsFromModule
>     tests.append(self.loadTestsFromName(submodule))
>   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 100, in loadTestsFromName
>     parent, obj = obj, getattr(obj, part)
> AttributeError: 'module' object has no attribute 'test_crypto'
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/pyca/pyopenssl/pull/155/files#r17953792>.
>



-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." -- Evelyn Beatrice Hall (summarizing Voltaire)
"The people's good is the highest law." -- Cicero
GPG Key fingerprint: 125F 5C67 DFE9 4084