mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Updating acme-tiny to 7ef9164, include fixes for OpenSSL 1.1
This commit is contained in:
parent
10b08dfd7f
commit
c55222e46f
1 changed files with 7 additions and 21 deletions
28
src/yunohost/vendor/acme_tiny/acme_tiny.py
vendored
28
src/yunohost/vendor/acme_tiny/acme_tiny.py
vendored
|
@ -1,21 +1,9 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import argparse
|
import argparse, subprocess, json, os, sys, base64, binascii, time, hashlib, re, copy, textwrap, logging
|
||||||
import subprocess
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import base64
|
|
||||||
import binascii
|
|
||||||
import time
|
|
||||||
import hashlib
|
|
||||||
import re
|
|
||||||
import copy
|
|
||||||
import textwrap
|
|
||||||
import logging
|
|
||||||
try:
|
try:
|
||||||
from urllib.request import urlopen # Python 3
|
from urllib.request import urlopen # Python 3
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from urllib2 import urlopen # Python 2
|
from urllib2 import urlopen # Python 2
|
||||||
|
|
||||||
#DEFAULT_CA = "https://acme-staging.api.letsencrypt.org"
|
#DEFAULT_CA = "https://acme-staging.api.letsencrypt.org"
|
||||||
DEFAULT_CA = "https://acme-v01.api.letsencrypt.org"
|
DEFAULT_CA = "https://acme-v01.api.letsencrypt.org"
|
||||||
|
@ -24,7 +12,6 @@ LOGGER = logging.getLogger(__name__)
|
||||||
LOGGER.addHandler(logging.StreamHandler())
|
LOGGER.addHandler(logging.StreamHandler())
|
||||||
LOGGER.setLevel(logging.INFO)
|
LOGGER.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
def get_crt(account_key, csr, acme_dir, log=LOGGER, CA=DEFAULT_CA):
|
def get_crt(account_key, csr, acme_dir, log=LOGGER, CA=DEFAULT_CA):
|
||||||
# helper function base64 encode for jose spec
|
# helper function base64 encode for jose spec
|
||||||
def _b64(b):
|
def _b64(b):
|
||||||
|
@ -39,7 +26,7 @@ def get_crt(account_key, csr, acme_dir, log=LOGGER, CA=DEFAULT_CA):
|
||||||
raise IOError("OpenSSL Error: {0}".format(err))
|
raise IOError("OpenSSL Error: {0}".format(err))
|
||||||
pub_hex, pub_exp = re.search(
|
pub_hex, pub_exp = re.search(
|
||||||
r"modulus:\n\s+00:([a-f0-9\:\s]+?)\npublicExponent: ([0-9]+)",
|
r"modulus:\n\s+00:([a-f0-9\:\s]+?)\npublicExponent: ([0-9]+)",
|
||||||
out.decode('utf8'), re.MULTILINE | re.DOTALL).groups()
|
out.decode('utf8'), re.MULTILINE|re.DOTALL).groups()
|
||||||
pub_exp = "{0:x}".format(int(pub_exp))
|
pub_exp = "{0:x}".format(int(pub_exp))
|
||||||
pub_exp = "0{0}".format(pub_exp) if len(pub_exp) % 2 else pub_exp
|
pub_exp = "0{0}".format(pub_exp) if len(pub_exp) % 2 else pub_exp
|
||||||
header = {
|
header = {
|
||||||
|
@ -82,10 +69,10 @@ def get_crt(account_key, csr, acme_dir, log=LOGGER, CA=DEFAULT_CA):
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
raise IOError("Error loading {0}: {1}".format(csr, err))
|
raise IOError("Error loading {0}: {1}".format(csr, err))
|
||||||
domains = set([])
|
domains = set([])
|
||||||
common_name = re.search(r"Subject:.*? CN=([^\s,;/]+)", out.decode('utf8'))
|
common_name = re.search(r"Subject:.*? CN\s?=\s?([^\s,;/]+)", out.decode('utf8'))
|
||||||
if common_name is not None:
|
if common_name is not None:
|
||||||
domains.add(common_name.group(1))
|
domains.add(common_name.group(1))
|
||||||
subject_alt_names = re.search(r"X509v3 Subject Alternative Name: \n +([^\n]+)\n", out.decode('utf8'), re.MULTILINE | re.DOTALL)
|
subject_alt_names = re.search(r"X509v3 Subject Alternative Name: \n +([^\n]+)\n", out.decode('utf8'), re.MULTILINE|re.DOTALL)
|
||||||
if subject_alt_names is not None:
|
if subject_alt_names is not None:
|
||||||
for san in subject_alt_names.group(1).split(", "):
|
for san in subject_alt_names.group(1).split(", "):
|
||||||
if san.startswith("DNS:"):
|
if san.startswith("DNS:"):
|
||||||
|
@ -178,7 +165,6 @@ def get_crt(account_key, csr, acme_dir, log=LOGGER, CA=DEFAULT_CA):
|
||||||
return """-----BEGIN CERTIFICATE-----\n{0}\n-----END CERTIFICATE-----\n""".format(
|
return """-----BEGIN CERTIFICATE-----\n{0}\n-----END CERTIFICATE-----\n""".format(
|
||||||
"\n".join(textwrap.wrap(base64.b64encode(result).decode('utf8'), 64)))
|
"\n".join(textwrap.wrap(base64.b64encode(result).decode('utf8'), 64)))
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
@ -208,5 +194,5 @@ def main(argv):
|
||||||
signed_crt = get_crt(args.account_key, args.csr, args.acme_dir, log=LOGGER, CA=args.ca)
|
signed_crt = get_crt(args.account_key, args.csr, args.acme_dir, log=LOGGER, CA=args.ca)
|
||||||
sys.stdout.write(signed_crt)
|
sys.stdout.write(signed_crt)
|
||||||
|
|
||||||
if __name__ == "__main__": # pragma: no cover
|
if __name__ == "__main__": # pragma: no cover
|
||||||
main(sys.argv[1:])
|
main(sys.argv[1:])
|
||||||
|
|
Loading…
Add table
Reference in a new issue