static void iks_sasl_challenge(struct stream_data *data, iks *challenge) { char *message; iks *x; char *tmp; tmp = iks_cdata(iks_child(challenge)); if(!tmp) return; /* decode received blob */ message = iks_base64_decode(tmp, NULL); if(!message) return; /* reply the challenge */ if(strstr(message, "rspauth")) { x = iks_new("response"); } else { x = make_sasl_response(data, message); } if(x) { iks_insert_attrib(x, "xmlns", IKS_NS_XMPP_SASL); iks_send(data->prs, x); iks_delete(x); } iks_free(message); }
/** * Parse authzid, authcid, and password tokens from base64 PLAIN auth message. * @param message the base-64 encoded authentication message * @param authzid the authorization id in the message - free this string when done with parsed message * @param authcid the authentication id in the message * @param password the password in the message */ void parse_plain_auth_message(const char *message, char **authzid, char **authcid, char **password) { char *decoded = iks_base64_decode(message); int maxlen = strlen(message) * 6 / 8 + 1; int pos = 0; *authzid = NULL; *authcid = NULL; *password = NULL; if (decoded == NULL) { goto end; } pos = strlen(decoded) + 1; if (pos >= maxlen) { goto end; } *authcid = strdup(decoded + pos); pos += strlen(*authcid) + 1; if (pos >= maxlen) { goto end; } *password = strdup(decoded + pos); if (zstr(decoded)) { *authzid = strdup(*authcid); } else { *authzid = strdup(decoded); } end: switch_safe_free(decoded); }
// xxx needs error return value static void send_sasl_challenge (ikss_Stream *self, iks *challenge) { char *message; iks *x; char *tmp; tmp = iks_cdata (iks_child (challenge)); if (!tmp) return; /* decode received blob */ message = iks_base64_decode (tmp); if (!message) return; /* reply the challenge */ if (strstr (message, "rspauth")) { x = iks_new ("response"); } else { x = make_sasl_response (self, message); } if (x) { iks_insert_attrib (x, "xmlns", IKS_NS_XMPP_SASL); ikss_Stream_send_node (self, x); // xxx check return value iks_delete (x); } iks_free (message); }