python自动获取或续签免费ssl证书代码

代码语言:python

所属分类:其他

代码描述:python自动获取或续签免费ssl证书代码,可以放在服务器上自动申请续签免费ssl证书,需要80端口没有被占用,如果被占用,就要通过反向代理访问这个程序。

代码标签: python 自动 获取 续签 免费 ssl 证书 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Let's Encrypt ACME 自动续期脚本(HTTP-01)

用法示例:
    python3 autosslcert.py \
        -d example.com -d www.example.com \
        -c /etc/nginx/ssl/fullchain.pem \
        -k /etc/nginx/ssl/privkey.pem \
        -e admin@example.com

    # 强制续期
    python3 autosslcert.py -d example.com -c /path/fullchain.pem -e a@b.com --force

    # 使用测试环境
    python3 autosslcert.py -d example.com -c /path/fullchain.pem -e a@b.com \
        --acme-directory https://acme-staging-v02.api.letsencrypt.org/directory
"""

import os
import sys
import shutil
import argparse
import datetime
import threading
from http.server import HTTPServer, BaseHTTPRequestHandler
from urllib.parse import urlparse

from cryptography import x509
from cryptography.x509.oid import NameOID
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.backends import default_backend

from acme import client, messages
from acme.errors import ValidationError, ConflictError
from josepy import jwk


# ---------- 默认配置 ----------
DEFAULT_ACME_DIRECTORY = "https://acme-v02.api.letsencrypt.org/directory"
DEFAULT_HTTP_PORT = 80
RENEW_DAYS_THRESHOLD = 7


def log(msg):
    ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    print("[{}] {}&quo.........完整代码请登录后点击上方下载按钮下载查看

网友评论0