1875999ce27430b581830625e33dcf88bac17e6b
[vg.git] / src / vg / vg_steam_auth.h
1 #ifndef VG_STEAM_AUTH_H
2 #define VG_STEAM_AUTH_H
3
4 #include "vg/vg_platform.h"
5
6 typedef u32 HAuthTicket;
7 enum{ k_HAuthTicketInvalid = 0 };
8
9 #include "vg_steam.h"
10 #if defined( VALVE_CALLBACK_PACK_SMALL )
11 #pragma pack( push, 4 )
12 #elif defined( VALVE_CALLBACK_PACK_LARGE )
13 #pragma pack( push, 8 )
14 #endif
15
16 typedef struct EncryptedAppTicketResponse_t EncryptedAppTicketResponse_t;
17 struct EncryptedAppTicketResponse_t
18 {
19 EResult m_eResult;
20 };
21 enum{ k_iEncryptedAppTicketResponse = k_iSteamUserCallbacks + 54 };
22
23 typedef struct GetAuthSessionTicketResponse_t GetAuthSessionTicketResponse_t;
24 struct GetAuthSessionTicketResponse_t
25 {
26 HAuthTicket m_hAuthTicket;
27 EResult m_eResult;
28 };
29 enum{ k_iGetAuthSessionTicketResponse = k_iSteamUserCallbacks + 63 };
30
31 #pragma pack(pop)
32
33 /*
34 * Regular authentication
35 */
36
37 typedef void ISteamUser;
38 ISteamUser *SteamAPI_SteamUser_v021(void);
39 ISteamUser *SteamAPI_SteamUser(void)
40 {
41 return SteamAPI_SteamUser_v021();
42 }
43
44 HAuthTicket SteamAPI_ISteamUser_GetAuthSessionTicket(
45 ISteamUser *self, void *pTicket,
46 int cbMaxTicket, u32 *pcbTicket );
47
48 /*
49 * Application symetric-key ticket (Client)
50 */
51
52 SteamAPICall_t SteamAPI_ISteamUser_RequestEncryptedAppTicket(
53 ISteamUser *self, void *pDataToInclude, int cbDataToInclude );
54
55 int SteamAPI_ISteamUser_GetEncryptedAppTicket(
56 ISteamUser *self, void *pTicket,
57 int cbMaxTicket, u32 *pcbTicket );
58
59
60 /*
61 * Application symetric-key ticket method (Server)
62 */
63
64 enum { k_nSteamEncryptedAppTicketSymmetricKeyLen = 32 };
65
66 int SteamEncryptedAppTicket_BDecryptTicket( u8 *rgubTicketEncrypted,
67 u32 cubTicketEncrypted, u8 *rgubTicketDecrypted,
68 u32 *pcubTicketDecrypted,
69 u8 rgubKey[k_nSteamEncryptedAppTicketSymmetricKeyLen],
70 int cubKey );
71
72 int SteamEncryptedAppTicket_BIsTicketForApp( u8 *rgubTicketDecrypted,
73 u32 cubTicketDecrypted, AppId_t nAppID );
74
75 RTime32 SteamEncryptedAppTicket_GetTicketIssueTime( u8 *rgubTicketDecrypted,
76 u32 cubTicketDecrypted );
77
78 void SteamEncryptedAppTicket_GetTicketSteamID(
79 u8 *rgubTicketDecrypted, u32 cubTicketDecrypted, CSteamID *psteamID );
80
81 AppId_t SteamEncryptedAppTicket_GetTicketAppID( u8 *rgubTicketDecrypted,
82 u32 cubTicketDecrypted );
83
84 int SteamEncryptedAppTicket_BUserOwnsAppInTicket( u8 *rgubTicketDecrypted,
85 u32 cubTicketDecrypted, AppId_t nAppID );
86
87 int SteamEncryptedAppTicket_BUserIsVacBanned( u8 *rgubTicketDecrypted,
88 u32 cubTicketDecrypted );
89
90 int SteamEncryptedAppTicket_BGetAppDefinedValue( u8 *rgubTicketDecrypted,
91 u32 cubTicketDecrypted, u32 *pValue );
92
93 u8 *SteamEncryptedAppTicket_GetUserVariableData( u8 *rgubTicketDecrypted,
94 u32 cubTicketDecrypted, u32 *pcubUserData );
95
96 int SteamEncryptedAppTicket_BIsTicketSigned( u8 *rgubTicketDecrypted,
97 u32 cubTicketDecrypted, u8 *pubRSAKey, u32 cubRSAKey );
98
99 int SteamEncryptedAppTicket_BIsLicenseBorrowed( u8 *rgubTicketDecrypted,
100 u32 cubTicketDecrypted );
101
102 int SteamEncryptedAppTicket_BIsLicenseTemporary( u8 *rgubTicketDecrypted,
103 u32 cubTicketDecrypted );
104
105 static u8 vg_char_base16( char c )
106 {
107 if( c >= '0' && c <= '9' )
108 return c-'0';
109 if( c >= 'a' && c <= 'f' )
110 return (c-'a') + 10;
111
112 return 0;
113 }
114
115 static int vg_load_steam_symetric_key( const char *path, u8 *buf )
116 {
117 i64 len;
118 char *text_src = vg_textasset_read_s( path, &len );
119
120 if( text_src )
121 {
122 if( len < k_nSteamEncryptedAppTicketSymmetricKeyLen )
123 {
124 vg_error( "Application key was invalid size\n" );
125 vg_free( text_src );
126 return 0;
127 }
128
129 for( int i=0; i<k_nSteamEncryptedAppTicketSymmetricKeyLen; i++ )
130 {
131 buf[i] = (vg_char_base16( text_src[i*2+0] ) << 4) |
132 vg_char_base16( text_src[i*2+1] );
133 }
134
135 vg_free( text_src );
136 return 1;
137 }
138 else
139 {
140 vg_error( "Application key path was invalid\n" );
141 return 0;
142 }
143 }
144
145
146 #endif /* VG_STEAM_AUTH_H */