已合并
[bugfix] 优化证书私钥模数校验性能并拆分 TLS 相关 UT #694
yuzechen创建于 2 天前
[bugfix] 优化证书私钥模数校验性能并拆分 TLS 相关 UT #694
已合并
Pull Request已成功合入, 合并人@wangyang
(感谢 yuzechen 的贡献)2 天前 关联了issue:[bug] 证书私钥模数校验过慢导致 TLS 相关 UT 耗时过高
2 天前 添加了label:ascend-cla/yes
ascend-robot
2 天前 评论:
2 天前 评论:
Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-Ascend/MindIE-Motor | ✅ 吕有辉, 韩依伦 (2/2) | ✅ 吕有辉 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
Jechin, thanks for your pull request. All authors of the commits have signed the CLA. 👍


2 天前 添加了label:ci-pipeline-running
ascend-robot
2 天前 评论:
2 天前 评论:
ascend docs pipeline is running...


2 天前 添加了label:docs-ci-pipeline-running
ascend-robot
2 天前 评论:
2 天前 评论:
✅ 跳过 docs ci 检查,没有需要检查的文档文件


2 天前 删除了label:docs-ci-pipeline-running
2 天前 添加了label:docs-ci-pipeline-success
2 天前 删除了label:ci-pipeline-running
2 天前 添加了label:ci-pipeline-failed
ascend-robot
2 天前 评论:
2 天前 评论:
流水线 PR-pipeline_MindIE-Motor_gitcode#2589 [ commitID:acda33f1 ] 运行失败
>>>代码风格自动修复执行成功(无修复内容)
| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_linux_arm | 🕚 | >>> |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | pre-commit | ❌ | >>> |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | UT_linux_arm | 🕚 | >>> |
| 流水线 | PR-pipeline_MindIE-Motor_gitcode | ❌ | >>> |
- compile : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


motor/common/http/cert_util.py
@@ -45,3 +45,3 @@
4545
4646def validate_certs_and_keys_modulus(server_crt: CryptoX509, server_key: CryptoX509) -> bool:
47- """Validate certificate and private key modulus match"""
47+ """Validate certificate and private key match via OpenSSL native check."""
use_privatekey可能因密钥格式/加密抛Error或密码缺失异常,当前只捕获SSL.Error,其他异常会中断调用方。


motor/common/http/cert_util.py
@@ -54,2 +49,2 @@
54- key_modulus = key_rsa_key.public_key().public_numbers().n
55- return cert_modulus == key_modulus
49+ ctx = SSL.Context(SSL.TLS_SERVER_METHOD)
50+ ctx.use_certificate(server_crt)
logger.error的f-string应改为%s占位符,项目硬约束禁止f-string日志。


motor/common/http/cert_util.py
@@ -15,7 +15,7 @@ import stat
1515from datetime import timezone
1616from ssl import Purpose, create_default_context
1717
18-from OpenSSL import crypto
18+from OpenSSL import SSL, crypto
1919from cryptography import x509 as crypt_x509
2020from cryptography.x509.oid import ExtensionOID
2121
@@ -44,15 +44,16 @@ UTF8_ENCODING = "utf-8"
4444
改用OpenSSL原生检查后,函数不再比较模数,建议改名如validate_cert_and_key_match。


motor/common/http/cert_util.py
@@ -45,3 +45,3 @@
4545
4646def validate_certs_and_keys_modulus(server_crt: CryptoX509, server_key: CryptoX509) -> bool:
47- """Validate certificate and private key modulus match"""
47+ """Validate certificate and private key match via OpenSSL native check."""
use_privatekey对加密密钥无口令时会抛异常,当前除SSL.Error外均未捕获,可能向上传播。


2 天前 删除了label:ci-pipeline-failed
2 天前 添加了label:stat/needs-squash
2 天前 删除了label:ascend-cla/yes
2 天前 添加了label:ascend-cla/yes
ascend-robot
2 天前 评论:
2 天前 评论:
ascend docs pipeline is running...


2 天前 删除了label:docs-ci-pipeline-success
2 天前 添加了label:docs-ci-pipeline-running
ascend-robot
2 天前 评论:
2 天前 评论:
✅ 跳过 docs ci 检查,没有需要检查的文档文件


2 天前 删除了label:docs-ci-pipeline-running
2 天前 添加了label:docs-ci-pipeline-success
2 天前 解决了最后一个问题
yuzechen
2 天前 评论:
2 天前 评论:
compile


2 天前 添加了label:ci-pipeline-running
ascend-robot
2 天前 评论:
2 天前 评论:
ascend docs pipeline is running...


2 天前 删除了label:docs-ci-pipeline-success
2 天前 添加了label:docs-ci-pipeline-running
ascend-robot
2 天前 评论:
2 天前 评论:
✅ 跳过 docs ci 检查,没有需要检查的文档文件


2 天前 删除了label:docs-ci-pipeline-running
2 天前 添加了label:docs-ci-pipeline-success
2 天前 删除了label:ci-pipeline-running
2 天前 添加了label:ci-pipeline-passed
ascend-robot
2 天前 评论:
2 天前 评论:
流水线 PR-pipeline_MindIE-Motor_gitcode#2597 [ commitID:3a228f01 ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_linux_arm | ✅ | >>> |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | pre-commit | ✅ | >>> |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | UT_linux_arm | ✅ | >>> |
| 流水线 | PR-pipeline_MindIE-Motor_gitcode | ✅ | >>> |
- compile : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


jason lyu
1 天前 评论:
1 天前 评论:
/approve


1 天前 添加了label:approved
1 天前 添加了label:lgtm
1 天前 关闭了关联的issue
1 天前 合入了pull request
1. 合入背景
Fixes #459
证书私钥模数校验在 RSA-3072 场景下通过
to_cryptography_key()比对模数,单次约 550ms,导致 TLS 相关 UT 耗时过高;本 PR 改用 OpenSSL 原生校验并拆分冗余 comprehensive 用例。2. 修改内容
motor/common/http/cert_util.pyvalidate_certs_and_keys_modulus改为SSL.Context.check_privatekey()校验证书与私钥匹配,避免私钥to_cryptography_key()的慢路径。tests/coordinator/test_http_server_cert.pytest_validate_cert_and_key_comprehensive拆为参数化用例(成功路径、非法路径、空文件、格式错误、密钥不匹配、CA 错误等),保持覆盖同时减少单函数内重复全量校验。3. 资料变更
不涉及
4. 接口变更
不涉及跨代码仓或客户面可见的接口变更;TLS 证书校验行为与语义不变,仅优化内部实现性能。
5. 测试结果
bash tests/run_tests.sh tests/coordinator/test_http_server_cert.py:31 passedbash tests/run_tests.sh --serial:2711 passed,1 skippedtest_validate_cert_and_key_comprehensive(约 6.75s)已消除6. CheckList
[x] 代码注释完备
[x] 正确记录维测日志
[x] 是否有UT用例
[x] 若涉及多线程场景,考虑了并发场景,不存在死锁问题