Skip to content

Commit

Permalink
RELEASE/v1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
celic committed Nov 21, 2023
1 parent 6434612 commit 2b38f4d
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 37 deletions.
1 change: 0 additions & 1 deletion client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ Note that only config.json and run.json are the only JSONs that should be filled
"Certify": <BOOLEAN>,
"moduleID": <INT referring to ID of module>,
"vendorID": <INT referring to ID of vendor>,
"itar": <BOOLEAN>,
"entropyID": <STRING referring to ID of submitted Entropy ID>
},
"Assessment": {
Expand Down
20 changes: 10 additions & 10 deletions client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ def prev_run(server_url, ea_id, df_ids, jwt_token, client_cert):
#Start (remember to change parse try statement)
client_cert, seed_path, server_url, esv_version = parse_config(config_path)
log("config_path", config_path)
assessment_reg, raw_noise, restart_test, conditioned, supporting_paths, comments, sdType, mod_id, vend_id, entropyId, oe_id, certify, single_mod, responses, itar = parse_run(run_path)
assessment_reg, raw_noise, restart_test, conditioned, supporting_paths, comments, sdType, mod_id, vend_id, entropyId, oe_id, certify, single_mod, responses = parse_run(run_path)
log("run_path", run_path)

if run_type == "full":
print("*** Entropy Source Validation Client tool startup!")
clear_previous_run()
ea = EntropyAssessment(client_cert, server_url, assessment_reg, seed_path, mod_id, vend_id, entropyId, oe_id, certify, single_mod, itar)
ea = EntropyAssessment(client_cert, server_url, assessment_reg, seed_path, mod_id, vend_id, entropyId, oe_id, certify, single_mod)
ea.login()
ea.send_reg()
responseCount=0
Expand All @@ -117,7 +117,7 @@ def prev_run(server_url, ea_id, df_ids, jwt_token, client_cert):
ThreadWrapper.runner_stats(server_url, response, client_cert)
responseCount = responseCount + 1

certSup = ThreadWrapper.runner_supp(comments, sdType, supporting_paths, ea.itar, server_url, client_cert, ea.auth_header)
certSup = ThreadWrapper.runner_supp(comments, sdType, supporting_paths, server_url, client_cert, ea.auth_header)
#i = 0
#for response in ea.responses:
client_cert, seed_path, server_url, esv_version = parse_config(config_path)
Expand All @@ -130,7 +130,7 @@ def prev_run(server_url, ea_id, df_ids, jwt_token, client_cert):

#log_file = json.load(open('jsons\\log.json', 'r'))[0]
client_cert, seed_path, server_url, esv_version = parse_config(config_path)
assessment_reg, raw_noise, restart_test, conditioned, supporting_paths, comments, sdType, mod_id, vend_id, entropyId, oe_id, certify, single_mod, responses, itar = parse_run(run_path)
assessment_reg, raw_noise, restart_test, conditioned, supporting_paths, comments, sdType, mod_id, vend_id, entropyId, oe_id, certify, single_mod, responses = parse_run(run_path)

#print("Logging in...")

Expand Down Expand Up @@ -160,7 +160,7 @@ def prev_run(server_url, ea_id, df_ids, jwt_token, client_cert):
if run_type == "submit":
clear_previous_run()
#ea = EntropyAssessment(client_cert, server_url, assessment_reg, seed_path, mod_id, vend_id, oe_id, certify, single_mod)
ea = EntropyAssessment(client_cert, server_url, assessment_reg, seed_path, mod_id, vend_id, entropyId, oe_id, certify, single_mod, itar)
ea = EntropyAssessment(client_cert, server_url, assessment_reg, seed_path, mod_id, vend_id, entropyId, oe_id, certify, single_mod)
ea.login()
ea.send_reg()
responseCount=0
Expand All @@ -171,9 +171,9 @@ def prev_run(server_url, ea_id, df_ids, jwt_token, client_cert):
#Send Supporting Documentation
if run_type == "support":
#ea = EntropyAssessment(client_cert, server_url, assessment_reg, seed_path, mod_id, vend_id, oe_id, certify, single_mod)
ea = EntropyAssessment(client_cert, server_url, assessment_reg, seed_path, mod_id, vend_id, entropyId, oe_id, certify, single_mod, itar)
ea = EntropyAssessment(client_cert, server_url, assessment_reg, seed_path, mod_id, vend_id, entropyId, oe_id, certify, single_mod)
ea.login()
certSup = ThreadWrapper.runner_supp(comments, sdType, supporting_paths, ea.itar, server_url, client_cert, ea.auth_header)
certSup = ThreadWrapper.runner_supp(comments, sdType, supporting_paths, server_url, client_cert, ea.auth_header)
if(globalenv.verboseMode):
print(certSup)

Expand All @@ -182,16 +182,16 @@ def prev_run(server_url, ea_id, df_ids, jwt_token, client_cert):
print("Using values from previous run..\n")
#log_file = json.load(open('jsons/log.json', 'r'))[0]
client_cert, seed_path, server_url, esv_version = parse_config(config_path)
assessment_reg, raw_noise, restart_test, conditioned, supporting_paths, comments, sdType, mod_id, vend_id, entropyId, oe_id, certify, single_mod, responses, itar = parse_run(run_path)
assessment_reg, raw_noise, restart_test, conditioned, supporting_paths, comments, sdType, mod_id, vend_id, entropyId, oe_id, certify, single_mod, responses = parse_run(run_path)
#ea = EntropyAssessment(client_cert, server_url, assessment_reg, seed_path, mod_id, vend_id, oe_id, certify, single_mod)
#i = 0
#for response in responses:
ea = EntropyAssessment(client_cert, server_url, assessment_reg, seed_path, mod_id, vend_id, entropyId, oe_id, certify, single_mod, itar)
ea = EntropyAssessment(client_cert, server_url, assessment_reg, seed_path, mod_id, vend_id, entropyId, oe_id, certify, single_mod)
ea.responses = responses
ea.login()
#ea.ea_id = response.ea_id; ea.entr_jwt, _ = eajwt_refresh(response.entr_jwt) #Uses old ID, refreshes eajwt
#ea.entr_jwt, _ = eajwt_refresh(response.entr_jwt)
certSup = ThreadWrapper.runner_supp(comments, sdType, supporting_paths, ea.itar, server_url, client_cert, ea.auth_header)
certSup = ThreadWrapper.runner_supp(comments, sdType, supporting_paths, server_url, client_cert, ea.auth_header)
ea.send_certify(certSup, client_cert, ea.login_jwt, esv_version)
#i += 1
#ea.send_certify(certSup, client_cert, ea.login_jwt, esv_version)
Expand Down
13 changes: 7 additions & 6 deletions client/entropy_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class EntropyAssessment():

def __init__(self, client_cert, server_url, assessment_reg, seed_path, mod_id, vend_id, entropy_id, oe_id, certify, single_mod, itar): #, rawNoise, restartTest, conditioned, supporting_paths, comments):
def __init__(self, client_cert, server_url, assessment_reg, seed_path, mod_id, vend_id, entropy_id, oe_id, certify, single_mod): #, rawNoise, restartTest, conditioned, supporting_paths, comments):
self.client_cert = client_cert
self.server_url = server_url
self.assessment_reg = assessment_reg
Expand All @@ -22,8 +22,7 @@ def __init__(self, client_cert, server_url, assessment_reg, seed_path, mod_id, v
self.seed_path = seed_path
self.certify = certify
# Changed 9/14/2022 because itar is now set in certify not registration
#self.itar = assessment_reg[1]['itar']
self.itar = itar
#self.itar = assessment_reg[1]['itar']
self.auth_header = ''
self.cert_supp = ''

Expand Down Expand Up @@ -110,22 +109,24 @@ def send_certify(self, cert_supp, client_cert, login_jwt, esv_version):
for response in self.responses:
ea_ids.append(response.ea_id)
entr_jwts.append(response.entr_jwt)
cert_json = cert_prep(cert_file, cert_supp, esv_version, self.single_mod, self.mod_id, self.vend_id, self.entropy_id, ea_ids, self.oe_id, entr_jwts, self.itar)
cert_json = cert_prep(cert_file, cert_supp, esv_version, self.single_mod, self.mod_id, self.vend_id, self.entropy_id, ea_ids, self.oe_id, entr_jwts)
if globalenv.verboseMode:
print("Outgoing cert request = ")
print(cert_json)
responseFromCert = requests.request("POST", self.server_url + '/certify', cert = client_cert, headers=auth_header, json=cert_json)
check_status(responseFromCert)
status, messageList, elementList = start.parsing.parse_certify_response(responseFromCert)

if globalenv.verboseMode:
print("Response coming back = ")
print(responseFromCert)
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"]))
print("Location:" + str(element["reference"]))
for message in element["messageList"]:
print(" Message:" + message)
#i+=1
Expand Down
16 changes: 13 additions & 3 deletions client/start/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import utilities.esvutil as esvutil
import certifi
import globalenv
import utilities.utils as utils

#Parse the config file into usable variables
def parse_config(config_path):
Expand Down Expand Up @@ -65,6 +66,16 @@ def parse_run(run_path):
restartTest.append(dataFile["restartTestPath"])
conditioned.append(dataFile["unvettedConditionedPaths"])

for filepath in rawNoise:
utils.checkDataFileSize(filepath)

for filepath in restartTest:
utils.checkDataFileSize(filepath)

for conditionedFiles in conditioned:
for filepath in conditionedFiles:
utils.checkDataFileSize(filepath)

numberOfOEs = assessment_reg[1]['numberOfOEs']
if len(oeId) != numberOfOEs:
print("Error: Number of oeIDs provided must match numberOfOEs in Assessment Registration. numberOfOEs is ", numberOfOEs, " but provided number of oeIDs is ", len(oeId))
Expand All @@ -81,15 +92,14 @@ def parse_run(run_path):

run_checks(comments, sdType, supporting_paths)
singleMod = run_file[0]["Assessment"]['limitEntropyAssessmentToSingleModule']
entropyId = None; modId = None; vendId = None; itar = None
entropyId = None; modId = None; vendId = None

certify = run_file[0]["Certify"]['Certify']
if certify: #Certification requires module and vendor IDs
try:
entropyId = run_file[0]["Certify"]['entropyID']
modId = run_file[0]["Certify"]['moduleID']
vendId = run_file[0]["Certify"]['vendorID']
itar = run_file[0]["Certify"]['itar']

except:
print("Error: Entropy, Module and Vendor IDs are required for certification")
Expand Down Expand Up @@ -134,7 +144,7 @@ def parse_run(run_path):

if(globalenv.verboseMode):
print('Run file successfully parsed')
return assessment_reg, rawNoise, restartTest, conditioned, supporting_paths, comments, sdType, modId, vendId, entropyId, oeId, certify, singleMod, responseList, itar
return assessment_reg, rawNoise, restartTest, conditioned, supporting_paths, comments, sdType, modId, vendId, entropyId, oeId, certify, singleMod, responseList

except Exception as e:
print("There was an error parsing your run file. Please try again")
Expand Down
24 changes: 11 additions & 13 deletions client/threads/thread_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,19 @@ def df_upload_restart(server_url, ea_id, df_ids, jwt, restart_test, client_cert)
return response

#Step 5(2): Send Supporting Documents
def send_supp(comments, sdType, supporting_path, itar, server_url, client_cert, auth_header):
def send_supp(comments, sdType, supporting_path, 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}
# added type 6/23/2022
payload={'isITAR': itar, 'sdType': sdType,'sdComments': comments}
files=[('sdFile', (supp_name, open(supporting_path,'rb'),'application/pdf'))]
payload={'sdType': sdType,'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)
response_1 = response.json()[1]
status = response_1['status']
if(status != "success"):
print (status)
else:
sd_id = response_1['sdId']
print(supp_name + ": " + str(sd_id) + " | Status: " + str(response_1['status']))
cert_supp.append({"sdId" : sd_id, "accessToken": response_1["accessToken"]})
return cert_supp, response
4 changes: 2 additions & 2 deletions client/threads/thread_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def runner_data(server_url, responses, conditioned, rawNoise, restartTest, clien
print("Data files submitted!\n")

#Step 5: Runner for threading supporting docs uploads
def runner_supp(comments, sdType, supporting_paths, itar, server_url, client_cert, auth_header):
def runner_supp(comments, sdType, supporting_paths, server_url, client_cert, auth_header):
threads= []
cert_supp = []
with ThreadPoolExecutor(max_workers=20) as executor:
Expand All @@ -56,7 +56,7 @@ def runner_supp(comments, sdType, supporting_paths, itar, server_url, client_cer
print("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], sdType[i], supporting_paths[i], itar, server_url, client_cert, auth_header))
threads.append(executor.submit(send_supp, comments[i], sdType[i], supporting_paths[i], server_url, client_cert, auth_header))

for task in as_completed(threads):
#Check status code of responses and create cert_sup for certify
Expand Down
19 changes: 17 additions & 2 deletions client/utilities/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

VALID_SD_TYPES = ["EntropyAssessmentReport","PublicUseDocument","Other"]

# Because there's sometimes misunderstandings of the definition of "megabyte" (1 million vs 2^20)
# we'll error on the side of allowing a lower min and a larger max
FILE_SIZE_MIN = 1000 * 1000 * 1
FILE_SIZE_MAX = 1024 * 1024 * 2

#Generates payload for JWT refresh
def ref_payload(passw, jwt):

Expand Down Expand Up @@ -77,7 +82,7 @@ def get_ids(response):
dfIDs.append(urls[0])
return eaID, dfIDs

def cert_prep(certify, certSup, esv_version, singleMod, modId, vendId, entropyId, eaIDs, oeIds, entrjwts, itar): # *Also uses other variables defined in main
def cert_prep(certify, certSup, esv_version, singleMod, modId, vendId, entropyId, eaIDs, oeIds, entrjwts): # *Also uses other variables defined in main

certify[0]["esvVersion"] = esv_version
certEntropy = certify[1]["entropyAssessments"] = []
Expand All @@ -87,7 +92,6 @@ def cert_prep(certify, certSup, esv_version, singleMod, modId, vendId, entropyId
#certEntropy["oeId"] = oeIds[x]
#certEntropy["eaId"] = int(eaIDs[x])
certEntropy.append({"eaId":int(eaIDs[x]), "oeId":oeIds[x], "accessToken":entrjwts[x]})
certify[1]["itar"] = itar #assessment_reg[1]["itar"]
certify[1]["limitEntropyAssessmentToSingleModule"] = singleMod
certify[1]["moduleId"] = modId
certify[1]["vendorId"] = vendId
Expand Down Expand Up @@ -221,3 +225,14 @@ def create_log_file():
f = open('jsons/log.json',"w")
f.write("[{\"entr_jwt\": \"placeholder\",\"df_ids\": [\"1\",\"2\"],\"ea_id\": \"1\",\"server_url\": \"https://demo.esvts.nist.gov:7443/esv/v1\",\"client_cert\": [\"ESVTest.cer\",\"ESVTest.key\"],\"config_path\": \"config.json\",\"run_path\": \"run.json\",\"cert_supp\": [[{\"sdId\": 1,\"accessToken\": \"placeholder\"}]]}]")
f.close()

def checkDataFileSize(filepath):
#file = open(filepath, "r")
filesize = os.path.getsize(filepath)
if filesize < FILE_SIZE_MIN:
print("Error: '" + filepath + "' is too small (" + str(filesize) + " bytes). Minimum is " + str(FILE_SIZE_MIN) + ".")
sys.exit(1)
if filesize > FILE_SIZE_MAX:
print("Error: '" + filepath + "' is too large (" + str(filesize) + " bytes). Maximum is " + str(FILE_SIZE_MAX) + ".")
sys.exit(1)
#file.close()

0 comments on commit 2b38f4d

Please sign in to comment.