Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

SSLContext.load_verify_locations accepts some cases of trailing data in DER #100372

Closed
Labels
stdlibStandard Library Python modules in the Lib/ directorytopic-SSLtype-bugAn unexpected behavior, bug, or error
@davidben

Description

@davidben

Bug report

SSLContext.load_verify_locations detects EOF by looking forPEM_R_NO_START_LINE andASN1_R_HEADER_TOO_LONG in PEM and DER, respectively. The former is correct. PEM allows arbitrary trailing data before and after and the OpenSSL API involveslooking for that particular error code.

ASN1_R_HEADER_TOO_LONG, however doesn't appear anywhere in OpenSSL's documentation and isn't the right way to detect EOF for a sequence of DER elements. It's signaled whenever there weren't enough bytes to read a full ASN.1 header. That could be because of EOF, but it could also be there was one byte, or any other truncated ASN.1 header. (It could also happen inside a deeply nested ASN.1 structure, but OpenSSL happens to pushERR_R_NESTED_ASN1_ERROR in that case, so that case doesn't confuse CPython.)

To repro, add this test totest_load_verify_cadata. It should fail.

       with self.assertRaises(ssl.SSLError):           ctx.load_verify_locations(cadata=cacert_der + b"A")

The fix is instead to stop atBIO_eof for DER, as there's no need to skip surrounding data. I'll upload a PR shortly to do that.

Your environment

  • CPython versions tested on: main
  • Operating system and architecture: Linux, x86_64

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-SSLtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp