|
|
|
@ -1175,6 +1175,68 @@ def getMyORM(): |
|
|
|
|
# 数据库 START |
|
|
|
|
# --------------------------------------------------------------------------------- |
|
|
|
|
|
|
|
|
|
##################### ssl start ######################################### |
|
|
|
|
# 获取证书名称 |
|
|
|
|
def getCertName(certPath): |
|
|
|
|
if not os.path.exists(certPath): |
|
|
|
|
return None |
|
|
|
|
try: |
|
|
|
|
import OpenSSL |
|
|
|
|
result = {} |
|
|
|
|
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, readFile(certPath)) |
|
|
|
|
# 取产品名称 |
|
|
|
|
issuer = x509.get_issuer() |
|
|
|
|
result['issuer'] = '' |
|
|
|
|
if hasattr(issuer, 'CN'): |
|
|
|
|
result['issuer'] = issuer.CN |
|
|
|
|
if not result['issuer']: |
|
|
|
|
is_key = [b'0', '0'] |
|
|
|
|
issue_comp = issuer.get_components() |
|
|
|
|
if len(issue_comp) == 1: |
|
|
|
|
is_key = [b'CN', 'CN'] |
|
|
|
|
for iss in issue_comp: |
|
|
|
|
if iss[0] in is_key: |
|
|
|
|
result['issuer'] = iss[1].decode() |
|
|
|
|
break |
|
|
|
|
if not result['issuer']: |
|
|
|
|
if hasattr(issuer, 'O'): |
|
|
|
|
result['issuer'] = issuer.O |
|
|
|
|
# 取到期时间 |
|
|
|
|
result['notAfter'] = strfDate( |
|
|
|
|
bytes.decode(x509.get_notAfter())[:-1]) |
|
|
|
|
# 取申请时间 |
|
|
|
|
result['notBefore'] = strfDate( |
|
|
|
|
bytes.decode(x509.get_notBefore())[:-1]) |
|
|
|
|
# 取可选名称 |
|
|
|
|
result['dns'] = [] |
|
|
|
|
for i in range(x509.get_extension_count()): |
|
|
|
|
s_name = x509.get_extension(i) |
|
|
|
|
if s_name.get_short_name() in [b'subjectAltName', 'subjectAltName']: |
|
|
|
|
s_dns = str(s_name).split(',') |
|
|
|
|
for d in s_dns: |
|
|
|
|
result['dns'].append(d.split(':')[1]) |
|
|
|
|
subject = x509.get_subject().get_components() |
|
|
|
|
# 取主要认证名称 |
|
|
|
|
if len(subject) == 1: |
|
|
|
|
result['subject'] = subject[0][1].decode() |
|
|
|
|
else: |
|
|
|
|
if not result['dns']: |
|
|
|
|
for sub in subject: |
|
|
|
|
if sub[0] == b'CN': |
|
|
|
|
result['subject'] = sub[1].decode() |
|
|
|
|
break |
|
|
|
|
if 'subject' in result: |
|
|
|
|
result['dns'].append(result['subject']) |
|
|
|
|
else: |
|
|
|
|
result['subject'] = result['dns'][0] |
|
|
|
|
result['endtime'] = int(int(time.mktime(time.strptime( |
|
|
|
|
result['notAfter'], "%Y-%m-%d")) - time.time()) / 86400) |
|
|
|
|
return result |
|
|
|
|
except Exception as e: |
|
|
|
|
writeFileLog(getTracebackInfo()) |
|
|
|
|
return None |
|
|
|
|
##################### ssl end ######################################### |
|
|
|
|
|
|
|
|
|
##################### notify start ######################################### |
|
|
|
|
|
|
|
|
|
|
|
|
|
|