예제 #1
0
    def test_json_serializer_functions(self):
        # Given a completed scan for a server with the CERTIFICATE_INFO scan command
        server_location = ServerNetworkLocationViaDirectConnection.with_ip_address_lookup(
            "www.hotmail.com", 443)
        server_info = ServerConnectivityTester().perform(server_location)
        plugin_result = CertificateInfoImplementation.perform(server_info)
        scan_results = {ScanCommandEnum.CERTIFICATE_INFO: plugin_result}
        scan_result = ServerScanResultFactory.create(
            scan_commands_results=scan_results)

        # When generating the JSON output for this server scan
        with StringIO() as file_out:
            json_generator = JsonOutputGenerator(file_to=file_out)
            json_generator.server_scan_completed(scan_result)

            # We call scans_completed() because this is when the output actually gets written to the file
            json_generator.scans_completed(0.2)
            final_output = file_out.getvalue()

        # It succeeds
        assert final_output

        # And complex object like certificates were properly serialized
        assert "notBefore" in final_output
        assert "issuer" in final_output
        assert "subject" in final_output
예제 #2
0
    def test_server_scan_completed_scan_command(self):
        # Given a completed scan for a server where a scan command was run
        compression_attempt = CompressionScanAttempt(
            status=ScanCommandAttemptStatusEnum.COMPLETED,
            error_reason=None,
            error_trace=None,
            result=CompressionScanResult(supports_compression=True),
        )
        server_scan_result = ServerScanResultFactory.create(
            scan_result=AllScanCommandsAttemptsFactory.create(
                {"tls_compression": compression_attempt}))

        # When converting it to JSON, it succeeds
        json_output = SslyzeOutputAsJson(
            server_scan_results=[
                ServerScanResultAsJson.from_orm(server_scan_result)
            ],
            date_scans_started=datetime.utcnow(),
            date_scans_completed=datetime.utcnow(),
        )
        json_output_as_str = json_output.json(sort_keys=True,
                                              indent=4,
                                              ensure_ascii=True)
        assert json_output_as_str
        assert "supports_compression" in json_output_as_str

        # And it can be parsed again
        assert SslyzeOutputAsJson.parse_raw(json_output_as_str)
예제 #3
0
    def test_server_scan_completed_but_scan_command_returned_error(self):
        # Given a completed scan for a server where a scan command was run
        error_trace = TracebackExceptionFactory.create()
        compression_attempt = CompressionScanAttempt(
            # And it triggered an error
            status=ScanCommandAttemptStatusEnum.ERROR,
            error_reason=ScanCommandErrorReasonEnum.BUG_IN_SSLYZE,
            error_trace=error_trace,
            result=None,
        )
        server_scan_result = ServerScanResultFactory.create(
            scan_result=AllScanCommandsAttemptsFactory.create(
                {"tls_compression": compression_attempt}))

        # When converting it to JSON, it succeeds
        json_output = SslyzeOutputAsJson(
            server_scan_results=[
                ServerScanResultAsJson.from_orm(server_scan_result)
            ],
            date_scans_started=datetime.utcnow(),
            date_scans_completed=datetime.utcnow(),
        )
        json_output_as_str = json_output.json(sort_keys=True,
                                              indent=4,
                                              ensure_ascii=True)
        assert json_output_as_str
        assert error_trace.exc_type.__name__ in json_output_as_str

        # And it can be parsed again
        assert SslyzeOutputAsJson.parse_raw(json_output_as_str)
예제 #4
0
    def test_server_scan_completed_with_proxy(self):
        # Given a completed scan for a server when the compression scan command was run
        compression_attempt = CompressionScanAttempt(
            status=ScanCommandAttemptStatusEnum.COMPLETED,
            error_reason=None,
            error_trace=None,
            result=CompressionScanResult(supports_compression=True),
        )
        scan_result = ServerScanResultFactory.create(
            # And sslyze connected to the server via an HTTP proxy
            server_location=ServerNetworkLocationViaHttpProxyFactory.create(),
            scan_result=AllScanCommandsAttemptsFactory.create(
                {"tls_compression": compression_attempt}),
        )

        # When generating the console output for this server scan
        with StringIO() as file_out:
            console_gen = ObserverToGenerateConsoleOutput(file_to=file_out)
            console_gen.server_scan_completed(scan_result)
            final_output = file_out.getvalue()

        # It succeeds and mentions the HTTP proxy
        assert final_output
        assert "HTTP PROXY" in final_output
        assert "Compression" in final_output
    def test_incomplete_scan_result(self):
        # Given a scan result that does not contain all the information needed by the Mozilla checker
        server_scan_result = ServerScanResultFactory.create()

        # When checking the server is compliant
        checker = MozillaTlsConfigurationChecker.get_default()
        # It fails
        with pytest.raises(ServerScanResultIncomplete):
            checker.check_server(
                against_config=MozillaTlsConfigurationEnum.MODERN,
                server_scan_result=server_scan_result,
            )
예제 #6
0
    def test(self):
        # Given a completed scan for a server
        scan_results = {
            ScanCommand.TLS_COMPRESSION:
            CompressionScanResult(supports_compression=True)
        }
        scan_result = ServerScanResultFactory.create(
            scan_commands_results=scan_results)

        # When converting it into to JSON
        result_as_json = json.dumps(asdict(scan_result),
                                    cls=sslyze.JsonEncoder)

        # It succeeds
        assert result_as_json
        assert "supports_compression" in result_as_json
예제 #7
0
    def test_server_scan_completed(self):
        # Given a completed scan for a server
        scan_results = {
            ScanCommand.TLS_COMPRESSION:
            CompressionScanResult(supports_compression=True)
        }
        scan_result = ServerScanResultFactory.create(
            scan_commands_results=scan_results)

        # When generating the console output for this server scan
        with StringIO() as file_out:
            console_gen = ConsoleOutputGenerator(file_to=file_out)
            console_gen.server_scan_completed(scan_result)
            final_output = file_out.getvalue()

        # It succeeds
        assert final_output
        assert "Compression" in final_output
예제 #8
0
    def test_server_scan_completed_with_error(self):
        # Given a completed scan for a server that triggered an error
        error_trace = TracebackExceptionFactory.create()
        scan_errors = {
            ScanCommand.TLS_COMPRESSION:
            ScanCommandError(reason=ScanCommandErrorReasonEnum.BUG_IN_SSLYZE,
                             exception_trace=error_trace)
        }
        scan_result = ServerScanResultFactory.create(
            scan_commands_errors=scan_errors)

        # When generating the console output for this server scan
        with StringIO() as file_out:
            console_gen = ConsoleOutputGenerator(file_to=file_out)
            console_gen.server_scan_completed(scan_result)
            final_output = file_out.getvalue()

        # It succeeds and displays the error
        assert final_output
        assert error_trace.stack.format()[0] in final_output
예제 #9
0
    def test_connectivity_test_failed(self):
        # Given a scan result where sslyze was unable to connect to the server
        server_scan_result = ServerScanResultFactory.create(
            scan_status=ServerScanStatusEnum.ERROR_NO_CONNECTIVITY)

        # When converting it to JSON, it succeeds
        json_output = SslyzeOutputAsJson(
            server_scan_results=[
                ServerScanResultAsJson.from_orm(server_scan_result)
            ],
            date_scans_started=datetime.utcnow(),
            date_scans_completed=datetime.utcnow(),
        )
        json_output_as_str = json_output.json(sort_keys=True,
                                              indent=4,
                                              ensure_ascii=True)
        assert json_output_as_str

        # And it can be parsed again
        assert SslyzeOutputAsJson.parse_raw(json_output_as_str)
예제 #10
0
    def test(self):
        # Given a completed scan for a server with the CERTIFICATE_INFO scan command
        server_location = ServerNetworkLocationViaDirectConnection.with_ip_address_lookup(
            "www.facebook.com", 443)
        server_info = ServerConnectivityTester().perform(server_location)
        plugin_result = CertificateInfoImplementation.scan_server(server_info)
        scan_results = {ScanCommand.CERTIFICATE_INFO: plugin_result}
        scan_result = ServerScanResultFactory.create(
            scan_commands_results=scan_results)

        # When converting it into to JSON
        result_as_json = json.dumps(asdict(scan_result),
                                    cls=sslyze.JsonEncoder)

        # It succeeds
        assert result_as_json

        # And complex object like certificates were properly serialized
        assert "issuer" in result_as_json
        assert "subject" in result_as_json
예제 #11
0
    def test_server_scan_completed(self):
        # Given a completed scan for a server
        scan_results = {
            ScanCommandEnum.TLS_COMPRESSION:
            CompressionScanResult(supports_compression=True)
        }
        scan_result = ServerScanResultFactory.create(
            scan_commands_results=scan_results)

        # When generating the JSON output for this server scan
        with StringIO() as file_out:
            json_generator = JsonOutputGenerator(file_to=file_out)
            json_generator.server_scan_completed(scan_result)

            # We call scans_completed() because this is when the output actually gets written to the file
            json_generator.scans_completed(0.2)
            final_output = file_out.getvalue()

        # It succeeds
        assert final_output
        assert "supports_compression" in final_output
예제 #12
0
    def test_server_scan_completed(self):
        # Given a completed scan for a server when the compression scan command was run
        compression_attempt = CompressionScanAttempt(
            status=ScanCommandAttemptStatusEnum.COMPLETED,
            error_reason=None,
            error_trace=None,
            result=CompressionScanResult(supports_compression=True),
        )
        scan_result = ServerScanResultFactory.create(
            scan_result=AllScanCommandsAttemptsFactory.create(
                {"tls_compression": compression_attempt}))

        # When generating the console output for this server scan
        with StringIO() as file_out:
            console_gen = ObserverToGenerateConsoleOutput(file_to=file_out)
            console_gen.server_scan_completed(scan_result)
            final_output = file_out.getvalue()

        # It succeeds
        assert final_output
        assert "Compression" in final_output
예제 #13
0
    def test_server_scan_completed_with_proxy(self):
        # Given a completed scan for a server
        server_info = ServerConnectivityInfoFactory.create(
            # And sslyze connected to the server via an HTTP proxy
            server_location=ServerNetworkLocationViaHttpProxyFactory.create())
        scan_results = {
            ScanCommand.TLS_COMPRESSION:
            CompressionScanResult(supports_compression=True)
        }
        scan_result = ServerScanResultFactory.create(
            server_info=server_info, scan_commands_results=scan_results)

        # When generating the console output for this server scan
        with StringIO() as file_out:
            console_gen = ConsoleOutputGenerator(file_to=file_out)
            console_gen.server_scan_completed(scan_result)
            final_output = file_out.getvalue()

        # It succeeds and mentions the HTTP proxy
        assert final_output
        assert "HTTP PROXY" in final_output
        assert "Compression" in final_output
예제 #14
0
    def test(self):
        # Given a bunch of scan results
        all_server_scan_results = [
            ServerScanResultFactory.create() for _ in range(5)
        ]

        # When converting them to JSON, it succeeds
        json_output = SslyzeOutputAsJson(
            server_scan_results=[
                ServerScanResultAsJson.from_orm(result)
                for result in all_server_scan_results
            ],
            date_scans_started=datetime.utcnow(),
            date_scans_completed=datetime.utcnow(),
        )
        json_output_as_str = json_output.json(sort_keys=True,
                                              indent=4,
                                              ensure_ascii=True)
        assert json_output_as_str

        # And it can be parsed again
        assert SslyzeOutputAsJson.parse_raw(json_output_as_str)
예제 #15
0
    def test_server_scan_completed_with_error(self):
        # Given a completed scan for a server that triggered an error
        error_trace = TracebackExceptionFactory.create()
        compression_attempt = CompressionScanAttempt(
            status=ScanCommandAttemptStatusEnum.ERROR,
            error_reason=ScanCommandErrorReasonEnum.BUG_IN_SSLYZE,
            error_trace=error_trace,
            result=None,
        )
        scan_result = ServerScanResultFactory.create(
            scan_result=AllScanCommandsAttemptsFactory.create(
                {"tls_compression": compression_attempt}))

        # When generating the console output for this server scan
        with StringIO() as file_out:
            console_gen = ObserverToGenerateConsoleOutput(file_to=file_out)
            console_gen.server_scan_completed(scan_result)
            final_output = file_out.getvalue()

        # It succeeds and displays the error
        assert final_output
        assert error_trace.stack.format()[0] in final_output
예제 #16
0
    def test_server_scan_completed_with_error(self):
        # Given a completed scan for a server that triggered an error
        error_trace = TracebackExceptionFactory.create()
        scan_errors = {
            ScanCommandEnum.TLS_COMPRESSION:
            ScanCommandError(reason=ScanCommandErrorReasonEnum.BUG_IN_SSLYZE,
                             exception_trace=error_trace)
        }
        scan_result = ServerScanResultFactory.create(
            scan_commands_errors=scan_errors)

        # When generating the JSON output for this server scan
        with StringIO() as file_out:
            json_generator = JsonOutputGenerator(file_to=file_out)
            json_generator.server_scan_completed(scan_result)

            # We call scans_completed() because this is when the output actually gets written to the file
            json_generator.scans_completed(0.2)
            final_output = file_out.getvalue()

        # It succeeds and displays the error
        assert final_output
        assert error_trace.exc_type.__name__ in final_output