<reponame>Kramer-M/cert_checker
# Author: <NAME> <<EMAIL>>
# Modified from serverlesscode.com/post/ssl-expiration-alerts-with-lambda/

import datetime
import fileinput
import logging
import os
import socket
import ssl
import time

logger = logging.getLogger('SSLVerify')

def ssl_expiry_datetime(hostname: str, port: int) -> datetime.datetime:
    ssl_date_fmt = r'%b %d %H:%M:%S %Y %Z'

    context = ssl.create_default_context()
    conn = context.wrap_socket(
        socket.socket(socket.AF_INET),
        server_hostname=hostname,
    )

    logger.debug('Trying to connect to {}'.format(hostname))
    conn.connect((hostname, port))
    ssl_info = conn.getpeercert()
    # parse the string from the certificate into a Python datetime object
    return datetime.datetime.strptime(ssl_info['notAfter'], ssl_date_fmt)


# Author: <NAME> <<EMAIL>>
# Modified from serverlesscode.com/post/ssl-expiration-alerts-with-lambda/

import datetime
import fileinput
import logging
import os
import socket
import ssl
import time

logger = logging.getLogger('SSLVerify')

def ssl_expiry_datetime(hostname: str, port: int) -> datetime.datetime:
    ssl_date_fmt = r'%b %d %H:%M:%S %Y %Z'

    context = ssl.create_default_context()
    conn = context.wrap_socket(
        socket.socket(socket.AF_INET),
        server_hostname=hostname,
    )

    logger.debug('Trying to connect to {}'.format(hostname))
    conn.connect((hostname, port))
    ssl_info = conn.getpeercert()
    # parse the string from the certificate into a Python datetime object
    return datetime.datetime.strptime(ssl_info['notAfter'], ssl_date_fmt)
# Author: <NAME> <<EMAIL>> # Modified from serverlesscode.com/post/ssl-expiration-alerts-with-lambda/ # parse the string from the certificate into a Python datetime object