支持分开导出pem和key

This commit is contained in:
wzj 2025-06-14 09:16:06 +08:00
parent c3408be019
commit 1b4098119b
2 changed files with 36 additions and 2 deletions

27
app.py
View File

@ -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')

View File

@ -21,9 +21,16 @@
<div class="form-check">
<input class="form-check-input" type="radio" name="format" id="formatPem" value="pem">
<label class="form-check-label" for="formatPem">
PEM (.pem)
PEM (.pem) - 合并文件
</label>
<div class="form-text">Base64编码的证书和私钥适用于Nginx/Apache等</div>
<div class="form-text">Base64编码的证书和私钥合并为一个文件</div>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="format" id="formatPemSeparate" value="pem_separate">
<label class="form-check-label" for="formatPemSeparate">
PEM (.pem) - 分开文件
</label>
<div class="form-text">Base64编码的证书和私钥作为两个单独文件</div>
</div>
</div>