AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SOLVED] XMPP Auth Problem (https://forums.alliedmods.net/showthread.php?t=221763)

GordonFreeman (RU) 07-26-2013 03:50

[SOLVED] XMPP Auth Problem
 
Im working on XMPP client for my server.
For client authorization im must encode "\x00{username}\x00{password}" string.
The problem is AMXX cuts string after 0x00 symbol.

Code:
formatex(auth,127,"%c%s%c%s",0x00,USER,0x00,PASSWORD)

The strlen(auth) give me 0.


How to do that? What i need to do for 0x00 do not cuting the string?

ConnorMcLeod 07-26-2013 03:54

Re: 0x00 in string
 
You can't, but you can manipulate that array as an array instead of a string.

GordonFreeman (RU) 07-26-2013 04:24

Re: 0x00 in string
 
Ok.

The next problem how to encode this string to base64.
Im used encode64 function from this stock. With my edit:
Code:
/* Encodes a string to Base64 */ stock Encode64(const sString[], strLen, sResult[], len) {     new const cFillChar = '=';     new nLength = strLen;

Code:
#define USER        "[email protected]" #define PASSWORD    "12345"
Code:
new auth[512]     formatex(auth,511,"%c%s%c%s",0x00,USER,0x00,PASSWORD)     Encode64(auth,(strlen(USER)+strlen(PASSWORD))+2,auth,511)         server_print(" Encoded: %s",auth)     Decode64(auth,auth,511)     server_print(" Decoded: %s",auth)

Result:
Code:
 Encoded: AQEFRlJsSnNTbk5UYms1VVltczFWVmx0Y3pGVw==  Decoded: FRlJsSnNTbk5UYms1VVltczFW

XMPP Says:
Code:
<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><malformed-request/></failure>

Black Rose 07-26-2013 10:19

Re: XMPP Auth Problem
 
Encode64(auth, ( strlen(USER) + strlen(PASSWORD) ) + 2, auth, 511)
Decode64(auth, auth, 511)

These functions are making changes to the output string on-the-fly. This means you cannot use the same input as output.
The only function that can be used like that is "format" if I'm not mistaken.

This is my code and result:

Code:
#define USER "BlackRose" #define PASSWORD "password" public plugin_init() {     register_plugin("", "", "");         new auth[512], auth2[512]     formatex(auth,511,"%c%s%c%s",0x00,USER,0x00,PASSWORD)         Encode64(auth, ( strlen(USER) + strlen(PASSWORD) ) + 2, auth2, 511)         server_print(" Encoded: %s",auth2)     Decode64(auth2, auth, 511)         for ( new i = 0 ; i < 32 ; i++ ) {         auth2[i] = ! auth[i] ? '*' : auth[i];     }         server_print(" Decoded: %s",auth2) }

Code:

Encoded: AEJsYWNrUm9zZQBwYXNzd29yZA==
 Decoded: *BlackRose*password*************


GordonFreeman (RU) 07-27-2013 01:36

Re: XMPP Auth Problem
 
Good! Thank you very much!


All times are GMT -4. The time now is 06:21.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.