From 1b4098119b45221ed2d6c67832bad482d660a529 Mon Sep 17 00:00:00 2001 From: wzj <244142824@qq.com> Date: Sat, 14 Jun 2025 09:16:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=88=86=E5=BC=80=E5=AF=BC?= =?UTF-8?q?=E5=87=BApem=E5=92=8Ckey?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 27 +++++++++++++++++++++++++++ templates/export_certificate.html | 11 +++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) 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 @@