def subject(email): """Create a subject """ url=vars.eHost+'/htsp/subject' conf_data = common.parse(vars.fileConf) if not conf_data: print("Bad config file") return if (not "jwt" in conf_data): print("You need to login first") return if (not "subject" in conf_data): print("You need to init first") return if (not isinstance(conf_data["subject"],dict)): print("Bad subject") return code = email message = {"subject": code, "type": "email"} headers={"Authorization":conf_data["jwt"]} response=common.sendingPost(url,message,headers) if (not email in conf_data): conf_data[email]=[] if response["status_code"] != 200: print(json.dumps(response["content"],indent=2)) return conf_data["subject"][email] = response["content"]["id_sec"] with open(vars.fileConf, 'w') as outfile: json.dump(conf_data, outfile,indent=2) print(response["content"]) code = input("Your email verification code: ") url=vars.eHost+'/htsp/verification/'+code response=common.sendingGet(url,headers) print(json.dumps(response["content"],indent=2))
def verify(file_sign): """Verify a file """ for i in file_sign: print('\n'+i.name) message = common.parse(i.name+'_hjws.json') if not message: print("Bad json file: ", i.name) return if ("id_hjws" in message): url=vars.eHost+'/htsp/hjws/'+message["id_hjws"] response=common.sendingGet(url) if response["status_code"] != 200: url=vars.eHost+'/htsp/htsr' response=common.sendingPost(url, message) if response["status_code"] != 200: print(json.dumps(response["content"],indent=2)) return else: url=vars.eHost+'/htsp/htsr' response=common.sendingPost(url, message) if response["status_code"] != 200: print(json.dumps(response["content"],indent=2)) return file_hash = common.hashCreate(response["content"]["alg"],i) if(file_hash==0): print("Bad algorithm") return if file_hash != response["content"]["hash"]: print("Bad file sign") else: print(json.dumps(response["content"],indent=2))
def init(): """Init a new account """ url=vars.eHost+'/htsp/subject' conf_data = common.parse(vars.fileConf) if not conf_data: print("Bad config file") return if (not "email" in conf_data): print("Bad 3vidence.json config file") return if (not "jwt" in conf_data): print("You need to login first") return email = conf_data["email"] message = {"subject": email, "type": "email"} headers={"Authorization":conf_data["jwt"]} response=common.sendingPost(url,message,headers) if response["status_code"] == 200: conf_data["subject"]= {conf_data["email"]:response["content"]["id_sec"]} with open(vars.fileConf, 'w') as outfile: json.dump(conf_data, outfile,indent=2) code = input("Your email verification code: ") url=vars.eHost+'/htsp/verification/'+code response=common.sendingGet(url,headers) print(json.dumps(response["content"],indent=2)) if response["status_code"] != 200: print("Bad Verification code") return if (not conf_data["subject"][conf_data["email"]]): print("Subject error") return url=vars.eHost+'/htsp/branch' branch = input("Your branch name: ") if ("branch" in conf_data): if(branch in conf_data["branch"]): print("This branch already exists") return message = {"id_sec": conf_data["subject"][conf_data["email"]],"branch":branch} headers={"Authorization":conf_data["jwt"]} response=common.sendingPost(url,message,headers) if response["status_code"] != 200: print(json.dumps(response["content"],indent=2)) return if (not "branch" in conf_data): conf_data["branch"]= {branch:response["content"]["api_key"]} elif (isinstance(conf_data["branch"],dict)): conf_data["branch"][branch]= response["content"]["api_key"] else: conf_data["branch"]= {branch:response["content"]["api_key"]} if(not email in conf_data): conf_data[email]=[branch] elif (isinstance(conf_data[email],list)): conf_data[email].append(branch) else: conf_data[email]=[branch] with open(vars.fileConf, 'w') as outfile: json.dump(conf_data, outfile,indent=2) print("Init OK!")
def signup(): """ 3vidence Signup """ code = input("Your verification code: ") url = vars.eHost + '/auth/verification/' + code response = common.sendingGet(url) print(json.dumps(response["content"], indent=2))
def info(): """Info account """ url=vars.eHost+'/htsp/info' conf_data = common.parse(vars.fileConf) if not conf_data: print("Bad config file") return if (not "jwt" in conf_data): print("You need to login first") return headers={"Authorization":conf_data["jwt"]} response=common.sendingGet(url,headers) print(json.dumps(response["content"],indent=2))
def get(file_sign): """Get a cloud id_hjws """ for i in file_sign: data = common.parse(i.name) if not data: print("Bad hjws file") return if (not "id_hjws" in data): print("Bad id_hjws") return url=vars.eHost+'/htsp/hjws/'+data["id_hjws"] response=common.sendingGet(url) print('\n'+i.name) print(json.dumps(response["content"],indent=2))
def info_key(key_name): """Info API key """ url=vars.eHost+'/htsp/info/apikey' conf_data = common.parse(vars.fileConf) if not conf_data: print("Bad config file") return if (not key_name in conf_data["branch"]): print("Bad key name") return message = {"api_key": conf_data["branch"][key_name]} response1=common.sendingPost(url,message) url=vars.eHost+'/htsp/pubkey/'+conf_data["branch"][key_name].split('.')[0] response=common.sendingGet(url) response1["content"]["pubkey"] = response["content"] print(json.dumps(response1["content"],indent=2))
def get(file_sign): """Get a snippet """ for i in file_sign: print('\n'+i.name) message = common.parse(i.name) if not message: print("Bad json file: ", i.name) return if (not"id_data" in message): print("Bad snpt file: ", i.name) return url=vars.eHost+'/snippets/data/'+message["id_data"] response=common.sendingGet(url) if response["status_code"] != 200: print(json.dumps(response["content"],indent=2)) return print(json.dumps(response["content"],indent=2))
def health(): """Health systems status """ url=vars.eHost+'/htsp/health' response=common.sendingGet(url) print(json.dumps(response["content"],indent=2))