CaliDog / certstream-python

Python library for connecting to CertStream
MIT License
425 stars 72 forks source link

Example script prints duplicate domains #52

Open cr4zyfish opened 3 years ago

cr4zyfish commented 3 years ago

when I run the example script, some domains are printed more that one time. some domains are printed again after a few minutes. what is the reason and how to prevent this?

import logging
import sys
import datetime
import certstream

def print_callback(message, context):
    logging.debug("Message -> {}".format(message))

    if message['message_type'] == "heartbeat":
        return

    if message['message_type'] == "certificate_update":
        all_domains = message['data']['leaf_cert']['all_domains']

        if len(all_domains) == 0:
            domain = "NULL"
        else:
            domain = all_domains[0]

        sys.stdout.write(u"[{}] {} (SAN: {})\n".format(datetime.datetime.now().strftime('%m/%d/%y %H:%M:%S'), domain, ", ".join(message['data']['leaf_cert']['all_domains'][1:])))
        sys.stdout.flush()

logging.basicConfig(format='[%(levelname)s:%(name)s] %(asctime)s - %(message)s', level=logging.INFO)

certstream.listen_for_events(print_callback, url='wss://certstream.calidog.io/')
mimi89999 commented 2 years ago

Most certificates are submitted to at least 2 different CT logs.