コード例 #1
0
/**
 * gsasl_step64:
 * @sctx: libgsasl client handle.
 * @b64input: input base64 encoded byte array.
 * @b64output: newly allocated output base64 encoded byte array.
 *
 * This is a simple wrapper around gsasl_step() that base64 decodes
 * the input and base64 encodes the output.
 *
 * The contents of the @b64output buffer is unspecified if this
 * functions returns anything other than %GSASL_OK or
 * %GSASL_NEEDS_MORE.  If this function return %GSASL_OK or
 * %GSASL_NEEDS_MORE, however, the @b64output buffer is allocated by
 * this function, and it is the responsibility of caller to deallocate
 * it by calling free (@b64output).
 *
 * Return value: Returns %GSASL_OK if authenticated terminated
 *   successfully, %GSASL_NEEDS_MORE if more data is needed, or error
 *   code.
 **/
int
gsasl_step64 (Gsasl_session * sctx, const char *b64input, char **b64output)
{
  size_t input_len = 0, output_len = 0;
  char *input = NULL, *output = NULL;
  int res;

  if (b64input)
    {
      res = gsasl_base64_from (b64input, strlen (b64input),
			       &input, &input_len);
      if (res != GSASL_OK)
	return GSASL_BASE64_ERROR;
    }

  res = gsasl_step (sctx, input, input_len, &output, &output_len);

  if (input != NULL)
    free (input);

  if (res == GSASL_OK || res == GSASL_NEEDS_MORE)
    {
      int tmpres = gsasl_base64_to (output, output_len, b64output, NULL);

      if (output != NULL)
	free (output);

      if (tmpres != GSASL_OK)
	return tmpres;
    }

  return res;
}
コード例 #2
0
bool builtinSASLMechanism::step
	(ref <SASLSession> sess, const byte_t* challenge, const long challengeLen,
	 byte_t** response, long* responseLen)
{
	char* output = 0;
	size_t outputLen = 0;

	const int result = gsasl_step(sess->m_gsaslSession,
		reinterpret_cast <const char*>(challenge), challengeLen,
		&output, &outputLen);

	if (result == GSASL_OK || result == GSASL_NEEDS_MORE)
	{
		byte_t* res = new byte_t[outputLen];

		for (size_t i = 0 ; i < outputLen ; ++i)
			res[i] = output[i];

		*response = res;
		*responseLen = outputLen;

		gsasl_free(output);
	}
	else
	{
		*response = 0;
		*responseLen = 0;
	}

	if (result == GSASL_OK)
	{
		// Authentication process completed
		m_complete = true;
		return true;
	}
	else if (result == GSASL_NEEDS_MORE)
	{
		// Continue authentication process
		return false;
	}
	else if (result == GSASL_MALLOC_ERROR)
	{
		throw std::bad_alloc();
	}
	else
	{
		throw exceptions::sasl_exception("Error when processing challenge: "
			+ SASLContext::getErrorMessage("gsasl_step", result));
	}
}