switchbrew / libnx

Library for Switch Homebrew
https://switchbrew.github.io/libnx/
ISC License
1.26k stars 167 forks source link

Implement FS "ChallengeCardExistence" and "GetGameCardDeviceCertificate" #631

Closed EpicUsername12 closed 7 months ago

EpicUsername12 commented 10 months ago

Example usage:

int main(int argc, char *argv[])
{
    consoleInit(NULL);

    PadState pad;
    padConfigureInput(1, HidNpadStyleSet_NpadStandard);
    padInitializeDefault(&pad);

    nsInitialize();
    fsInitialize();

    FsDeviceOperator deviceOperator;
    fsOpenDeviceOperator(&deviceOperator);

    FsGameCardHandle gcHandle = {-1};
    fsDeviceOperatorGetGameCardHandle(&deviceOperator, &gcHandle);

    u8 cert[0x200]; // output
    fsDeviceOperatorGetGameCardDeviceCertificate(&deviceOperator, &gcHandle, cert, sizeof(cert), sizeof(cert));

    // From application authentication /v%i/challenge endpoint (AAuth, used to authenticate gamecards, they can complete a proprietary challenge to prove they are legit)
    u8 seed[15] = {...};
    u8 value[16] = {...};
    u8 challenge[0x58]; // output
    fsDeviceOperatorChallengeCardExistence(&deviceOperator, &gcHandle,
                                                challenge, sizeof(challenge),
                                                seed, sizeof(seed),
                                                value, sizeof(value));

    fsDeviceOperatorClose(&deviceOperator);
    fsExit();

    nsEnsureGameCardAccess();
    nsExit();

    consoleExit(NULL);
    return 0;
}