Skip to content

SSLSocket extra level of indirection #68522

Closed

Description

@tiran
BPO 24334
Nosy @pitrou, @giampaolo, @tiran, @alex, @vadmium, @dstufft
PRs
  • bpo-24334: Cleanup SSLSocket #5252
  • [3.7] bpo-24334: Cleanup SSLSocket (GH-5252) #5857
  • bpo-24334: Remove inaccurate match_hostname call #6211
  • [3.7] bpo-24334: Remove inaccurate match_hostname call (GH-6211) #6212
  • Files
  • no_sslobject.patch
  • 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 = 'https://github.com/tiran'
    closed_at = <Date 2018-02-24.20:52:43.134>
    created_at = <Date 2015-05-30.20:37:28.364>
    labels = ['3.7', 'expert-SSL', '3.8', 'type-bug', 'library']
    title = 'SSLSocket extra level of indirection'
    updated_at = <Date 2018-03-24.14:59:18.615>
    user = 'https://github.com/tiran'

    bugs.python.org fields:

    activity = <Date 2018-03-24.14:59:18.615>
    actor = 'christian.heimes'
    assignee = 'christian.heimes'
    closed = True
    closed_date = <Date 2018-02-24.20:52:43.134>
    closer = 'christian.heimes'
    components = ['Library (Lib)', 'SSL']
    creation = <Date 2015-05-30.20:37:28.364>
    creator = 'christian.heimes'
    dependencies = []
    files = ['39570']
    hgrepos = []
    issue_num = 24334
    keywords = ['patch']
    message_count = 9.0
    messages = ['244494', '244495', '246168', '246277', '312753', '312754', '312755', '314368', '314371']
    nosy_count = 8.0
    nosy_names = ['geertj', 'janssen', 'pitrou', 'giampaolo.rodola', 'christian.heimes', 'alex', 'martin.panter', 'dstufft']
    pr_nums = ['5252', '5857', '6211', '6212']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue24334'
    versions = ['Python 3.7', 'Python 3.8']

    Activity

    1. tiran commented on May 30, 2015

      @tiran
      MemberAuthor

      I just noticed that bpo-21965 has added an extra level of indirection to the SSLSocket object. In Python 3.4 and earlier the ssl.SSLSocket object has one level of indirection:

      >>> import ssl
      >>> ctx = ssl.create_default_context()
      >>> sock = ssl.create_connection(('www.python.org', 443))
      >>> ssock = ctx.wrap_socket(sock, server_hostname='www.python.org')
      >>> ssock
      <ssl.SSLSocket fd=3, family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, proto=6, laddr=('192.168.7.122', 39657), raddr=('185.31.17.223', 443)>
      >>> ssock._sslobj
      <_ssl._SSLSocket object at 0x7efcb9fd8c00>

      In 3.5 an additional level comes into play:

      >>> import ssl
      >>> ctx = ssl.create_default_context()
      >>> sock = ssl.create_connection(('www.python.org', 443))
      >>> ssock = ctx.wrap_socket(sock, server_hostname='www.python.org')
      >>> ssock
      <ssl.SSLSocket fd=3, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('192.168.7.122', 39664), raddr=('185.31.17.223', 443)>
      >>> ssock._sslobj
      <ssl.SSLObject object at 0x7fa55a96bb00>
      >>> ssock._sslobj._sslobj
      <_ssl._SSLSocket object at 0x7fa5506918a0>

      Method calls like SSLSocket.read() now call SSLObject.read(), which call _SSLSocket.read(). That seems a bit excessive. Isn't there a better way with less indirections?

      I have created a proof-of-concept patch that removes the extra layer with some code duplication. Maybe the common code can be moved into a commmon base class for SSLObject and SSLSocket? After all both classes provide a similar interface.

    2. added
      stdlib
      type-bug
      on May 30, 2015
    3. pitrou commented on May 30, 2015

      @pitrou
      Member

      I'm nosying Geert, who is the original author of the SSLObject code.

    4. geertj commented on Jul 3, 2015

      geertjmannequin
      Mannequin

      Apologies for the late reply.

      I made SSLSocket go through SSLObject so that the test suite that is primarily testing SSLSocket will test both.

      Also, this layering allows us to define some non-networked operations (such as SSL certificate checking and channel binding types) in a single location rather than duplicating them between SSLSocket and SSLObject.

    5. pitrou commented on Jul 4, 2015

      @pitrou
      Member

      I made SSLSocket go through SSLObject so that the test suite that is primarily testing SSLSocket will test both.

      Indeed, I like the fact it makes test coverage broader.

      Of course, if there's another way to get such coverage without duplicating lots of code, then why not.

    6. self-assigned this
      on Sep 15, 2016
    7. tiran commented on Feb 24, 2018

      @tiran
      MemberAuthor

      New changeset 141c5e8 by Christian Heimes in branch 'master':
      bpo-24334: Cleanup SSLSocket (bpo-5252)
      141c5e8

    8. tiran commented on Feb 24, 2018

      @tiran
      MemberAuthor

      New changeset 8fa8478 by Christian Heimes (Miss Islington (bot)) in branch '3.7':
      [3.7] bpo-24334: Cleanup SSLSocket (GH-5252) (bpo-5857)
      8fa8478

    9. tiran commented on Feb 24, 2018

      @tiran
      MemberAuthor

      Thanks for your review, Antoine!

    10. tiran commented on Mar 24, 2018

      @tiran
      MemberAuthor

      New changeset e42ae91 by Christian Heimes in branch 'master':
      bpo-24334: Remove inaccurate match_hostname call (bpo-6211)
      e42ae91

    11. tiran commented on Mar 24, 2018

      @tiran
      MemberAuthor

      New changeset 1a0bb62 by Christian Heimes (Miss Islington (bot)) in branch '3.7':
      [3.7] bpo-24334: Remove inaccurate match_hostname call (GH-6211) (bpo-6212)
      1a0bb62

    12. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    3.7 (EOL)3.8 (EOL)stdlibtopic-SSLtype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions