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