Ejemplo n.º 1
0
        # Convert JADN Abstract Syntax (JAS) to JADN

        print(os.path.join(os.getcwd(), ifname + ":"))
        source_s = ifname + ".jas"
        dest = ofname + "_gens"
        schema_s = jas_load(source_s)
        jadn_check(schema_s)
        jadn_dump(schema_s, dest + ".jadn", source_s)
        jadn_analyze(schema_s)

        # Convert JADN to JAS, prettyprinted JADN, and property tables

        source = ifname + ".jadn"
        dest = ofname + "_genj"
        schema = jadn_load(source)
        jas_dump(schema, dest + ".jas", source)
        jadn_dump(schema, dest + ".jadn", source)
        table_dump(schema, dest + ".xlsx", source)

        # Check that they match
        try:
            assert schema == schema_s
        except AssertionError:
            print('Warning:', source_s, '!=', source)
            t1 = {t[0]:t for t in schema_s['types']}
            t2 = {t[0]:t for t in schema['types']}
            for t in set(t1) & set(t2):
                if t1[t] != t2[t]:
                    print('  x', t)
Ejemplo n.º 2
0
import os
import json
from libs.codec.codec import Codec
from libs.codec.codec_utils import flatten
from libs.codec.jadn import jadn_load

# OpenC2 producer application:

command1 = {  # Python literals use either single or double quotes - no difference in API object
    "action": "mitigate",
    'target': {
        "domain_name": 'cdn.badco.org'
    }
}

schema = jadn_load(os.path.join(
    "schema", "openc2.jadn"))  # Load and validate the OpenC2 schema
codec = Codec(schema, verbose_rec=True, verbose_str=True
              )  # Create an OpenC2 encoder/decoder (JSON-Verbose encoding)
message1 = codec.encode("OpenC2Command",
                        command1)  # Validate and encode the command
print("Command to be sent (API)         =", command1)
print("Sent Message (JSON-v string)     =",
      json.dumps(message1))  # Single quotes are invalid in JSON

# OpenC2 consumer application:

message2 = '[32,{"7":"cdn.badco.org"}]'  # Received OpenC2 command in JSON-minified format
codec.set_mode(verbose_rec=False,
               verbose_str=False)  # Tell codec to use JSON-minified encoding
command2 = codec.decode(
    "OpenC2Command", json.loads(message2))  # Validate and decode the command
Ejemplo n.º 3
0
 def setUp(self):
     schema = jadn_load(os.path.join("schema", "relax1.jadn"))
     self.tc = Codec(schema)
 def setUp(self):
     schema = jadn_load(os.path.join("schema", "openc2.jadn"))
     self.tc = Codec(schema, True, True)