示例#1
0
def slide_bundle(bundle):
    cybox.utils.caches.cache_clear()

    setup_logger(bundle["id"])
    stix_package = convert_bundle(bundle)
    validator_options = get_validator_options()

    if stix_package:
        xml = stix_package.to_xml(encoding=None)
        validator_options.in_files = io.StringIO(xml)

        try:
            scripts.set_output_level(validator_options)

            validation_results = scripts.validate_file(
                validator_options.in_files, validator_options)
            results = {stix_package.id_: validation_results}

            # Print stix-validator results
            scripts.print_results(results, validator_options)
        except (errors.ValidationError, IOError) as ex:
            scripts.error("Validation error occurred: '%s'" % str(ex),
                          codes.EXIT_VALIDATION_ERROR)
        except Exception:
            log.exception("Fatal error occurred", extra={'ecode': 0})
            sys.exit(codes.EXIT_FAILURE)

        return xml
示例#2
0
def slide_file(fn, encoding="utf-8"):
    cybox.utils.caches.cache_clear()

    setup_logger(fn)
    validator_options = get_validator_options()

    with io.open(fn, "r", encoding=encoding) as json_data:
        json_content = json.load(json_data)

    obj = stix2.parse(json_content)
    stix_package = convert_bundle(obj)

    if stix_package:
        xml = stix_package.to_xml(encoding=None)
        validator_options.in_files = io.StringIO(xml)

        try:
            scripts.set_output_level(validator_options)

            validation_results = scripts.validate_file(
                validator_options.in_files, validator_options)
            results = {stix_package.id_: validation_results}

            # Print stix-validator results
            scripts.print_results(results, validator_options)
        except (errors.ValidationError, IOError) as ex:
            scripts.error("Validation error occurred: '%s'" % str(ex),
                          codes.EXIT_VALIDATION_ERROR)
        except Exception:
            log.exception("Fatal error occurred", extra={'ecode': 0})
            sys.exit(codes.EXIT_FAILURE)

        return xml
示例#3
0
def slide_string(string):
    obj = stix2.parse(string)
    setup_logger(obj["id"])

    stix_package = convert_bundle(obj)

    if stix_package:
        return stix_package.to_xml(encoding=None)
示例#4
0
def slide_file(fn, encoding="utf-8"):
    setup_logger(fn)

    with io.open(fn, "r", encoding=encoding) as json_data:
        json_content = json.load(json_data)

    obj = stix2.parse(json_content)
    # TODO: validate STIX 2.0 content - what to do if it is invalid??
    stix_package = convert_bundle(obj)

    if stix_package:
        return stix_package.to_xml(encoding=None)
示例#5
0
def slide_bundle(bundle):
    setup_logger(bundle["id"])
    stix_package = convert_bundle(bundle)

    if stix_package:
        return stix_package.to_xml(encoding=None)