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