ECDH accepts peer keys whose explicit curve parameters are malformed (order = 0, cofactor = n, no cofactor)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 76/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- cryptography
Hướng nghiên cứu
Start with ECDH.load_received_public_key_der() and the repro_pyecdsa_ecdh_params.py reproducer using the named Wycheproof Brainpool vectors. Trace where explicit curve parameters are matched to a known curve, then add validation for order and cofactor alongside regression tests for the listed invalid cases. The work is done when loading or exchanging rejects order 0, order 1, a missing cofactor, and a cofactor equal to the curve order.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Versions: python-ecdsa 0.19.2 (latest release), CPython 3.13.15.
What happens
ECDH.load_received_public_key_der() accepts a SubjectPublicKeyInfo with explicit (unnamed) curve parameters that
are malformed, and generate_sharedsecret_bytes() then returns a secret. Wycheproof testvectors_v1
ecdh_brainpoolP256r1_test.json (sha256 8502c0259d85813d93cba5a664245b2d5ad1cdd3480a77337f3b377b8d63ccf4) marks these cases invalid:
| tcId | comment | Wycheproof | python-ecdsa 0.19.2 |
|---|---|---|---|
| 545 | order = 0 | invalid | accepted |
| 551 | no cofactor | invalid | accepted |
| 553 | cofactor = n | invalid | accepted |
Across the five ecdh_brainpool* files: 5 "order = 0", 3 "no cofactor" and 3 "cofactor = n" invalid cases accepted.
The secret returned equals the correct one for the named curve, so we found no wrong result; the problem is that
parameters which are not a valid group description are accepted. It looks as if the explicit parameters are matched
to a known curve without comparing the order and cofactor fields.
Reproducer
repro_pyecdsa_ecdh_params.py (below): for each test case with one of those comments, load the private key on
brainpoolP256r1, load the peer key from its DER, exchange. Run as python repro_pyecdsa_ecdh_params.py ecdh_brainpoolP256r1_test.json.
Suggested fix
When explicit parameters are parsed, require the order and (if present) the cofactor to equal the matched curve's,
and reject an order of 0 or 1 outright.
repro_pyecdsa_ecdh_params.py
"""Minimal reproducer: python-ecdsa's ECDH accepts a peer public key whose explicit curve parameters are malformed
(order = 0, no cofactor, cofactor = n), cases Wycheproof marks "invalid".
Input: Wycheproof ecdh_brainpoolP256r1_test.json (C2SP/wycheproof testvectors_v1). For each test case with one of those
comments: load our private key on the named curve, load the peer key from its DER, and run the exchange.
Expected: loading or exchanging raises an error.
"""
import json
import pathlib
import sys
import ecdsa
from ecdsa import ECDH, SigningKey
from ecdsa.curves import BRAINPOOLP256r1
d = json.loads(pathlib.Path(sys.argv[1]).read_text())
print("python-ecdsa", ecdsa.__version__)
hits = 0
for g in d["testGroups"]:
for tc in g["tests"]:
if tc.get("comment") not in ("order = 0", "no cofactor", "cofactor = n"):
continue
sk = SigningKey.from_secret_exponent(int(tc["private"], 16) % BRAINPOOLP256r1.order, curve=BRAINPOOLP256r1)
ecdh = ECDH(curve=BRAINPOOLP256r1, private_key=sk)
try:
ecdh.load_received_public_key_der(bytes.fromhex(tc["public"]))
secret = ecdh.generate_sharedsecret_bytes()
hits += tc["result"] == "invalid"
res = f"ACCEPTED, secret equals Wycheproof's value: {secret.hex() == tc['shared']}"
except Exception as exc: # noqa: BLE001
res = f"rejected: {type(exc).__name__}: {exc}"
print(f" tcId {tc['tcId']:4d} '{tc['comment']}' (expected {tc['result']}) -> {res}")
print("REPRODUCED" if hits else "NOT REPRODUCED", f"({hits} invalid cases accepted)")
- Ngôn ngữ chính
- Python
- Star
- 975
- Fork
- 346
- Merge trung bình
- 26 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của tlsfuzzer/python-ecdsa
-
`verify()` raises `TypeError` instead of rejecting when `u1*G + u2*Q` is the point at infinityĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
tlsfuzzer/python-ecdsa#389 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
tlsfuzzer/python-ecdsa#387 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
tlsfuzzer/python-ecdsa#381 · 1 bình luận · 5 reaction ·
-
ecdsa.keys.VerifyingKey.verify_digest should fail for CurveEdTwCó thể đã có người làm @apoorvdarshan đã nhận 143 ngày trước. Đang mởbug help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
tlsfuzzer/python-ecdsa#349 · 1 bình luận ·
-
feature help wanted
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
tlsfuzzer/python-ecdsa#348 · 1 bình luận ·
Tất cả issue của tlsfuzzer/python-ecdsa
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
comet-ml/opik#9877 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Resource]: FlavianĐang mởresource-submission validation-passed
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 80/100
hesreallyhim/awesome-claude-code#3736 · 1 bình luận ·
-
area: trackers bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Review: WordPress copy/snapshot download media with no size cap and a hostname-only origin checkĐang mởperformance product:quill
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Community-Access/quill#2634 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày