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

SteamEncryptedAppTicket.BDecryptTicket does not correctly decrypt app ticket in Spacewar #617

Open
altamkp opened this issue Jun 23, 2024 · 1 comment

Comments

@altamkp
Copy link

altamkp commented Jun 23, 2024

I am trying to create a backend server for my game built in Godot. By following this page, I have come up with the following code so far. Note that the private key was retrieved from within the example code in the sdk.

private const uint SIZE = 1024;
private static readonly byte[] KEY = [0xed, 0x93, 0x86, 0x07, 0x36, 0x47, 0xce, 0xa5, 0x8b, 0x77, 0x21, 0x49, 0x0d, 0x59, 0xed, 0x44, 0x57, 0x23, 0xf0, 0xf6, 0x6e, 0x74, 0x14, 0xe1, 0x53, 0x3b, 0xa3, 0x3c, 0xd8, 0x03, 0xbd, 0xbd];
    
public AuthenticationResult Authenticate(string ticket) {
    var ticketEncrypted = Convert.FromBase64String(ticket);
    var ticketDecrypted = new byte[SIZE];
    uint ticketSize = SIZE;
    if (!SteamEncryptedAppTicket.BDecryptTicket(ticketEncrypted, (uint)ticketEncrypted.Length,
            ticketDecrypted, ref ticketSize, KEY, KEY.Length)) {
        return new AuthenticationResult(false, null!);
    }

    return new AuthenticationResult(true, "Hello world");
}

My problem is that SteamEncryptedAppTicket.BDecryptTicket always return false. The documentation for this api states that it returns false under these conditions:

false under the following conditions:
cubKey was 0.
The size of the output buffer rgubTicketDecrypted is too small. It must be at least as big as rgubTicketEncrypted.
Reading rgubTicketEncrypted failed, this could happen if it's NULL or empty.
Encryption failed, likely because the key is incorrect.

Please kindly point me in the right direction.

@altamkp
Copy link
Author

altamkp commented Jun 24, 2024

To follow up, I have discovered that further calls to other SteamEncryptedAppTicket apis return correct and expected results, even after BDecryptTicket returned false.

var isForApp = SteamEncryptedAppTicket.BIsTicketForApp(ticketDecrypted, ticketSize, (AppId_t)480);
var appId = SteamEncryptedAppTicket.GetTicketAppID(ticketDecrypted, ticketSize);
var issueTimeUnix = SteamEncryptedAppTicket.GetTicketIssueTime(ticketDecrypted, ticketSize);
var issueTime = DateTimeOffset.FromUnixTimeSeconds(issueTimeUnix).ToLocalTime();
SteamEncryptedAppTicket.GetTicketSteamID(ticketDecrypted, ticketSize, out var steamId);

If the above calls return correct results, I would expect that the ticket was successfully decrypted. Could this be an issue related to #21?

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

No branches or pull requests

1 participant