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)
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)
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)
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)
def run_verify(args): insp, insp_path = load_insp(args) try: d = x.file_to_dict(args.blob) blob = x.Blob.from_dict(d) try: resp = insp.verify_blob(blob) x.to_file(args.output, resp) print("The Response was succesfully created. Stored in file: ", args.output) except: print("Error when trying to validate blob") except: print("Error when trying to parse given blob")
def test_entity_io(self): # entity = user filename = "tests/tmp/test_entity_save" usr = self.usr x.to_file(filename, usr) usr2 = x.load_usr(filename) self.assertEqual(usr.ID, usr2.ID) keys1 = usr.key_pair keys2 = usr2.key_pair self.assertEqual(keys1, keys2) for k in usr.database.keys(): self.assertEqual(usr.database[k], usr2.database[k]) for k in usr2.database.keys(): self.assertEqual(usr.database[k], usr2.database[k]) # entity = service src = self.src x.to_file(filename, src) src2 = x.load_src(filename) self.assertEqual(src.ID, src2.ID) keys1 = src.key_pair keys2 = src2.key_pair self.assertEqual(keys1, keys2) for k in src.database.keys(): self.assertEqual(src.database[k], src2.database[k]) for k in src2.database.keys(): self.assertEqual(src.database[k], src2.database[k]) # entity = inspector insp = self.insp x.to_file(filename, insp) insp2 = x.load_insp(filename) self.assertEqual(insp.ID, insp2.ID) self.assertEqual(insp.scope, insp2.scope) self.assertEqual(insp.vko_pair, insp2.vko_pair) self.assertEqual(insp.sign_pair, insp2.sign_pair) for k in insp.database.keys(): self.assertEqual(insp.database[k], insp2.database[k]) for k in insp2.database.keys(): self.assertEqual(insp.database[k], insp2.database[k]) # entity = auth center auth = self.auth x.to_file(filename, auth) auth2 = x.load_auth(filename) self.assertEqual(auth.total_ids, auth2.total_ids) self.assertEqual(auth.users, auth2.users) self.assertEqual(auth.id_scope, auth2.id_scope) self.assertEqual(auth.services, auth2.services) self.assertEqual(auth.inspectors_sig, auth2.inspectors_sig) self.assertEqual(auth.inspectors_vko, auth2.inspectors_vko)
def run_form(args): usr, usr_path = load_usr(args) d = x.file_to_dict(args.req) req = x.Request.from_dict(d) try: blob = usr.create_blob(req, data=args.secdata) except: print("Problems with forming Blob. Request might be damaged or wrong") blob = None if blob is not None: x.to_file(args.output, blob) print("The blob was succesfully created. Stored in file: ", args.output) x.to_file(usr_path, usr) x.to_file(auth_path(args), usr.AUTH)
def run_form(args): src, src_path = load_src(args) due = datetime.datetime.strptime(args.due, '%Y-%m-%d').date() ttl = x.TTL(due) req = src.create_request(args.uid, args.scope, ttl) if args.verbose: print("The following request was formed:") print("Src ID: ", req.srcid) print("User ID: ", req.uid) print("Scope: ", req.scope) print("Due to: ", req.ttl.expired) x.to_file(args.output, req) if args.verbose: print("The following file for output was used: ", args.output) print("Request was succesfully created. Stored in file: ", args.output) x.to_file(src_path, src) x.to_file(auth_path(args), src.AUTH)
def run_adduser(args): insp, insp_path = load_insp(args) insp.add_user(args.uid, args.secdata) print("User personal data was succesfully added") x.to_file(insp_path, insp) x.to_file(auth_path(args), insp.AUTH)
def parse_CLI(arguments): parser = argparse.ArgumentParser(description='Registration script') parser.add_argument('--service', '-s', action="store_true", dest="src") parser.add_argument('--user', '-u', action="store_true", dest="usr") parser.add_argument('--inspector', '-i', action="store_true", dest="insp") parser.add_argument('--scope', '-S', action="store", dest="scope") parser.add_argument('--auth', '-a', action="store", dest="AUTH") parser.add_argument('--key' '-k', action="store", dest="key") parser.add_argument('--output', '-o', action="store", dest="output") parser.add_argument('--verbose', '-v', action="store_true") args = parser.parse_args(arguments) check = check_args(args) if check: return args else: return None if __name__ == "__main__": args = parse_CLI(sys.argv[1:]) if args is not None: AUTH = x.load_auth(auth_path(args)) if args.src: create_service(args, AUTH) elif args.usr: create_user(args, AUTH) else: create_inspector(args, AUTH) x.to_file(auth_path(args),AUTH)