Esempio n. 1
0
rho::String MethodResultJni::getErrorMessage(JNIEnv* env)
{
    if(m_resType == typeNone)
    {
        jhstring jhMessage = getStringResult(env);
        return rho_cast<std::string>(env, jhMessage.get());
    } else
    {
        return m_errMsg;
    }
}
rho::String MethodResultJni::getErrorMessage(JNIEnv* env) const
{
    RAWTRACE(__FUNCTION__);
    if(m_resType == typeNone && m_jhResult)
    {
        jhstring jhMessage = getStringResult(env);
        return rho_cast<std::string>(env, jhMessage.get());
    } else
    {
        return m_errMsg;
    }
}
Esempio n. 3
0
 void CouchbaseRowBuilder::getUTF8Result(const RtlFieldInfo *field, size32_t &chars, char * &result)
 {
     getStringResult(field, chars, result);
     return;
 }
Esempio n. 4
0
 void CouchbaseEmbedFunctionContext::getUTF8Result(size32_t &chars, char * &result)
 {
     getStringResult(chars, result);
 }
/**
 * @brief Private routine used to check if the Digest Authentication message can be accepted or rejected.
 *
 * @param 
 *
 * @Return TRUE if everything if fine
 *         FALSE otherwise.
 *
 */
bool
performClientDigestAuthentication(const char * _str){

  bool nRet = false;

  DBG("DIGEST AUTH - Str:\n%s", _str);

  unsigned char signature[SIGNATURE_SIZE];

  char digestUsernameTokenStr[MAXTOKENSIZE];
  char realmTokenStr[MAXTOKENSIZE];
  char nonceTokenStr[MAXTOKENSIZE];
  char uriTokenStr[MAXTOKENSIZE];
  char responseTokenStr[MAXTOKENSIZE];
  char opaqueTokenStr[MAXTOKENSIZE];
  char qopTokenStr[MAXTOKENSIZE];
  char ncTokenStr[MAXTOKENSIZE];
  char cnonceTokenStr[MAXTOKENSIZE];
  char * httpMethodPtr = NULL;
  char pBufferTemp[SIZE_HTTP_MSG]; // No need to require a very large buffer.

  // Below variables used to compute the response
  MD5_CTX ha1Ctx;
  MD5_CTX ha2Ctx;
  MD5_CTX responseCtx;
  char ha1Str[HA1_MAXTOKENSIZE];
  char ha2Str[HA2_MAXTOKENSIZE];
  char totalStr[TOTAL_MAXTOKENSIZE];
  char ha1StrResult[MAXTOKENSIZE];
  char ha2StrResult[MAXTOKENSIZE];
  char totalStrResult[MAXTOKENSIZE];

  memset((void*) digestUsernameTokenStr, 0x00, MAXTOKENSIZE);
  memset((void*) realmTokenStr,          0x00, MAXTOKENSIZE);
  memset((void*) nonceTokenStr,          0x00, MAXTOKENSIZE);
  memset((void*) uriTokenStr,            0x00, MAXTOKENSIZE);
  memset((void*) responseTokenStr,       0x00, MAXTOKENSIZE);
  memset((void*) opaqueTokenStr,         0x00, MAXTOKENSIZE);
  memset((void*) qopTokenStr,            0x00, MAXTOKENSIZE);
  memset((void*) ncTokenStr,             0x00, MAXTOKENSIZE);
  memset((void*) cnonceTokenStr,         0x00, MAXTOKENSIZE);
  memset((void*) pBufferTemp,            0x00, SIZE_HTTP_MSG);  

  memset((void *) ha1Str,                0x00, HA1_MAXTOKENSIZE);
  memset((void *) ha2Str,                0x00, HA2_MAXTOKENSIZE);
  memset((void *) totalStr,              0x00, TOTAL_MAXTOKENSIZE);

  // Get all the digest data from the message
  if(!_getDigestMessageToken(_str,
                             digestUsernameTokenStr,
                             realmTokenStr,
                             nonceTokenStr,
                             uriTokenStr,
                             responseTokenStr,
                             opaqueTokenStr,
                             qopTokenStr,
                             ncTokenStr,
                             cnonceTokenStr)) {
    EXEC_ERROR("Can not retrieve all the HTTP Digest Tokens");
    return false;
	}

	// Make sure the nonce and opaque str are identical to 
	// the strings sent in the request authentication demand message
	// Note: These strings are generated randomly
	if((0 != strcmp(randomNonceStr, nonceTokenStr))   ||
	   (0 != strcmp(randomOpaqueStr, opaqueTokenStr))) {
    EXEC_ERROR("Authentication request does not match the generated Authentication demand message");
    EXEC_ERROR("Nonce and opaue strings are diferent from the generated ones.");
    return false;	   
	} else {
	  DBG("HTTP Digest MD5 Auth - Nonce and Opaque are valid.");
	}

	// Make sure the requested URL corrspond to the randomly choosen one.
	if(NULL == strstr(uriTokenStr, g_randomCpeUrl)) {
	  WARN("--------- The requested and choosen URL are not equal");
	  WARN("--------- Requested: %s, randomly Choosen by CPE: %s", uriTokenStr, g_randomCpeUrl);
	  WARN("Must return FALSE but for test purpose and while DM_ENGINE does not use g_randomCpeUrl continue...");
	  // return FALSE;
  } else {
    DBG("HTTP Digest MD5 Auth - CPE URL is Valid.");
  }

  char* parameterNames[] = { (char*)DM_TR106_CONNECTIONREQUESTUSERNAME, (char*)DM_TR106_CONNECTIONREQUESTPASSWORD, NULL };
  DM_ENG_ParameterValueStruct** result = NULL;

  char* cpeUsername = NULL;
  char* cpeConnectionRequestPassword = NULL;

  if ((DM_ENG_GetParameterValues( DM_ENG_EntityType_ANY, parameterNames, &result ) == 0)
   && (result != NULL) && (result[0] != NULL) && (result[1] != NULL)) // luxe de conditions normalement inutiles
  {
     cpeUsername = result[0]->value;
     cpeConnectionRequestPassword = result[1]->value;
  }

  if ((cpeUsername == NULL) || (cpeConnectionRequestPassword == NULL))
  {
    EXEC_ERROR("Can not retrieve the CPE Connection Request Username and Password");
    return false;  
  }

  DBG("CPE username: %s, password: %s", cpeUsername, cpeConnectionRequestPassword);

  // Build ha1Str (username:realm:password)
  strncpy(ha1Str, cpeUsername,                  HA1_MAXTOKENSIZE);
  strncat(ha1Str, ":",                          HA1_MAXTOKENSIZE - strlen(ha1Str));
  strncat(ha1Str, realmTokenStr,                HA1_MAXTOKENSIZE - strlen(ha1Str));
  strncat(ha1Str, ":",                          HA1_MAXTOKENSIZE - strlen(ha1Str));
  strncat(ha1Str, cpeConnectionRequestPassword, HA1_MAXTOKENSIZE - strlen(ha1Str));

  DM_ENG_deleteTabParameterValueStruct(result);

	// Compute the response.
  DBG("DIGEST AUTH - ha1Str:%s", ha1Str);

  MD5_Init (&ha1Ctx);  
  MD5_Update (&ha1Ctx, (unsigned char *) ha1Str, strlen(ha1Str));
  memset((void *) signature, 0x00, SIGNATURE_SIZE);
  MD5_Final (signature, &ha1Ctx);
  getStringResult(signature, ha1StrResult);
  DBG("DIGEST AUTH - MD5(ha1Str):%s", ha1StrResult);

  // Build ha2Str (HTTPCommand:uri)
  // Recopy the buffer into a temp one to use strtok
  strncpy( pBufferTemp, _str, SIZE_HTTP_MSG );
  httpMethodPtr   = strtok( pBufferTemp, " " );
  strncpy(ha2Str, httpMethodPtr, HA2_MAXTOKENSIZE);
  strncat(ha2Str, ":",           HA2_MAXTOKENSIZE - strlen(ha2Str));
  strncat(ha2Str, uriTokenStr,   HA2_MAXTOKENSIZE - strlen(ha2Str));

  DBG("DIGEST AUTH - ha2Str:%s\n", ha2Str);

  MD5_Init (&ha2Ctx);  
  MD5_Update (&ha2Ctx, (unsigned char *) ha2Str, strlen(ha2Str));
  memset((void *) signature, 0x00, SIGNATURE_SIZE);
  MD5_Final (signature, &ha2Ctx);
  getStringResult(signature, ha2StrResult);
  DBG("DIGEST AUTH - MD5(ha2Str):%s\n", ha2StrResult);

  // Build totalStr (ha1:noncevalue:nc-value:cnonce-value:qop:ha2)
  strncpy(totalStr, ha1StrResult,   TOTAL_MAXTOKENSIZE);
  strncat(totalStr, ":",            TOTAL_MAXTOKENSIZE - strlen(totalStr) );
  strncat(totalStr, nonceTokenStr,  TOTAL_MAXTOKENSIZE - strlen(totalStr));
  strncat(totalStr, ":",            TOTAL_MAXTOKENSIZE - strlen(totalStr));
  strncat(totalStr, ncTokenStr,     TOTAL_MAXTOKENSIZE - strlen(totalStr));
  strncat(totalStr, ":",            TOTAL_MAXTOKENSIZE - strlen(totalStr));
  strncat(totalStr, cnonceTokenStr, TOTAL_MAXTOKENSIZE - strlen(totalStr));
  strncat(totalStr, ":",            TOTAL_MAXTOKENSIZE - strlen(totalStr));
  strncat(totalStr, qopTokenStr,    TOTAL_MAXTOKENSIZE - strlen(totalStr));
  strncat(totalStr, ":",            TOTAL_MAXTOKENSIZE - strlen(totalStr));
  strncat(totalStr, ha2StrResult,   TOTAL_MAXTOKENSIZE - strlen(totalStr));

  DBG("DIGEST AUTH - totalStr:%s\n", totalStr);

  MD5_Init (&responseCtx);
  MD5_Update (&responseCtx, (unsigned char *) totalStr, strlen(totalStr));
  memset((void *) signature, 0x00, SIGNATURE_SIZE);
  MD5_Final (signature, &responseCtx);
  getStringResult(signature, totalStrResult);

  // Compare the computed result and the transmitted one.
  if(0 == strcmp(totalStrResult, responseTokenStr)) {
    INFO("DIGEST AUTH - AUTHENTICATION OK");
    nRet = true;
  } else {
    WARN("DIGEST AUTH - AUTHENTICATION NOK");
    WARN("DIGEST AUTH - Computed Result:%s", totalStrResult);
    WARN("DIGEST AUTH - Transmitted Result:%s", responseTokenStr);
  }

  return nRet;
}
Esempio n. 6
0
VALUE MethodResultJni::toRuby()
{
    RAWTRACE("toRuby");

    VALUE res = Qnil;

    JNIEnv *env = jniInit();
    if (!env) {
        RAWLOG_FATAL("JNI initialization failed");
        rb_raise(rb_eRuntimeError,"JNI initialization failed");
        return Qnil;
    }

    int type = getResultType(env);
    switch(type)
    {
    case typeNone:
        break;
    case typeBoolean:
        {
            bool booleanResult = static_cast<bool>(getBooleanResult(env));
            res = booleanResult ? Qtrue : Qfalse;
        }
        break;
    case typeInteger:
    {
        int intResult = static_cast<int>(getIntegerResult(env));
        res = rho_ruby_create_integer(intResult);
    }
    break;
    case typeDouble:
    {
        double doubleResult = static_cast<double>(getDoubleResult(env));
        res = rho_ruby_create_double(doubleResult);
    }
    break;
    case typeString:
        {
            jhstring jhStrResult = getStringResult(env);
            res = rho_cast<VALUE>(env, jhStrResult);
        }
        break;
    case typeList:
        {
            jhobject jhListResult = getListResult(env);
            res = rho_cast<VALUE>(env, jhListResult);
        }
        break;
    case typeMap:
        {
            jhobject jhMapResult = getMapResult(env);
            res = rho_cast<VALUE>(env, jhMapResult);
        }
        break;
    case typeArgError:
        rho_ruby_raise_argerror(getErrorMessage(env).c_str());
        break;
    case typeError:
        rb_raise(rb_eRuntimeError, getErrorMessage(env).c_str());
        break;
    default:
        RAWLOG_FATAL("Unknown runtime error in MethodResultJni class");
        rb_raise(rb_eRuntimeError,"Unknown runtime error in MethodResultJni class");
    }

    reset(env);
    return res;
}