Skip to content

Commit

Permalink
improve ticket verify
Browse files Browse the repository at this point in the history
  • Loading branch information
seiya-git committed Nov 1, 2023
1 parent a2364f1 commit f6072a8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
1 change: 1 addition & 0 deletions py/Fs/Nca.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def __getitem__(self, key):
return self.sectionFilesystems[key]

def open(self, file = None, mode = 'rb', cryptoType = -1, cryptoKey = -1, cryptoCounter = -1):

super(Nca, self).open(file, mode, cryptoType, cryptoKey, cryptoCounter)
self.header = NcaHeader()
self.partition(0x0, 0xC00, self.header, Fs.Type.Crypto.XTS, uhx(Keys.get('header_key')))
Expand Down
37 changes: 26 additions & 11 deletions py/lib/Verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,21 +236,32 @@ def verify_decrypt(nspx, vmsg = None):
tik_file = file
check_tik = False

tik_data = Fs.Ticket.Ticket()
print(tik_data.__dict__)
for f in temp_hfs:
if f._path.endswith('.nca'):
if check_tik == False and f.header.getRightsId() != 0:
check_tik = VerifyTools.verify_key(temp_hfs, f._path, tik_file)
if check_tik == True:
break
if f._path.endswith('.ncz'):
tncz = FsTools.get_ncz_data(f)
if check_tik == False and tncz.header.getRightsId() != 0:
check_tik = 'ncz'
break
if f._path.endswith('.tik') and f._path == tik_file:
tik_data = f
break

if len(titlerights) < 1:
if len(titlerights) < 1 or tik_data.rightsId == 0 or tik_data.rightsId == None:
check_tik = 'unused'

if check_tik == False:
for f in temp_hfs:
if f._path.endswith('.nca'):
if f.header.getRightsId() == tik_data.rightsId and f.header.keyStatus == False:
check_tik = 'nca'
break
if f.header.getRightsId() == tik_data.rightsId:
check_tik = VerifyTools.verify_key(temp_hfs, f._path, tik_file)
if check_tik == True:
break
if f._path.endswith('.ncz'):
tncz = FsTools.get_ncz_data(f)
if tncz.header.getRightsId() == tik_data.rightsId:
check_tik = 'ncz'
break

cert_file = f'{tik_file[:-3]}cert'
if not cert_file in listed_certs:
cert_message += f'\n:{cert_file[:16].upper()} - Content.CERTIFICATE'
Expand Down Expand Up @@ -288,6 +299,10 @@ def verify_decrypt(nspx, vmsg = None):
tvmsg = f'> {file}\t\t -> ncz file needs HASH check'
print(tvmsg)
vmsg.append(tvmsg)
elif file.endswith('.tik') and correct == 'nca':
tvmsg = f'> {file}\t\t -> is EXISTS'
print(tvmsg)
vmsg.append(tvmsg)
elif file.endswith('.tik') and correct == 'ncz':
tvmsg = f'> {file}\t\t -> is EXISTS'
print(tvmsg)
Expand Down
6 changes: 3 additions & 3 deletions py/nut/Keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ def load(fileName):
errorMsg = ""
for kf in keyfiles:
if errorMsg != "":
errorMsg += "or "
errorMsg += f"{str(kf)} not found\n"
errorMsg += "\nPlease dump your keys using https://github.com/shchmue/Lockpick_RCM/releases\n"
errorMsg += "\nor "
errorMsg += f"{str(kf)}"
errorMsg += " not found\n\nPlease dump your keys using https://github.com/shchmue/Lockpick_RCM/releases\n"
Print.error(errorMsg)
input("Press Enter to exit...")
sys.exit(1)

0 comments on commit f6072a8

Please sign in to comment.