Loading...

修改/www/server/panel/class/ssl_info.py文件第242行左右的verify_certificate_and_key_match函数为下面并重启面板即可(注意缩进)。

def verify_certificate_and_key_match(self, key_pem, cert_pem, password=None): """ 验证证书和私钥是否匹配(通过签名验证) :param key_pem: 私钥内容 :param cert_pem: 证书内容 :param password: 私钥密码 :return: 验证成功返回True,失败返回False """ from cryptography.hazmat.primitives.asymmetric import ec message = b"test message" private_key = self.analysis_private_key(key_pem, password) cert = self.analysis_certificate(cert_pem) if not private_key: return False, "密钥错误,请检查是否为正确的PEM格式私钥" if not cert: return False, "证书错误,请检查是否为正确的PEM格式证书" # 根据私钥类型选择不同的签名方式 try: if isinstance(private_key, ec.EllipticCurvePrivateKey): # EC密钥签名 signature = private_key.sign( message, ec.ECDSA(hashes.SHA256()) ) else: # RSA密钥签名 signature = private_key.sign( message, padding.PKCS1v15(), hashes.SHA256() ) # 使用证书中的公钥验证签名 public_key = cert.public_key() if isinstance(public_key, ec.EllipticCurvePublicKey): # EC公钥验证 public_key.verify( signature, message, ec.ECDSA(hashes.SHA256()) ) else: # RSA公钥验证 public_key.verify( signature, message, padding.PKCS1v15(), hashes.SHA256() ) return True, "验证成功" except Exception as e: return False, f"密钥和证书不匹配:{str(e)}"

如果申请ssl出现:module 'OpenSSL.crypto' has no att...,这是宝塔官方的bug
官方bug复现贴:https://www.bt.cn/bbs/thread-140990-1-1.html
解决办法

btpip install pyOpenSSL==24.2.1 -U

执行上面的命令 然后重启面板

本文标题: 宝塔9.3无法保存证书报错TypeError: ECPrivateKey.sign() takes 2 positional arguments but 3 were given

本文链接: https://luola.me/90.html

除非另有说明,本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议

声明:转载请注明文章来源。

最后修改:2025 年 01 月 11 日
如果觉得我的文章对你有用,请随意赞赏