Ejemplo n.º 1
0
def eajwt_refresh(ea_jwt, sec = int(time.time() / 30)-1):
    if sec == int(time.time() / 30): #if in same window, keep same token
        print("inside if")
        auth_header = {'Authorization': 'Bearer ' + ea_jwt}
        return ea_jwt, auth_header
    try: #if trying refresh without login
        payload = ref_payload(generate_pass(seed_path), ea_jwt)
        
        totpAlreadyUsed = False
        retries = 0
        response = ""
        while not(totpAlreadyUsed) and retries < 3:
            retries+=1
            response = requests.post(server_url + '/login', cert=client_cert, json=payload, verify=False)
            totpAlreadyUsed = not(isTOTPExpired(response))
            if(not(totpAlreadyUsed)):
                print("TOTP Window has already been used. Retrying...")
                time.sleep(15)
        check_status(response)
        if(globalenv.verboseMode):
            print(response.json())
        jwt_token = response.json()[1]['accessToken']
        auth_header = {'Authorization': 'Bearer ' + jwt_token}

        return jwt_token, auth_header
    except:
        auth_header = {'Authorization': 'Bearer ' + ea_jwt}
        return ea_jwt, auth_header
Ejemplo n.º 2
0
    def runner_supp(comments, supporting_paths, itar, server_url, client_cert,
                    auth_header):
        threads = []
        cert_supp = []
        with ThreadPoolExecutor(max_workers=20) as executor:
            print('\nSending supporting documents')
            if len(comments) < len(supporting_paths):  #Check formatting
                print(
                    "Error: Comments array must be the same length as that of the supporting file paths"
                )
                exit()

            print("Your Supporting Documentation ID(s): ")
            #cert_supp = [] #Get and format IDs and JWTs for certify
            for i in range(len(supporting_paths)):
                threads.append(
                    executor.submit(send_supp, comments[i],
                                    supporting_paths[i], itar, server_url,
                                    client_cert, auth_header))

            for task in as_completed(threads):
                #Check status code of responses and create cert_sup for certify
                supp_1, response = task.result()
                check_status(response)
                cert_supp.append(supp_1)

            log("cert_supp", cert_supp)
            return cert_supp
Ejemplo n.º 3
0
    def send_certify(self, cert_supp, client_cert, login_jwt, esv_version):
            
        if self.certify:
            print("Starting Certification Process...")
            auth_header = {'Authorization': 'Bearer ' + login_jwt}

            cert_temp = open('jsons/temp_certify.json', 'w')

            # TODO: Build this automatically 
            cert_temp.write("[{\"esvVersion\": \"1.0\"},{\"entropyId\": \"E123\", \"isITAR\": false,\"limitEntropyAssessmentToSingleModule\": false,\"moduleId\": null,\"vendorId\": null,\"supportingDocumentation\": [],\"entropyAssessments\":[{\"eaId\": null,\"oeId\": null,\"accessToken\": \"<jwt-with-claims-for-eaId1>\"}]}]")
            #cert_temp.write("[{\"esvVersion\": \"1.0\"},{\"itar\": false,\"limitEntropyAssessmentToSingleModule\": false,\"moduleId\": null,\"vendorId\": null,\"supportingDocumentation\": [],\"entropyAssessments\":[{\"entropyId\": null,\"oeId\": null,\"accessToken\": \"<jwt-with-claims-for-eaId1>\"}]}]")

            cert_temp.close()
            cert_temp = open('jsons/temp_certify.json','r')
            cert_file = json.load(cert_temp)
            #import os; os.remove('jsons/temp_certify.json')
            cert_json = cert_prep(cert_file, cert_supp, esv_version, self.single_mod, self.mod_id, self.vend_id, self.entropy_id, self.ea_id, self.oe_id, self.entr_jwt)
            if globalenv.verboseMode:
                print("Outgoing cert request = ")
                print(cert_json)
            response = requests.request("POST", self.server_url + '/certify', cert = client_cert, headers=auth_header, json=cert_json)
            check_status(response)
            status, messageList, elementList = start.parsing.parse_certify_response(response)

            print("\nStatus: " + status + "\n")
            print("Message List: ")
            print(*messageList, sep = "\n")
            print("")
            print("Entropy Assessment:")
            #print(*elementList, sep = "\n")
            for element in elementList:
                print("Location:" + str(element["location"]))
                for message in element["messageList"]:
                    print("   Message:" + message)
Ejemplo n.º 4
0
    def runner_stats(server_url, ea_id, df_ids, entr_jwt, client_cert):
        threads = []
        print("Getting Status...")
        print("Waiting for data file tests to complete...")
        with ThreadPoolExecutor(max_workers=20) as executor:
            for id in df_ids:
                threads.append(
                    executor.submit(get_status, server_url, ea_id, id,
                                    entr_jwt, client_cert))

            #Check status codes of responses
            for task in as_completed(threads):
                check_status(task.result())
Ejemplo n.º 5
0
def df_upload_raw(server_url, ea_id, df_ids, jwt, raw_noise, client_cert):
    url = server_url + "/entropyAssessments/" + ea_id + "/dataFiles/"
    auth_header = {'Authorization': 'Bearer ' + jwt}
    payload = {}

    #Send rawNoise
    files = [('dataFile', (os.path.basename(raw_noise), open(raw_noise, 'rb'),
                           'application/octet-stream'))]
    response = requests.request("POST",
                                url + df_ids[0],
                                cert=client_cert,
                                headers=auth_header,
                                data=payload,
                                files=files)
    check_status(response)
    return response
Ejemplo n.º 6
0
    def jwt_refresh(seed_path, client_cert, server_url):

        payload = login_payload(generate_pass(seed_path))
        if globalenv.verboseMode:
            print ("JWT Refresh Outgoing:")
            print (payload)
        
        response = requests.post(server_url + '/login', cert=client_cert, json=payload)
        if globalenv.verboseMode:
            print ("JWT Refresh Incoming:")
            print (response)
        check_status(response)     
        jwt_token = response.json()[1]['accessToken']
        auth_header = {'Authorization': 'Bearer ' + jwt_token}

        return jwt_token, auth_header
Ejemplo n.º 7
0
    def runner_data(server_url, ea_id, df_ids, entr_jwt, conditioned, rawNoise,
                    restartTest, client_cert):
        threads = []
        with ThreadPoolExecutor(max_workers=20) as executor:
            #Send raw and restart
            threads.append(
                executor.submit(df_upload_raw, server_url, ea_id, df_ids,
                                entr_jwt, rawNoise, client_cert))
            threads.append(
                executor.submit(df_upload_restart, server_url, ea_id, df_ids,
                                entr_jwt, restartTest, client_cert))
            #Send Conditioning
            for i in range(len(conditioned)):
                threads.append(
                    executor.submit(df_upload_cond, server_url, ea_id, df_ids,
                                    entr_jwt, i, conditioned, client_cert))

            #Check status codes of responses
            for task in as_completed(threads):
                check_status(task.result())

            print("Data files submitted!\n")
Ejemplo n.º 8
0
def send_supp(comments, supporting_path, itar, server_url, client_cert,
              auth_header):
    cert_supp = []
    supp_name = os.path.basename(supporting_path)
    files = [('sdFile', (supp_name, open(supporting_path,
                                         'rb'), 'application/pdf'))]
    # changed 3/15/2022
    #payload={'itar': itar,'sdComments': comments}
    payload = {'isITAR': itar, 'sdComments': comments}
    response = requests.request("POST",
                                server_url + '/supportingDocumentation',
                                cert=client_cert,
                                headers=auth_header,
                                data=payload,
                                files=files)
    response_1 = response.json()[1]
    sd_id = response_1['sdId']
    print(supp_name + ": " + str(sd_id) + " | Status: " +
          str(response_1['status']))
    # Changed 3/15/2022
    cert_supp.append({"sdId": sd_id, "accessToken": response_1["accessToken"]})
    check_status(response)
    return cert_supp, response
Ejemplo n.º 9
0
    def send_reg(self):
        
        print("\nSending Entropy Assessment Registration...")
        if globalenv.verboseMode:
            print ("Send Registration Outgoing:")
            print (self.assessment_reg)
        response = requests.post(self.server_url + '/entropyAssessments', headers=self.auth_header, cert=self.client_cert, json=self.assessment_reg, verify=False)
        if globalenv.verboseMode:
            print ("Send Registration Incoming:")
            print (response)
        check_status(response)
        print("Sent.")

        response = response.json()
        ea_id, df_ids = get_ids(response)

        entr_jwt = response[1]['accessToken']
    
        log("entr_jwt", entr_jwt)
        log("df_ids", df_ids)
        log("ea_id", ea_id)
        self.ea_id = ea_id
        self.df_ids = df_ids
        self.entr_jwt = entr_jwt