diff --git a/api_sample.py b/api_sample.py index 1452b02d..f20dbf03 100755 --- a/api_sample.py +++ b/api_sample.py @@ -1,4 +1,6 @@ +from datetime import datetime from pathlib import Path +from typing import List from sslyze import ( Scanner, @@ -7,6 +9,8 @@ ServerNetworkLocation, ScanCommandAttemptStatusEnum, ServerScanStatusEnum, + ServerScanResult, + ServerScanResultAsJson, ) from sslyze.errors import ServerHostnameCouldNotBeResolved from sslyze.scanner.scan_command_attempt import ScanCommandAttempt @@ -20,6 +24,9 @@ def _print_failed_scan_command_attempt(scan_command_attempt: ScanCommandAttempt) def main() -> None: + print("=> Starting the scans") + date_scans_started = datetime.utcnow() + # First create the scan requests for each server that we want to scan try: all_scan_requests = [ @@ -36,7 +43,9 @@ def main() -> None: scanner.queue_scans(all_scan_requests) # And retrieve and process the results for each server + all_server_scan_results = [] for server_scan_result in scanner.get_results(): + all_server_scan_results.append(server_scan_result) print(f"\n\n****Results for {server_scan_result.server_location.hostname}****") # Were we able to connect to the server and run the scan? @@ -92,10 +101,34 @@ def main() -> None: # etc... Other scan command results to process are in server_scan_result.scan_result + # Lastly, save the all the results to a JSON file + json_file_out = Path("api_sample_results.json") + print(f"\n\n=> Saving scan results to {json_file_out}") + example_json_result_output(json_file_out, all_server_scan_results, date_scans_started, datetime.utcnow()) + + # And ensure we are able to parse them + print(f"\n\n=> Parsing scan results from {json_file_out}") + example_json_result_parsing(json_file_out) + + +def example_json_result_output( + json_file_out: Path, + all_server_scan_results: List[ServerScanResult], + date_scans_started: datetime, + date_scans_completed: datetime, +) -> None: + json_output = SslyzeOutputAsJson( + server_scan_results=[ServerScanResultAsJson.from_orm(result) for result in all_server_scan_results], + invalid_server_strings=[], # Not needed here - specific to the CLI interface + date_scans_started=date_scans_started, + date_scans_completed=date_scans_completed, + ) + json_output_as_str = json_output.json(sort_keys=True, indent=4, ensure_ascii=True) + json_file_out.write_text(json_output_as_str) + -def example_json_result_parsing() -> None: +def example_json_result_parsing(results_as_json_file: Path) -> None: # SSLyze scan results serialized to JSON were saved to this file using --json_out - results_as_json_file = Path(__file__).parent / "tests" / "json_tests" / "sslyze_output.json" results_as_json = results_as_json_file.read_text() # These results can be parsed diff --git a/docs/documentation/.buildinfo b/docs/documentation/.buildinfo index b1647912..e8d899af 100644 --- a/docs/documentation/.buildinfo +++ b/docs/documentation/.buildinfo @@ -1,4 +1,4 @@ # Sphinx build info version 1 # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. -config: 97b3451be6c04378175579402a82d6be +config: 710e1f17bd6b1026352fe79ab79c95d4 tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/docs/documentation/_static/documentation_options.js b/docs/documentation/_static/documentation_options.js index 54adbea3..86d47bd6 100644 --- a/docs/documentation/_static/documentation_options.js +++ b/docs/documentation/_static/documentation_options.js @@ -1,6 +1,6 @@ var DOCUMENTATION_OPTIONS = { URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'), - VERSION: '5.0.3', + VERSION: '5.0.6', LANGUAGE: 'None', COLLAPSE_INDEX: false, BUILDER: 'html', diff --git a/docs/documentation/available-scan-commands.html b/docs/documentation/available-scan-commands.html index 7c138ff3..81c8b912 100644 --- a/docs/documentation/available-scan-commands.html +++ b/docs/documentation/available-scan-commands.html @@ -6,7 +6,7 @@ - Appendix: Scan Commands — SSLyze 5.0.3 documentation + Appendix: Scan Commands — SSLyze 5.0.6 documentation @@ -525,7 +525,7 @@

Result class
-ev_oids: Optional[List[cryptography.hazmat._oid.ObjectIdentifier]] = None
+ev_oids: Optional[List[ObjectIdentifier]] = None
@@ -1441,7 +1441,7 @@

Quick search