2424from cryptography .hazmat .primitives import hashes , serialization
2525from cryptography .hazmat .primitives .asymmetric import padding , ec
2626init (autoreset = True )
27- current_version = "v1.3 "
27+ current_version = "v1.4 "
2828
2929# ==== This code is to check update
3030
@@ -291,6 +291,9 @@ async def keybox_check_cli(keybox_path):
291291 google_status = (f"{ status ['reason' ]} " )
292292
293293 overrall_status = get_overrall_status (status , keychain_status , cert_status , google_status )
294+ oid_values = {}
295+ for rdn in subject :
296+ oid_values [rdn .oid ._name ] = rdn .value
294297
295298 keybox_parsed = (f"{ certificate .subject } " )
296299 keybox_string = re .search (r"2\.5\.4\.5=([0-9a-fA-F]+)" , keybox_parsed )
@@ -300,11 +303,19 @@ async def keybox_check_cli(keybox_path):
300303 else :
301304 print (f"Keybox SN : { Fore .YELLOW } Software or Invalid" )
302305 print (f"Cert SN : { Fore .BLUE } { serial_number_string } " )
306+ keybox_title = oid_values .get ('title' , 'N/A' )
307+ if keybox_title != 'TEE' :
308+ print (f"Keybox Title : { Fore .BLUE } { keybox_title } " )
309+ if 'organizationName' in oid_values :
310+ print (f"Keybox Organization: { Fore .BLUE } { oid_values ['organizationName' ]} " )
311+ if 'commonName' in oid_values :
312+ print (f"Keybox Name: { Fore .BLUE } { oid_values ['commonName' ]} " )
303313 print (f"Status : { overrall_status } " )
304314 print (f"Keychain : { keychain_status } " )
305315 print (f"Validity: { validity_status } " )
306316 print (f"Root Cert : { cert_status } " )
307317 print (f"Check Time : { Fore .BLUE } { datetime .now ().strftime ('%Y-%m-%d %H:%M:%S' )} " )
318+ return overrall_status
308319
309320 # Im dying here
310321def get_overrall_status (status , keychain_status , cert_status , google_status ):
@@ -353,25 +364,45 @@ def get_overrall_status(status, keychain_status, cert_status, google_status):
353364 metavar = "FOLDER_PATH" ,
354365 help = "Check keybox.xml files in bulk."
355366 )
367+ parser .add_argument (
368+ "-v" , "--version" ,
369+ action = 'version' ,
370+ version = f'KeyboxChecker Version : { current_version } '
371+ )
356372
357373 args = parser .parse_args ()
358374
359375 if args .bulk :
360376 folder_path = args .bulk
377+ keybox_statuses = {}
378+ total_valid_keybox = 0
379+ total_software_keybox = 0
380+ total_invalid_keybox = 0
381+
382+ print ("Checking keyboxs folder..." )
361383 for filename in os .listdir (folder_path ):
362384 if filename .endswith (".xml" ):
363385 file_path = os .path .join (folder_path , filename )
364- print ("=====================================" )
365- print (f"Processing: { file_path } " )
366- asyncio .run (keybox_check_cli (file_path ))
386+ overrall_status = asyncio .run (keybox_check_cli (file_path ))
387+ keybox_statuses [file_path ] = overrall_status
388+ os .system ('cls' if os .name == 'nt' else 'clear' )
389+
390+ if overrall_status == f"{ Fore .GREEN } Valid. (Google Hardware Attestation)" :
391+ total_valid_keybox += 1
392+ elif overrall_status == f"{ Fore .YELLOW } Valid. (Software signed)" :
393+ total_software_keybox += 1
394+ elif overrall_status in [f"{ Fore .RED } Invalid Keybox." , f"{ Fore .RED } Invalid. (Key Compromised)" , f"{ Fore .RED } Invalid. (Software flaw)" , f"{ Fore .RED } Invalid. (CA Compromised)" , f"{ Fore .RED } Invalid. (Suspended)" ]:
395+ total_invalid_keybox += 1
367396
368- elif args .keybox_path : # If --bulk is not used, check single file
397+ for keybox , overrall_status in keybox_statuses .items ():
398+ print (f"{ keybox } : { overrall_status } " )
399+
400+ print (f"\n Valid Keyboxs : { total_valid_keybox } " )
401+ print (f"Software Keyboxs : { total_software_keybox } " )
402+ print (f"Invalid Keyboxs : { total_invalid_keybox } " )
403+
404+ elif args .keybox_path : # If --bulk is not used, check single file
369405 asyncio .run (keybox_check_cli (args .keybox_path ))
370406 else :
371- print ("Error: Please provide a folder full of keybox.xml files or a single keybox.xml file." )
372- sys .exit (1 )
373-
374-
375- if not args .keybox_path :
376- print ("Error: Please provide the path to the keybox file." )
377- sys .exit (1 )
407+ print ("Error: Please provide a folder full of keybox.xml files or the path to the keybox file." ) # Modified error message
408+ sys .exit (1 )
0 commit comments