Last active
November 30, 2020 13:33
-
-
Save lgtml/ce1f0dab154dd130f3d4b2724727ab8e to your computer and use it in GitHub Desktop.
check ssl labs with python output junit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import time | |
import re | |
from ssllabsscanner import resultsFromCache,newScan | |
from junit_xml import TestSuite,TestCase | |
def passing_grade(grade): | |
if re.match("A", grade): | |
return True | |
return False | |
def scan_host(host): | |
start_time = time.clock() | |
grade = newScan(host)['endpoints'][0]['grade'] | |
stop_time = time.clock() | |
return grade,(stop_time - start_time)*1000 | |
def check_hosts_ssl(hosts): | |
test_cases = [] | |
exit_code = 0 | |
for host in hosts: | |
grade, time = scan_host(host) | |
tc = TestCase('Check A Plus', 'ssllabs.grade.' + host, time) | |
if not passing_grade(grade): | |
exit_code += 1 | |
tc.add_failure_info('Got {} expected A+'.format(grade)) | |
test_cases.append(tc) | |
ts = TestSuite("SSLLabs Grade Hosts", test_cases) | |
print(TestSuite.to_xml_string([ts])) | |
sys.exit(exit_code) | |
def main(): | |
hosts = sys.argv[1:] | |
check_hosts_ssl(hosts) | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Add Docstring | |
This file is from https://raw.githubusercontent.com/TrullJ/ssllabs/master/ssllabsscanner.py | |
""" | |
import requests | |
import time | |
API = "https://api.ssllabs.com/api/v2/" | |
def requestAPI(path, payload={}): | |
"""This is a helper method that takes the path to the relevant | |
API call and the user-defined payload and requests the | |
data/server test from Qualys SSL Labs. | |
Returns JSON formatted data""" | |
url = API + path | |
try: | |
response = requests.get(url, params=payload) | |
except requests.exception.RequestException as e: | |
print(e) | |
sys.exit(1) | |
data = response.json() | |
return data | |
def resultsFromCache(host, publish = "off", startNew = "off", fromCache = "on", all = "done"): | |
path = "analyze" | |
payload = {'host': host, 'publish': publish, 'startNew': startNew, 'fromCache': fromCache, 'all': all} | |
data = requestAPI(path, payload) | |
return data | |
def newScan(host, publish = "off", startNew = "on", all = "done", ignoreMismatch = "on"): | |
path = "analyze" | |
payload = {'host': host, 'publish': publish, 'startNew': startNew, 'all': all, 'ignoreMismatch': ignoreMismatch} | |
results = requestAPI(path, payload) | |
payload.pop('startNew') | |
while results['status'] != 'READY' and results['status'] != 'ERROR': | |
#print("Scan in progress, please wait for the results.") | |
time.sleep(30) | |
results = requestAPI(path, payload) | |
return results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment