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