← 输入框|github.com|刷新
Skip to content

if check_hostname is true, context can't be used for server purposes #65224

Open

Description

@pitrou
BPO 21025
Nosy @pitrou, @giampaolo, @tiran, @dstufft

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 = None
created_at = <Date 2014-03-22.11:35:11.719>
labels = ['type-bug', 'library']
title = "if check_hostname is true, context can't be used for server purposes"
updated_at = <Date 2014-03-22.17:25:12.431>
user = 'https://github.com/pitrou'

bugs.python.org fields:

activity = <Date 2014-03-22.17:25:12.431>
actor = 'pitrou'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2014-03-22.11:35:11.719>
creator = 'pitrou'
dependencies = []
files = []
hgrepos = []
issue_num = 21025
keywords = []
message_count = 2.0
messages = ['214462', '214492']
nosy_count = 5.0
nosy_names = ['janssen', 'pitrou', 'giampaolo.rodola', 'christian.heimes', 'dstufft']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue21025'
versions = ['Python 3.4', 'Python 3.5']

Linked PRs

Activity

  1. pitrou commented on Mar 22, 2014

    @pitrou
    MemberAuthor

    On a SSLContext with check_hostname = True, calling wrap_socket(..., server_side=True) will complain that no server hostname has been passed. This should only be done for client sockets.

  2. added
    stdlib
    type-bug
    on Mar 22, 2014
  3. pitrou commented on Mar 22, 2014

    @pitrou
    MemberAuthor

    (of course, it may be better to have separate contexts for client and server use, but it can also be convenient to use a single context - especially when doing tests :-))

  4. transferred this issue fromon Apr 10, 2022
  5. photon-e commented on Feb 18, 2023

    @photon-e

    @ezio-melotti looks like this issue needs to be closed

  6. vasiliyk commented on Oct 24, 2026

    @vasiliyk
    Contributor

    This still reproduces on 3.16.0a1+dev:

    >>> import ssl
    ... ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
    ... ctx.check_hostname = True
    ... ctx.wrap_bio(ssl.MemoryBIO(), ssl.MemoryBIO(), server_side=True)
    
    Traceback (most recent call last):
    ...
    ValueError: check_hostname requires server_hostname

    The error message is misleading in server mode. I propose:

    • a server-specific error message like: "check_hostname cannot be used with server_side=True; disable check_hostname or use a separate server context".
    • SSLContext.check_hostname docs addition like: "Hostname checking applies only to client-side connections; a context with it enabled cannot be used with server_side=True, so use a separate context for servers."

    I'm happy to open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibtype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions