Example #1
5
// =========================================================================
// 函数功能:处理客户端对挑战信息的响应
// 输入参数:待交流的客户端cl
// 输出参数:
// 返回值  :
// 说明    :当响应消息失败时,3.7以上的版本会发送失败的原因,而3.7及其以下会直接
//          关闭客户端
// =========================================================================
void rfbAuthProcessClientMessage(rfbClientPtr cl)
{
    char *passwd="123";
    int n;
    u8 response[CHALLENGESIZE];
    u32 authResult;

    if ((n = ReadExact(cl, (char *)response, CHALLENGESIZE)) <= 0) {
        if (n != 0)
            debug_printf("rfbAuthProcessClientMessage: read");
        rfbCloseClient(cl);
        return;
    }
     rfbEncryptBytes(cl->authChallenge, passwd);


    if (memcmp(cl->authChallenge, response, CHALLENGESIZE) != 0) {
        debug_printf("rfbAuthProcessClientMessage: authentication failed from %s\n",
               cl->host);

        authResult = Swap32IfLE(rfbVncAuthFailed);

        if (WriteExact(cl, (char *)&authResult, 4) < 0) {
            debug_printf("rfbAuthProcessClientMessage: write");
            rfbClientSendString(cl,"challengdge failed\n");
        }
        rfbCloseClient(cl);
        return;
    }
    else
    {
        debug_printf("challendge success ---cl=%s",cl->host);

    }

    authResult = Swap32IfLE(rfbVncAuthOK);

    if (WriteExact(cl, (char *)&authResult, 4) < 0) {
        debug_printf("rfbAuthProcessClientMessage: write");
        rfbCloseClient(cl);
        return;
    }

    cl->state = RFB_INITIALISATION;
}
Example #2
0
File: auth.c Project: djyos/djyos
static void
rfbSendSecurityTypeList(rfbClientPtr cl, int primaryType)
{
    /* The size of the message is the count of security types +1,
     * since the first byte is the number of types. */
    int size = 1;
    rfbSecurityHandler* handler;
#define MAX_SECURITY_TYPES 255
    uint8_t buffer[MAX_SECURITY_TYPES+1];


    /* Fill in the list of security types in the client structure. (NOTE: Not really in the client structure) */
    switch (primaryType) {
    case rfbSecTypeNone:
        rfbRegisterSecurityHandler(&VncSecurityHandlerNone);
        break;
    case rfbSecTypeVncAuth:
        rfbRegisterSecurityHandler(&VncSecurityHandlerVncAuth);
        break;
    }

    for (handler = securityHandlers;
	    handler && size<MAX_SECURITY_TYPES; handler = handler->next) {
	buffer[size] = handler->type;
	size++;
    }
    buffer[0] = (unsigned char)size-1;

    /* Send the list. */
    if (rfbWriteExact(cl, (char *)buffer, size) < 0) {
	rfbLogPerror("rfbSendSecurityTypeList: write");
	rfbCloseClient(cl);
	return;
    }

    /*
      * if count is 0, we need to send the reason and close the connection.
      */
    if(size <= 1) {
	/* This means total count is Zero and so reason msg should be sent */
	/* The execution should never reach here */
	char* reason = "No authentication mode is registered!";

	rfbClientSendString(cl, reason);
	return;
    }

    /* Dispatch client input to rfbProcessClientSecurityType. */
    cl->state = RFB_SECURITY_TYPE;
}