diff --git a/app.py b/app.py index 61f1672..e2781cc 100644 --- a/app.py +++ b/app.py @@ -921,6 +921,33 @@ def export_certificate_view(cert_id): "Content-Disposition": f"attachment; filename={cert['common_name']}.pem" } ) + elif format_type == 'pem_separate': + # 创建临时zip文件包含两个单独的文件 + import zipfile + from io import BytesIO + + # 创建内存中的zip文件 + memory_file = BytesIO() + with zipfile.ZipFile(memory_file, 'w') as zf: + # 添加证书文件 + with open(cert['cert_path'], 'r') as f: + cert_content = f.read() + zf.writestr(f"{cert['common_name']}.crt", cert_content) + + # 添加私钥文件 + with open(cert['key_path'], 'r') as f: + key_content = f.read() + zf.writestr(f"{cert['common_name']}.key", key_content) + + memory_file.seek(0) + + return Response( + memory_file, + mimetype="application/zip", + headers={ + "Content-Disposition": f"attachment; filename={cert['common_name']}_separate.zip" + } + ) else: flash('不支持的导出格式', 'danger') diff --git a/templates/export_certificate.html b/templates/export_certificate.html index 3a3cd6e..098e917 100644 --- a/templates/export_certificate.html +++ b/templates/export_certificate.html @@ -21,9 +21,16 @@
-
Base64编码的证书和私钥,适用于Nginx/Apache等
+
Base64编码的证书和私钥合并为一个文件
+
+
+ + +
Base64编码的证书和私钥作为两个单独文件