Skip to content

Instantly share code, notes, and snippets.

@Fitblip
Created June 24, 2017 05:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fitblip/924777595f21f04cf158f7a34f7ac358 to your computer and use it in GitHub Desktop.
Save Fitblip/924777595f21f04cf158f7a34f7ac358 to your computer and use it in GitHub Desktop.
Find a specific keyword (paypal) in any certificates sent by Certstream
import certstream
import base64
NEEDLE = "paypal"
# Search for domains with a keyword in them and write the corresponding certificate to a file
def certstream_callback(message):
if message['message_type'] == "certificate_update":
all_domains = message['data']['leaf_cert']['all_domains']
if NEEDLE.lower() in " ".join(all_domains).lower():
cn = all_domains[0]
filename = "/tmp/{}".format(cn)
print("Found {} in cert for {}. Writing to {}.".format(NEEDLE, cn, filename))
with open(filename, 'w') as f:
f.write(base64.b64decode(message['data']['leaf_cert']['as_der']))
certstream.listen_for_events(certstream_callback)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment