88import requests
99import settings
1010import sys
11+ import time
1112import traceback
1213import urllib .parse
1314import csv
@@ -104,7 +105,7 @@ def main(argv):
104105 except :
105106 problemfiles [filepath ] = "" + str (sys .exc_info ()[0 ]) + " -- " + str (sys .exc_info ()[1 ]) + " -- "
106107 CVECount += 1
107- if CVECount % 250 == 0 : spinner .next ()
108+ if CVECount % 100 == 0 : spinner .next ()
108109
109110 print ('FINISHED processed directory' , inputdir )
110111 print ('' )
@@ -343,7 +344,8 @@ def CVE_Convert(inputfile, outputpath):
343344 global keys_used
344345 global extra_keys
345346 global states_processed
346- global all_users
347+ # global all_users
348+ global all_orgs
347349 global scoring_other
348350 global invalid_impact_versions
349351 global requester_map
@@ -357,13 +359,15 @@ def CVE_Convert(inputfile, outputpath):
357359 if len (requester_map ) < 1 :
358360 getRequesterMap ()
359361
362+ ''' Not needed if querying IDR by CVE ID
360363 if len(all_users) < 1:
361364 getAllUsers()
362365 # get min and max length of org shortname
363366 for org in all_orgs:
364367 minShortName = min(minShortName, len(all_orgs[org]["short_name"]))
365368 maxShortName = max(maxShortName, len(all_orgs[org]["short_name"]))
366-
369+ '''
370+
367371 with open (inputfile ) as json_file :
368372 writeout = False
369373 data = json .load (json_file )
@@ -384,6 +388,7 @@ def CVE_Convert(inputfile, outputpath):
384388 if i_meta ["STATE" ] not in keys_used : keys_used [i_meta ["STATE" ]] = {}
385389 keys_used [i_meta ["STATE" ]]["CVE_data_meta" ] = {}
386390
391+ '''
387392 if "ASSIGNER" in i_meta:
388393 # v4 assigner email converted to orgId before v5 upconvert
389394 # get org info
@@ -461,8 +466,9 @@ def CVE_Convert(inputfile, outputpath):
461466 else:
462467 o_meta["assignerOrgId"] = all_users[username]["org_UUID"]
463468 o_meta["assignerShortName"] = all_users[username]["org_short_name"]
464-
469+
465470 # print("in = " + i_meta["ASSIGNER"] + " out = " +o_meta["assignerShortName"])
471+ '''
466472
467473 if "STATE" in i_meta :
468474 if i_meta ["STATE" ] == 'RESERVED' :
@@ -478,6 +484,19 @@ def CVE_Convert(inputfile, outputpath):
478484 if "ID" in i_meta :
479485 o_meta ["cveId" ] = i_meta ["ID" ]
480486
487+ o_meta ["assignerOrgId" ] = "Not found"
488+ o_meta ["assignerShortName" ] = "Not found"
489+ if i_meta ["STATE" ] != 'RESERVED' :
490+ recData = getIDRInfo ( o_meta ["cveId" ] )
491+ if recData and "owning_cna" in recData :
492+ org_short_name = recData ["owning_cna" ]
493+ org_uuid = getOrgUUID (org_short_name )
494+ o_meta ["assignerOrgId" ] = org_uuid
495+ o_meta ["assignerShortName" ] = org_short_name
496+ else :
497+ print ("Record with data issue: " + o_meta ["cveId" ])
498+ raise Exception ("ERROR - no CNA for record ID - " + o_meta ["cveId" ])
499+
481500 if "DATE_PUBLIC" in i_meta and i_meta ["DATE_PUBLIC" ] != "" :
482501 o_meta ["datePublished" ] = i_meta ["DATE_PUBLIC" ]
483502 try :
@@ -514,6 +533,7 @@ def CVE_Convert(inputfile, outputpath):
514533 else :
515534 raise MissingRequiredPropertyValue (inputfile , "CVE_data_meta no STATE" )
516535 except Exception as e :
536+ # print("test 5")
517537 print ( str (e ) )
518538 if type (e ) is not MissingRequiredPropertyValue :
519539 raise MissingRequiredPropertyValue (inputfile , "CVE_data_meta structure error" )
@@ -1404,6 +1424,26 @@ def __init__(self, cveid, propertyname, message="Required property missing from
14041424 def __str__ (self ):
14051425 return self .cveid + " - " + self .propertyname + " - " + self .message
14061426
1427+
1428+ def getOrgUUID ( short_name ):
1429+ global all_orgs
1430+
1431+ if not all_orgs or len (all_orgs ) < 1 : getOrgData ()
1432+
1433+ # try/except block to catch integrity error in case the org doesn't exist
1434+ uuid = None
1435+ try :
1436+ for org in all_orgs :
1437+ # print( json.dumps(all_orgs, indent=2))
1438+ orgShortName = all_orgs [org ]["short_name" ]
1439+ if orgShortName == short_name :
1440+ uuid = all_orgs [org ]["UUID" ]
1441+ break
1442+ except :
1443+ pass
1444+ return uuid
1445+
1446+
14071447def getAllUsers ():
14081448 global all_orgs
14091449 global all_users
@@ -1447,27 +1487,61 @@ def getAllUsers():
14471487
14481488
14491489
1450- def getIDRInfo (cveId ):
1451- IDR_URL = settings .AWG_IDR_SERVICE_URL + '/cve/' + cveId
1490+ def getIDRInfo (cveId , delay = 20 , retry = 0 ):
1491+ IDR_URL = settings .AWG_IDR_SERVICE_URL + '/cve-id /' + cveId
14521492 idr_params = {}
14531493 data = None
1494+
14541495 # try/except block to catch integrity error in case the org doesn't exist
14551496 try :
14561497 # Attempt to get org from RSUS
14571498 idr_result = call_idr_service ('get' , BASE_HEADERS , IDR_URL , idr_params )
1458- data = json .loads (idr_result )
1459- print ( json .dumps (data , indent = 4 ) )
1499+ if idr_result and idr_result .startswith ("{" ):
1500+ data = json .loads (idr_result )
1501+ else :
1502+ if retry < 10 :
1503+ # print("delay for: "+ str(delay))
1504+ time .sleep (delay )
1505+ data = getIDRInfo (cveId , delay * 2 , retry + 1 )
1506+ else :
1507+ print ("Record Issue - URL - " + IDR_URL )
1508+ # print(str(idr_result))
1509+ except Exception as e :
1510+ if retry < 10 :
1511+ if delay > 179 :
1512+ print ("exception delay for: " + str (delay ))
1513+ time .sleep (delay )
1514+ data = getIDRInfo (cveId , delay * 2 , retry + 1 )
1515+ else :
1516+ # print(str(idr_result))
1517+ print ("Exception -- URL - " + IDR_URL )
1518+ print (str (e ))
1519+ raise e
1520+ return data
1521+
1522+
1523+ def getRecordMetaData (recordId ):
1524+ ORG_URL = settings .AWG_IDR_SERVICE_URL + '/cve-id/' + str (recordId )
1525+ org_params = {}
1526+
1527+ # try/except block to catch integrity error in case the ID doesn't exist
1528+ try :
1529+ # Attempt to get org from RSUS
1530+ record_result = call_idr_service ('get' , BASE_HEADERS , ORG_URL , org_params )
1531+ data = json .loads (record_result )
1532+ if "owning_cna" in data :
1533+ return data
1534+ else :
1535+ raise Exception (str (recordId ) + " did not find an owning_cna." )
14601536 except Exception as e :
14611537 print (str (e ))
14621538 raise e
1463- return data
1464-
1539+ return None
14651540
14661541
14671542def getOrgData ():
14681543 global all_orgs
14691544
1470- # ORG_URL = settings.AWG_IDR_SERVICE_URL + '/org/' + orgId
14711545 ORG_URL = settings .AWG_IDR_SERVICE_URL + '/org'
14721546 org_params = {}
14731547
0 commit comments