@@ -37,6 +37,10 @@ def getDomainsCovered(cert_path):
3737 if san_extension :
3838 # Extract and print the domains from SAN
3939 san_domains = san_extension .value .get_values_for_type (x509 .DNSName )
40+ try :
41+ logging .CyberCPLogFileWriter .writeToFile (f'Covered domains: { str (san_domains )} ' )
42+ except :
43+ pass
4044 return 1 , san_domains
4145 else :
4246 # If SAN is not present, return the Common Name as a fallback
@@ -54,20 +58,52 @@ def CheckIfSSLNeedsToBeIssued(virtualHostName):
5458 x509 = OpenSSL .crypto .load_certificate (OpenSSL .crypto .FILETYPE_PEM , open (filePath , 'r' ).read ())
5559 SSLProvider = x509 .get_issuer ().get_components ()[1 ][1 ].decode ('utf-8' )
5660
57- if SSLProvider != 'Denial' :
58- return sslUtilities .ISSUE_SSL
59- else :
60- status , domains = sslUtilities .getDomainsCovered (filePath )
6161
62+
63+ #### totally seprate check to see if both non-www and www are covered
64+
65+ if SSLProvider == "Let's Encrypt" :
66+ status , domains = sslUtilities .getDomainsCovered (filePath )
6267 if status :
6368 if len (domains ) > 1 :
64- return sslUtilities .DONT_ISSUE
69+ ### need further checks here to see if ssl is valid for less then 15 days etc
70+ logging .CyberCPLogFileWriter .writeToFile (
71+ '[CheckIfSSLNeedsToBeIssued] SSL exists for %s and both versions are covered, just need to ensure if SSL is valid for less then 15 days.' % (virtualHostName ), 0 )
72+ pass
6573 else :
6674 return sslUtilities .ISSUE_SSL
75+
76+ #####
77+
78+ expireData = x509 .get_notAfter ().decode ('ascii' )
79+ from datetime import datetime
80+ finalDate = datetime .strptime (expireData , '%Y%m%d%H%M%SZ' )
81+ now = datetime .now ()
82+ diff = finalDate - now
83+
84+ if int (diff .days ) >= 15 and SSLProvider != 'Denial' :
85+ logging .CyberCPLogFileWriter .writeToFile (
86+ '[CheckIfSSLNeedsToBeIssued] SSL exists for %s and is not ready to fetch new SSL., skipping..' % (
87+ virtualHostName ), 0 )
88+
89+ return sslUtilities .DONT_ISSUE
90+ elif SSLProvider == 'Denial' :
91+ logging .CyberCPLogFileWriter .writeToFile (
92+ f'[CheckIfSSLNeedsToBeIssued] Self-signed SSL found, lets issue new SSL for { virtualHostName } ' , 0 )
93+ return sslUtilities .ISSUE_SSL
94+ elif SSLProvider != "Let's Encrypt" :
95+ logging .CyberCPLogFileWriter .writeToFile (
96+ f'[CheckIfSSLNeedsToBeIssued] Custom SSL found for { virtualHostName } ' , 0 )
97+ return sslUtilities .DONT_ISSUE
98+ else :
99+ logging .CyberCPLogFileWriter .writeToFile (
100+ f'[CheckIfSSLNeedsToBeIssued] We will issue SSL for { virtualHostName } ' , 0 )
101+ return sslUtilities .ISSUE_SSL
67102 else :
103+ logging .CyberCPLogFileWriter .writeToFile (
104+ f'[CheckIfSSLNeedsToBeIssued] We will issue SSL for { virtualHostName } ' , 0 )
68105 return sslUtilities .ISSUE_SSL
69106
70-
71107 @staticmethod
72108 def checkIfSSLMap (virtualHostName ):
73109 try :
@@ -435,6 +471,7 @@ def installSSLForDomain(virtualHostName, adminEmail='example@example.org'):
435471
436472 @staticmethod
437473 def obtainSSLForADomain (virtualHostName , adminEmail , sslpath , aliasDomain = None ):
474+
438475 from plogical .acl import ACLManager
439476 from plogical .sslv2 import sslUtilities as sslv2
440477 import json
0 commit comments