Skip to content

Play your Steam library's Windows games on a jailbroken PS5.

C++
5.5 KB
Raw Blame
#pragma once

#include "steam/backend/proto_wire.h"

#include <cstddef>
#include <cstdint>
#include <optional>
#include <string>
#include <vector>

namespace playden::steam::auth {

enum class PlatformType : std::int32_t {
  kUnknown = 0,
  kSteamClient = 1,
  kWebBrowser = 2,
  kMobileApp = 3,
};

enum class GuardType : std::int32_t {
  kUnknown = 0,
  kNone = 1,
  kEmailCode = 2,
  kDeviceCode = 3,
  kDeviceConfirmation = 4,
  kEmailConfirmation = 5,
  kMachineToken = 6,
  kLegacyMachineAuth = 7,
};

enum class SessionPersistence : std::int32_t {
  kEphemeral = 0,
  kPersistent = 1,
};

enum class TokenRenewalType : std::int32_t {
  kNone = 0,
  kAllow = 1,
};

struct DeviceDetails {
  std::string device_friendly_name;
  PlatformType platform_type = PlatformType::kSteamClient;
  std::int32_t os_type = 0;
  // The machine ID the CM logon sends (binary KeyValues), so the sign-in and the logons name one machine. Empty: not sent.
  std::vector<std::uint8_t> machine_id;
};

// The device's friendly name and platform are also sent at the top level, like the credentials request.
struct BeginAuthSessionViaQrRequest {
  DeviceDetails device_details;
  std::string website_id = "Client";
};

struct AllowedConfirmation {
  GuardType confirmation_type = GuardType::kUnknown;
  std::string associated_message;
};

struct BeginAuthSessionViaQrResponse {
  std::uint64_t client_id = 0;
  std::string challenge_url;
  std::vector<std::uint8_t> request_id;
  float interval = 0;
  std::vector<AllowedConfirmation> allowed_confirmations;
  std::int32_t version = 0;
};

// Sent as a GET: the key encrypts the account's password for BeginAuthSessionViaCredentials.
struct GetPasswordRsaPublicKeyRequest {
  std::string account_name;
};

struct GetPasswordRsaPublicKeyResponse {
  std::string publickey_mod;  // hex
  std::string publickey_exp;  // hex
  std::uint64_t timestamp = 0;
};

// The device's friendly name and platform are also sent at the top level, as the Steam client does.
struct BeginAuthSessionViaCredentialsRequest {
  DeviceDetails device_details;
  std::string account_name;
  std::string encrypted_password;  // base64
  std::uint64_t encryption_timestamp = 0;
  bool remember_login = true;
  SessionPersistence persistence = SessionPersistence::kPersistent;
  std::string website_id = "Client";
};

struct BeginAuthSessionViaCredentialsResponse {
  std::uint64_t client_id = 0;
  std::vector<std::uint8_t> request_id;
  float interval = 0;
  std::vector<AllowedConfirmation> allowed_confirmations;
  std::uint64_t steam_id = 0;
  std::string weak_token;
  std::string agreement_session_url;
  std::string extended_error_message;
};

// Its response carries nothing Playden uses; success is the X-EResult header.
struct UpdateAuthSessionWithSteamGuardCodeRequest {
  std::uint64_t client_id = 0;
  std::uint64_t steam_id = 0;
  std::string code;
  GuardType code_type = GuardType::kUnknown;
};

struct PollAuthSessionStatusRequest {
  std::uint64_t client_id = 0;
  std::vector<std::uint8_t> request_id;
  std::optional<std::uint64_t> token_to_revoke;
};

struct PollAuthSessionStatusResponse {
  std::optional<std::uint64_t> new_client_id;
  std::optional<std::string> new_challenge_url;
  std::string refresh_token;
  std::string access_token;
  bool had_remote_interaction = false;
  std::string account_name;
  std::optional<std::string> new_guard_data;
  std::string agreement_session_url;
};

struct GenerateAccessTokenForAppRequest {
  std::string refresh_token;
  std::uint64_t steam_id = 0;
  TokenRenewalType renewal_type = TokenRenewalType::kNone;
};

struct GenerateAccessTokenForAppResponse {
  std::string access_token;
  std::optional<std::string> refresh_token;
};

proto::Status Encode(const BeginAuthSessionViaQrRequest& message,
                     std::vector<std::uint8_t>* output);
proto::Status Decode(const std::uint8_t* data, std::size_t size,
                     BeginAuthSessionViaQrResponse* message,
                     proto::DecodeLimits limits = {});

proto::Status Encode(const GetPasswordRsaPublicKeyRequest& message,
                     std::vector<std::uint8_t>* output);
proto::Status Decode(const std::uint8_t* data, std::size_t size,
                     GetPasswordRsaPublicKeyResponse* message,
                     proto::DecodeLimits limits = {});

proto::Status Encode(const BeginAuthSessionViaCredentialsRequest& message,
                     std::vector<std::uint8_t>* output);
proto::Status Decode(const std::uint8_t* data, std::size_t size,
                     BeginAuthSessionViaCredentialsResponse* message,
                     proto::DecodeLimits limits = {});

proto::Status Encode(const UpdateAuthSessionWithSteamGuardCodeRequest& message,
                     std::vector<std::uint8_t>* output);

proto::Status Encode(const PollAuthSessionStatusRequest& message,
                     std::vector<std::uint8_t>* output);
proto::Status Decode(const std::uint8_t* data, std::size_t size,
                     PollAuthSessionStatusResponse* message,
                     proto::DecodeLimits limits = {});

proto::Status Encode(const GenerateAccessTokenForAppRequest& message,
                     std::vector<std::uint8_t>* output);
proto::Status Decode(const std::uint8_t* data, std::size_t size,
                     GenerateAccessTokenForAppResponse* message,
                     proto::DecodeLimits limits = {});

template <typename Message>
proto::Status Decode(const std::vector<std::uint8_t>& bytes, Message* message,
                     proto::DecodeLimits limits = {}) {
  return Decode(bytes.data(), bytes.size(), message, limits);
}

}  // namespace playden::steam::auth