Esempio n. 1
0
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))
Esempio n. 2
0
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!")
Esempio n. 3
0
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))
Esempio n. 4
0
def sign(file_sign,key_name,hash,desc,cloud):
    """Sign a file
    """
    url=vars.eHost+'/htsp/htsq'
    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
    for i in file_sign:
        file_hash = common.hashCreate(hash,i)
        if(file_hash==0):
            print("Bad algorithm")
            return
        if (cloud == "False"):
            cloud = False
        else:
            cloud = True
        message = {"api_key": conf_data["branch"][key_name], "algorithm": hash,
            "hash":file_hash, "cloud": cloud,"desc": desc}
        response=common.sendingPost(url,message)
        if response["status_code"] != 200:
            print('\n'+i.name)
            print(json.dumps(response["content"],indent=2))
            return
        print("File signed OK!",i.name)
        with open(i.name+'_hjws.json', 'w') as outfile:
            json.dump(response["content"], outfile,indent=2)
Esempio n. 5
0
def post(file_sign,key_name,hash,desc):
    """Create a snippets signed
    """
    url=vars.eHost+'/snippets'
    algs=["sha224","sha256","sha384","sha512","whirlpool", "sha3_224","sha3_256","sha3_384","sha3_512"]
    if (not hash in algs):
        print("Bad algorithm")
        return 0
    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
    for i in file_sign:
        data = common.parse(i.name)
        if not data:
            print("Bad json file: ", i.name)
            return
        message = {"api_key": conf_data["branch"][key_name],"data": data,"algorithm": hash,"desc": desc }
        response=common.sendingPost(url,message)
        if response["status_code"] != 200:
            print(json.dumps(response["content"],indent=2))
            return
        print("Snippet OK!: ", i.name)
        with open(i.name+'_snpt.json', 'w') as outfile:
            json.dump(response["content"], outfile,indent=2)
Esempio n. 6
0
def search(file_sign,hash):
    """search a file by hash
    """
    url=vars.eHost+'/htsp/hash'
    for i in file_sign:
        file_hash = common.hashCreate(hash,i)
        if(file_hash==0):
            print("Bad algorithm")
            return
        message = {"hash": file_hash}
        response=common.sendingPost(url,message)
        print('\n'+i.name)
        print(json.dumps(response["content"],indent=2))
Esempio n. 7
0
def info_key(key_name):
    """Info API key
    """
    url=vars.eHost+'/snippets/info'
    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]}
    response=common.sendingPost(url,message)
    print(json.dumps(response["content"],indent=2))
Esempio n. 8
0
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))
Esempio n. 9
0
def sign_anon(file_sign,hash):
    """Sign a file anonymously
    """
    url=vars.eHost+'/htsp/open/htsq'
    for i in file_sign:
        file_hash = common.hashCreate(hash,i)
        if(file_hash==0):
            print("Bad algorithm")
            return
        message = {"algorithm": hash,"hash":file_hash}
        response=common.sendingPost(url,message)
        if response["status_code"] != 200:
            print('\n'+i.name)
            print(json.dumps(response["content"],indent=2))
            return
        print("File signed OK!: ", i.name)
        with open(i.name+'_hjws.json', 'w') as outfile:
            json.dump(response["content"], outfile,indent=2)
Esempio n. 10
0
def branch(email,suite):
    """Create a branch
    """
    url=vars.eHost+'/htsp/branch'
    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 email in conf_data["subject"]):
        print("Bad subject")
        return
    if (not "branch" in conf_data):
        print("You need to init first")
        return
    if (not isinstance(conf_data["branch"],dict)):
        print("Bad branches")
        return
    if (not email in conf_data):
        print("You need to verify your subject")
        return
    if (not isinstance(conf_data[email],list)):
        print("You need to init first")
        return
    branch = input("Your branch name: ")
    if (branch in conf_data["branch"]):
        print("Branch already exists")
        return
    message = {"id_sec": conf_data["subject"][email],"branch":branch, "suite": suite}
    headers={"Authorization":conf_data["jwt"]}
    response=common.sendingPost(url,message,headers)
    if response["status_code"] != 200:
        print(json.dumps(response["content"],indent=2))
        return
    conf_data["branch"][branch]= response["content"]["api_key"]
    conf_data[email].append(branch)
    with open(vars.fileConf, 'w') as outfile:
        json.dump(conf_data, outfile,indent=2)
    print("Branch OK!")
Esempio n. 11
0
def login():
    """
    3vidence login
    """
    url = vars.eHost + '/auth/login'
    conf_data = common.parse(vars.fileConf)
    if not conf_data:
        print("Bad config file")
        return
    if (not "email" in conf_data) or (not "password" in conf_data):
        print("Bad email/password")
        return
    data = {"email": conf_data["email"], "password": conf_data["password"]}
    response = common.sendingPost(url, data)
    if response["status_code"] != 200:
        print(json.dumps(response["content"], indent=2))
        return
    conf_data["jwt"] = response["content"]["jwt"]
    with open(vars.fileConf, 'w') as outfile:
        json.dump(conf_data, outfile, indent=2)
    print("Login OK")