Skip to content

Instantly share code, notes, and snippets.

@khang06
Last active January 26, 2019 21:53
Show Gist options
  • Save khang06/7c56149dfaf663643ef9f653a2d8457b to your computer and use it in GitHub Desktop.
Save khang06/7c56149dfaf663643ef9f653a2d8457b to your computer and use it in GitHub Desktop.
hactool key verifier
'''
hactool key verifier v0.2 by Khangaroo
a very badly made script to verify your hactool keys
Hash sources:
https://gist.github.com/roblabla/d8358ab058bbe3b00614740dcba4f208
My own console
https://github.com/SocraticBliss/hactool/blob/4169184c88a10cde0db8eaa83d38bd32a7f35751/KEYS.md
Some places that I can't link
'''
import sys
from configparser import ConfigParser
from binascii import unhexlify, hexlify
import hashlib
key_lookup = {
'aes_kek_generation_source': 'FC02B9D37B42D7A1452E71444F1F700311D1132E301A83B16062E72A78175085',
'aes_key_generation_source': 'FBD10056999EDC7ACDB96098E47E2C3606230270D23281E671F0F389FC5BC585',
'header_kek_source': '1888CAED5551B3EDE01499E87CE0D86827F80820EFB275921055AA4E2ABDFFC2',
'header_key': '8E03DE24818D96CE4F2A09B43AF979E679974F7570713A61EED8B314864A11D5',
'header_key_source': '8F783E46852DF6BE0BA4E19273C4ADBAEE16380043E1B8C418C4089A8BD64AA6',
'keyblob_00': '820C0DA78FC41341E8CA3A7DEAA89E57136AE53FBECEA5BC86D79F98926D83E5',
'keyblob_01': '191E2D2097F39B0904F1C981C59D66E32C83C6F3338EE573EB268DC14D1813D5',
'keyblob_02': '5842E09C38F602A3A96E4752B26BB9A315501F5EA382F85391D8DA01A92AB7BC',
'keyblob_03': '0179DFBF83428C638B7A3A0016A4091150FD43DBA8EAE7FCA87500B3C6C2651A',
'keyblob_04': 'EAD90954126B68B0C7F44981AA35F8EABD6FE8E8C5E570C8D9E29260D7154873',
'keyblob_key_source_00': '8A06FE274AC491436791FDB388BCDD3AB9943BD4DEF8094418CDAC150FD73786',
'keyblob_key_source_01': '2D5CAEB2521FEF70B47E17D6D0F11F8CE2C1E442A979AD8035832C4E9FBCCC4B',
'keyblob_key_source_02': '61C5005E713BAE780641683AF43E5F5C0E03671117F702F401282847D2FC6064',
'keyblob_key_source_03': '8E9795928E1C4428E1B78F0BE724D7294D6934689C11B190943923B9D5B85903',
'keyblob_key_source_04': '95FA33AF95AFF9D9B61D164655B32710ED8D615D46C7D6CC3CC70481B686B402',
'keyblob_mac_key_source': 'B24BD293259DBC7AC5D63F88E60C59792498E6FC5443402C7FFE87EE8B61A3F0',
'key_area_key_application_00': '592957F44FE5DB5EC6B095F568910E31A226D3B7FE42D64CFB9CE4051E90AEB6',
'key_area_key_application_01': 'C2252A0FBF9D339ABC3D681351D00452F926E7CA0C6CA85F659078DE3FA647F3',
'key_area_key_application_02': '7C7722824B2F7C4938C40F3EA93E16CB69D3285EB133490EF8ECCD2C4B52DF41',
'key_area_key_application_03': 'AFBB8EBFB2094F1CF71E330826AE06D64414FCA128C464618DF30EED92E62BE6',
'key_area_key_application_04': '5DC10EB81918DA3F2FA90F69C8542511963656CFB31FB7C779581DF8FAF1F2F5',
'key_area_key_application_source': '04AD66143C726B2A139FB6B21128B46F56C553B2B3887110304298D8D0092D9E',
'key_area_key_ocean_00': 'AA2C65F0E27F730807A13F2ED5B99BE5183165B87C50B6ED48F5CAC2840687EB',
'key_area_key_ocean_01': '860185F2313A14F7006A029CB21A52750E7718C1E94FFB98C0AE2207D1A60165',
'key_area_key_ocean_02': '7283FB1EFBD42438DADF363FDB776ED355C98737A2AAE75D0E9283CE1C12A2E4',
'key_area_key_ocean_03': '9881C2D3AB70B14C8AA12016FC73ADAD93C6AD9FB59A9ECAD312B6F89E2413EC',
'key_area_key_ocean_04': 'EAA6A8D242B89E174928FA9549A0F66EC1562E2576FAC896F438A2B3C1FB6005',
'key_area_key_ocean_source': 'FD434000C8FF2B26F8E9A9D2D2C12F6BE5773CBB9DC86300E1BD99F8EA33A417',
'key_area_key_system_00': '194CF6BD14554DA8D457E14CBFE04E55C8FB8CA52E0AFB3D7CB7084AE435B801',
'key_area_key_system_01': 'CE1DB7BB6E5962384889DB7A396AFD614F82F69DC38A33D2DEAF47F3E4B964B7',
'key_area_key_system_02': '42238DE5685DEF4FDE7BE42C0097CEB92447006386D6B5D5AAA2C9AFD2E28422',
'key_area_key_system_03': '1F6847F268E9D9C5D1AD4D7E226A63B833BF02071446957A962EF065521879C1',
'key_area_key_system_04': '644007F9913C3602399D4D75CC34FAEB7F1FAAD18B23E34187B16FDC45F4980F',
'key_area_key_system_source': '1F17B1FD51AD1C2379B58F152CA4912EC2106441E51722F38700D5937A1162F7',
'master_key_00': '0EE359BE3C864BB0782E1D70A718A0342C551EED28C369754F9C4F691BECF7CA',
'master_key_01': '4FE707B7E4ABDAF727C894AAF13B1351BFE2AC90D875F73B2E20FA94B9CC661E',
'master_key_02': '79277C0237A2252EC3DFAC1F7C359C2B3D121E9DB15BB9AB4C2B4408D2F3AE09',
'master_key_03': '4F36C565D13325F65EE134073C6A578FFCB0008E02D69400836844EAB7432754',
'master_key_04': '75FF1D95D26113550EE6FCC20ACB58E97EDEB3A2FF52543ED5AEC63BDCC3DA50',
'master_key_source': '7944862A3A5C31C6720595EFD302245ABD1B54CCDCF33000557681E65C5664A4',
'package1_key_00': '4543CD1B7CAD7EE0466A3DE2086A0EF923805DCEA6C741541CDDB14F54F97B40',
'package1_key_01': '984F1916834540FF3037D65133F374BD9E715DC3B162AAC77C8387F9B22CF909',
'package1_key_02': '9E7510E4141AD89D0FB697E817326D3C80F96156DCE7B6903049AC033E95F612',
'package1_key_03': 'E65C383CDF526DFFAA77682868EBFA9535EE60D8075C961BBC1EDE5FBF7E3C5F',
'package1_key_04': '28AE73D6AE8F7206FCA549E27097714E599DF1208E57099416FF429B71370162',
'package2_key_00': '94D6F38B9D0456644E21DFF4707D092B70179B82D1AA2F5B6A76B8F9ED948264',
'package2_key_01': '7794F24FA879D378FEFDC8776B949B88AD89386410BE9025D463C619F1530509',
'package2_key_02': '5304BDDE6AC8E462961B5DB6E328B1816D245D36D6574BB78938B74D4418AF35',
'package2_key_03': 'BE1E52C4345A979DDD4924375B91C902052C2E1CF8FBF2FAA42E8F26D5125B60',
'package2_key_04': '631B45D349AB8F76A050FE59512966FB8DBAF0755EF5B6903048BF036CFA611E',
'package2_key_source': '21E2DF100FC9E094DB51B47B9B1D6E94ED379DB8B547955BEF8FE08D8DD35603',
'sd_card_kek_source': '6B2ED877C2C52334AC51E59ABFA7EC457F4A7D01E46291E9F2EAA45F011D24B7',
'sd_card_save_key_source': 'D482743563D3EA5DCDC3B74E97C9AC8A342164FA041A1DC80F17F6D31E4BC01C',
'sd_card_nca_key_source': '2E751CECF7D93A2B957BD5FFCB082FD038CC2853219DD3092C6DAB9838F5A7CC',
'titlekek_00': 'C2FA30CAC6AE1680466CB54750C24550E8652B3B6F38C30B49DADF067B5935E9',
'titlekek_01': '0D6B8F3746AD910D36438A859C11E8BE4310112425D63751D09B5043B87DE598',
'titlekek_02': 'D09E18D3DB6BC7393536896F728528736FBEFCDD15C09D9D612FDE5C7BDCD821',
'titlekek_03': '47C6F9F7E99BB1F56DCDC93CDBD340EA82DCCD74DD8F3535ADA20ECF79D438ED',
'titlekek_04': '128610DE8424CB29E08F9EE9A81C9E6FFD3C6662854AAD0C8F937E0BCEDC4D88',
'titlekek_source': 'C48B619827986C7F4E3081D59DB2B460C84312650E9A8E6B458E53E8CBCA4E87'
}
def verify_keyfile(path):
with open(path, 'r') as f:
config_string = '[DEFAULT]\n' + f.read() # from https://stackoverflow.com/questions/2819696/parsing-properties-file-in-python/25493615#25493615
ini = ConfigParser()
ini.read_string(config_string)
for key, value in key_lookup.items():
try:
inikeyhash = hashlib.sha256(unhexlify(ini['DEFAULT'][key])).hexdigest().upper()
if value == inikeyhash
print('\033[1;32m', key, 'OK')
else:
print('\033[1;31m', key, 'invalid\n', 'Expected:', value, '\n', 'Got:', inikeyhash)
except KeyError:
print('\033[1;33m', key, 'skipped')
def main(argc, argv):
if argc != 2:
print('Usage: %s path/to/prod.keys' % argv[0])
return 1
verify_keyfile(argv[1])
if __name__=='__main__':
sys.exit(main(len(sys.argv), sys.argv))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment