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

Add a way to get the peer certificate of a SSL Transport #66957

Closed
mathieui mannequin opened this issue Oct 30, 2014 · 9 comments
Closed

Add a way to get the peer certificate of a SSL Transport #66957

mathieui mannequin opened this issue Oct 30, 2014 · 9 comments
Labels
topic-asyncio type-feature A feature request or enhancement

Comments

@mathieui
Copy link
Mannequin

mathieui mannequin commented Oct 30, 2014

BPO 22768
Nosy @gvanrossum, @pitrou, @vstinner, @mathieui, @1st1
Files
  • peercert_bin.patch: simple patch adding a peercert_bin extra info to the transport
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2014-12-05.00:48:38.445>
    created_at = <Date 2014-10-30.18:18:56.146>
    labels = ['type-feature', 'invalid', 'expert-asyncio']
    title = 'Add a way to get the peer certificate of a SSL Transport'
    updated_at = <Date 2015-09-14.22:02:34.213>
    user = 'https://github.com/mathieui'

    bugs.python.org fields:

    activity = <Date 2015-09-14.22:02:34.213>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-12-05.00:48:38.445>
    closer = 'vstinner'
    components = ['asyncio']
    creation = <Date 2014-10-30.18:18:56.146>
    creator = 'mathieui'
    dependencies = []
    files = ['37076']
    hgrepos = []
    issue_num = 22768
    keywords = ['patch']
    message_count = 9.0
    messages = ['230281', '230282', '230284', '230287', '230319', '230333', '230334', '232167', '250707']
    nosy_count = 5.0
    nosy_names = ['gvanrossum', 'pitrou', 'vstinner', 'mathieui', 'yselivanov']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue22768'
    versions = ['Python 3.5']

    @mathieui
    Copy link
    Mannequin Author

    mathieui mannequin commented Oct 30, 2014

    Currently, the only workaround is to use transport._sock.getpeercert(True) on the Transport returned by loop.create_connection(), which is not something to be encouraged. It is useful to get such information, for example to perform a manual certificate check against a previously recorded certificate or hash.

    I attached a trivial patch adding an extra 'peercert_bin' info, but I do not know if this is the right approach, as other issues of feature disparity might arise when more people try to switch to asyncio. Exposing a proxy SSLSocket object for read-only functions might be more beneficial.

    @mathieui mathieui mannequin added topic-asyncio type-feature A feature request or enhancement labels Oct 30, 2014
    @pitrou
    Copy link
    Member

    pitrou commented Oct 30, 2014

    Thanks for the patch!

    other issues of
    feature disparity might arise when more people try to switch to asyncio.
    Exposing a proxy SSLSocket object for read-only functions might be
    more beneficial.

    I'm not sure that would make a difference. We still have to implement the proxy SSLSocket, which is no easier than adding the extra info by hand. Or did I misunderstand you?

    @mathieui
    Copy link
    Mannequin Author

    mathieui mannequin commented Oct 30, 2014

    I'm not sure that would make a difference. We still have to implement
    the proxy SSLSocket, which is no easier than adding the extra info by
    hand. Or did I misunderstand you?

    The difference would be that exposing methods can be more future-proof, as some methods take parameters (like the offender getpeercert(bool), or get_channel_binding() that takes an element of ssl.CHANNEL_BINDING_TYPES, list that may grow in the future) that need to be covered in the properties. But the API of SSLSocket is stable and small so I don't think it really matters.

    @pitrou
    Copy link
    Member

    pitrou commented Oct 30, 2014

    some methods take parameters (like the offender getpeercert(bool), or
    get_channel_binding() that takes an element of
    ssl.CHANNEL_BINDING_TYPES, list that may grow in the future) that need
    to be covered in the properties

    That's a good point. I don't have any strong feelings either way. Perhaps other people want to chime in?

    As for the patch, it will need to add a unit test as well.

    @gvanrossum
    Copy link
    Member

    Maybe

    transport.get_extra_info('socket').getpeercert(True)

    would be okay, no patch needed?

    On Thu, Oct 30, 2014 at 11:56 AM, Antoine Pitrou <report@bugs.python.org>
    wrote:

    Antoine Pitrou added the comment:

    > some methods take parameters (like the offender getpeercert(bool), or
    > get_channel_binding() that takes an element of
    > ssl.CHANNEL_BINDING_TYPES, list that may grow in the future) that need
    > to be covered in the properties

    That's a good point. I don't have any strong feelings either way. Perhaps
    other people want to chime in?

    As for the patch, it will need to add a unit test as well.

    ----------
    stage: -> patch review
    versions: +Python 3.5 -Python 3.4


    Python tracker <report@bugs.python.org>
    <http://bugs.python.org/issue22768\>


    @mathieui
    Copy link
    Mannequin Author

    mathieui mannequin commented Oct 31, 2014

    Maybe
    transport.get_extra_info('socket').getpeercert(True)
    would be okay, no patch needed?

    Thanks, that indeed works; I don't know why I missed it while reading the source. Maybe the docs could use some clarification, though? (users are not supposed to know that _SelectorTransport is subclassed by _SelectorSslTransport, which thus gets the extra info of both)

    @pitrou
    Copy link
    Member

    pitrou commented Oct 31, 2014

    Maybe
    transport.get_extra_info('socket').getpeercert(True)
    would be okay, no patch needed?

    That will be problematic with bpo-22560. The clear-text socket object and the SSL object become unrelated, and it would be logical for get_extra_info('socket') to return the clear-text socket, so either a get_extra_info('ssl') would be needed, or we should expose the SSL properties directly as extra info members.

    @vstinner
    Copy link
    Member

    vstinner commented Dec 5, 2014

    Thanks, that indeed works; I don't know why I missed it while reading the source.

    Ok, it looks like we can close the issue.

    That will be problematic with bpo-22560.

    In this case, it should be discussed there.

    @vstinner
    Copy link
    Member

    In Python 3.5, it's no more possible to get the peer certificate as binary. See the issue bpo-25114 for a general fix.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-asyncio type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants