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

asyncio.open_connection returns a closed client when server fails to authenticate client certificate #83375

Open
JonathanMartin mannequin opened this issue Jan 2, 2020 · 3 comments
Labels
3.8 only security fixes 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes topic-asyncio type-bug An unexpected behavior, bug, or error

Comments

@JonathanMartin
Copy link
Mannequin

JonathanMartin mannequin commented Jan 2, 2020

BPO 39194
Nosy @tiran, @asvetlov, @1st1
Files
  • example_code.py
  • 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 2020-01-02.15:09:12.015>
    labels = ['type-bug', '3.8', '3.9', '3.10', '3.11', 'expert-asyncio']
    title = 'asyncio.open_connection returns a closed client when server fails to authenticate client certificate'
    updated_at = <Date 2021-04-21.06:36:33.422>
    user = 'https://bugs.python.org/JonathanMartin'

    bugs.python.org fields:

    activity = <Date 2021-04-21.06:36:33.422>
    actor = 'christian.heimes'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['asyncio']
    creation = <Date 2020-01-02.15:09:12.015>
    creator = 'Jonathan Martin'
    dependencies = []
    files = ['48824']
    hgrepos = []
    issue_num = 39194
    keywords = []
    message_count = 2.0
    messages = ['359200', '391489']
    nosy_count = 4.0
    nosy_names = ['christian.heimes', 'asvetlov', 'yselivanov', 'Jonathan Martin']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue39194'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10', 'Python 3.11']

    @JonathanMartin
    Copy link
    Mannequin Author

    JonathanMartin mannequin commented Jan 2, 2020

    I'm trying to use SSL to validate clients connecting a an asyncio socket server by specifying CERT_REQUIRED and giving a cafile containing the client certificate to allow. client and server code attached.

    Certificates are generated with:

    openssl req -x509 -newkey rsa:2048 -keyout client.key -nodes -out client.cert -sha256 -days 100

    openssl req -x509 -newkey rsa:2048 -keyout server.key -nodes -out server.cert -sha256 -days 100

    Observed behavior with python 3.7.5 and openSSL 1.1.1d
    ------------------------------------------------------

    When the client tries to connect without specifying a certificate, the call to asyncio.open_connection succeeds, but the received socket is closed right away, or to be more exact an EOF is received.

    Observed behavior with python 3.7.4 and openSSL 1.0.2t
    ------------------------------------------------------

    When the client tries to connect without specifying a certificate, the call to asyncio.open_connection fails.

    Expected behavior
    -----------------

    I'm not sure which behavior is to be considered the expected one, although I would prefer to connection to fail directly instead of returning a dead client. Wouldn't it be better to have only one behavior?

    Note that when disabling TLSv1.3, the connection does fail to open:
    ctx.maximum_version = ssl.TLSVersion.TLSv1_2

    This can be reproduces on all latest releases of 3.6, 3.7, and 3.8 (which all have openssl 1.1.1d in my case)

    @JonathanMartin JonathanMartin mannequin assigned tiran Jan 2, 2020
    @JonathanMartin JonathanMartin mannequin added topic-SSL 3.7 (EOL) end of life 3.8 only security fixes topic-asyncio labels Jan 2, 2020
    @JonathanMartin JonathanMartin mannequin assigned tiran Jan 2, 2020
    @JonathanMartin JonathanMartin mannequin added type-bug An unexpected behavior, bug, or error topic-SSL 3.7 (EOL) end of life 3.8 only security fixes topic-asyncio labels Jan 2, 2020
    @tiran
    Copy link
    Member

    tiran commented Apr 21, 2021

    I'm unassigning myself. This seems to be an asyncio-specific behavior.

    @tiran tiran added 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes and removed topic-SSL 3.7 (EOL) end of life labels Apr 21, 2021
    @tiran tiran removed their assignment Apr 21, 2021
    @tiran tiran added 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes and removed topic-SSL 3.7 (EOL) end of life labels Apr 21, 2021
    @tiran tiran removed their assignment Apr 21, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @RouquinBlanc
    Copy link

    This is still the case in python 3.9 and 3.10. Until now we are using the following option to go around the issue:

        sc = ssl.create_default_context(...)
        sc.options |= ssl.OP_NO_TLSv1_3

    But in python 3.10 the use of this flag is deprecated...

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes topic-asyncio type-bug An unexpected behavior, bug, or error
    Projects
    Status: Todo
    Development

    No branches or pull requests

    2 participants