Exemple #1
0
def create_keys(args):
    if args.key is None:
        keys = [x.crypto.KeyPair()]
        if args.insp is not None:
            keys.append(x.crypto.KeyPair())
        printv("No key file was provided, random key is generated", args.verbose)
    else:
        with open(args.key, mode='rb') as file:
            raw = file.read(32)
            keys = [x.crypto.KeyPair(raw_key=raw)]
            if args.insp is not None:
                raw2 = file.read(32)
                keys.append(x.crypto.KeyPair(raw_key=raw2))
        printv("Key file ", args.key, " was used to generate the key(s)", args.verbose)
    return keys
Exemple #2
0
def load_src(args):
    if args.src is None:
        src_path = default.DEFAULT_SERVICE
        msg = noexplicit("Service")
        printv(msg, args.verbose)
    else:
         src_path = args.src
    try:
        src = x.load_src(src_path)
        src.AUTH = x.load_auth(auth_path(args))
        return src, src_path
    except x.SrcLoadError:
        print("Error when trying to load Src file")
        print("Service path: ", src_path)
        raise
    except x.AuthLoadError:
        print("Error when trying to load Auth file")
        print("Auth path: ", auth_path(args))
        raise
Exemple #3
0
def load_insp(args):
    if args.insp is None:
        insp_path = default.DEFAULT_INSPECTOR
        msg = noexplicit("Inspector")
        printv(msg, args.verbose)
    else:
        insp_path = args.insp

    try:
        insp = x.load_insp(insp_path)
        insp.AUTH = x.load_auth(auth_path(args))
        return insp, insp_path
    except x.InspLoadError:
        print("Error when trying to load Inspector file")
        print("Inspector path: ", insp_path)
        raise
    except x.AuthLoadError:
        print("Error when trying to load Auth file")
        print("Auth path: ", auth_path(args))
        raise
Exemple #4
0
def load_usr(args):
    if args.usr is None:
        usr_path = default.DEFAULT_USER
        msg = noexplicit("User")
        printv(msg, args.verbose)
    else:
        usr_path = args.usr

    try:
        usr = x.load_usr(usr_path)
        usr.AUTH = x.load_auth(auth_path(args))
        return usr, usr_path
    except x.UsrLoadError:
        print("Error when trying to load User file")
        print("User path: ", usr_path)
        raise
    except x.AuthLoadError:
        print("Error when trying to load Auth file")
        print("Auth path: ", auth_path(args))
        raise
Exemple #5
0
def create_service(args, AUTH):
    printv("Generating Service file...",args.verbose)
    keys = create_keys(args)
    src = x.Service(keys=keys[0])
    AUTH.reg_service(src)
    if args.output is not None:
        out_file = args.output
    else:
        out_file = default.DEFAULT_SERVICE
        printv("No output path was provided.",args.verbose)
    printv("The following file for output is used: ", out_file, args.verbose)    
    x.to_file(out_file, src)
    printv("Service file was successfully created.",args.verbose)
Exemple #6
0
def create_user(args, AUTH):
    printv("Generating User file...", args.verbose)
    keys = create_keys(args)
    usr = x.AgentUser(keys=keys[0])
    AUTH.reg_user(usr)
    if args.output is not None:
        out_file = args.output
    else:
        out_file = default.DEFAULT_USER 
        printv("No output path was provided.",args.verbose)
    printv("The following file for output is used: ", out_file, args.verbose)    
    x.to_file(out_file, usr)
    printv("User file was successfully created.", args.verbose)
Exemple #7
0
def create_inspector(args, AUTH):
    printv("Generating Inspector file...", args.verbose)
    keys = create_keys(args)
    insp = x.Inspector(args.scope, keys_sign=keys[0], keys_vko=keys[1])
    AUTH.reg_inspector(insp)
    if args.output is not None:
        out_file = args.output
    else:
        out_file = default.DEFAULT_INSPECTOR 
        printv("No output path was provided.", args.verbose)
    printv("The following file for output is used: ", out_file, args.verbose)
    x.to_file(out_file, insp)
    printv("Inspector file was successfully created.", args.verbose)
Exemple #8
0
def run_create(args):
    if args.output is not None:
        out_file = args.output
    else:
        out_file = default.DEFAULT_AUTH
        printv("No output path was provided.", args.verbose)
    if args.verbose:
        print("The following file for output is used: ", out_file)
    printv("Creating auth center file.", args.verbose)
    AUTH = x.AuthCenter()
    x.to_file(out_file, AUTH)
    printv("Auth Center file was succesfully generated.", args.verbose)