File: check_certs.py

package info (click to toggle)
https-everywhere 4.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 16,040 kB
  • ctags: 1,990
  • sloc: xml: 29,807; python: 1,839; sh: 322; makefile: 36
file content (40 lines) | stat: -rwxr-xr-x 1,051 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python

import sys
import re
from subprocess import Popen, PIPE
from glob import glob

host_targets = re.compile(r'<target *host="([a-z0-9\-\*\.]+)"')
wget_cmd = lambda h : ["wget", "-O", "/dev/null", "https://" + h]

for fname in sys.argv[1:]:
  hosts = host_targets.findall(open(fname).read())
  if not hosts:
    print("Could not find <target hosts> in " + fname)
    continue
  successes = []
  failures = []
  for h in hosts:
    h2 = h.replace("*", "www")
    cmd = Popen(wget_cmd(h2), stdout=PIPE, stderr=PIPE)
    out, err = cmd.communicate()
    for l in err.split("\n"):
      if "certificate" in l:
        failures.append(l)
        break
    else:
      successes.append(h)
  if successes and not failures:
    print(fname + " no cert warnings")
  elif failures and not successes:
    print(fname + " categorical failure:")
    for f in failures:
      print("    " + f)
  else:
    print(fname + " mixed results:")
    for s in successes:
      print("    " + s + " is OK")
    for f in failures:
      print("    " + f)