Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom decrypted TitleKey #100

Merged
merged 4 commits into from
Jan 26, 2021
Merged

Conversation

xprism1
Copy link

@xprism1 xprism1 commented Jan 25, 2021

I've added the -titlekey option, so users can specify a decrypted TitleKey to use when encrypting a CIA.

@jakcron
Copy link
Collaborator

jakcron commented Jan 26, 2021

Thank you for your pull request! I will review it now.

Copy link
Collaborator

@jakcron jakcron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your pull request, can you please address my feedback so I can merge this :)

makerom/tik.c Outdated
@@ -65,7 +65,7 @@ void SetupTicketHeader(tik_hdr *hdr, cia_settings *ciaset)
SetLimits(hdr,ciaset);

// Crypt TitleKey
if(ciaset->content.encryptCia)
if(ciaset->content.encryptCia || ciaset->common.titleKey)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ciaset->common.titleKey will always evaluate to true because it's a defined as part of struct cia_settings:
u8 titleKey[16];

You need to respect ciaset->content.encryptCia because the common key may not be available in all target configurations (namely test).

I know content.encryptCia will be false by default unless otherwise specified in the RSF file. If you want to override this to true when specifying a title key, then I would do that in here:

cia.c

int GetSettingsFromUsrset(cia_settings *ciaset, user_settings *usrset)
{
	//...
	ciaset->content.encryptCia = usrset->common.rsfSet.Option.EnableCrypt || usrset->cia.titleKey != NULL;
	//...
}

Because a few lines later the ability to encrypt is checked, and turned off if not available. So it's safer this way.

	if(ciaset->keys->aes.commonKey[ciaset->keys->aes.currentCommonKey] == NULL && ciaset->content.encryptCia){
		fprintf(stderr,"[CIA WARNING] Common Key could not be loaded, CIA will not be encrypted\n");
		ciaset->content.encryptCia = false;
	}

makerom/cia.c Show resolved Hide resolved
PrintArgReqParam(argv[i], 1);
return USR_ARG_REQ_PARAM;
}
set->cia.titleKey = argv[i + 1];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please change the indentation from spaces to tabs to match the existing code?

@xprism1
Copy link
Author

xprism1 commented Jan 26, 2021

Addressed your feedback, and made -titlekey override content.encryptCia to true.

@jakcron jakcron merged commit 01ad8fb into 3DSGuy:master Jan 26, 2021
@jakcron
Copy link
Collaborator

jakcron commented Jan 26, 2021

Looks good! Thank you for your contribution :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants