⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 des_auth.c

📁 基于nucleus实时操作系统的webserver源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
         * http://XXX.XXX.XXX.XXX/index.htm,
         */
        strcpy(success, "http://");
        strcat(success, (CHAR *)NU_ITOA((INT)WS_Master_Server.ws_ip[0], temp, 10));
        strcat(success, ".");
        strcat(success, (CHAR *)NU_ITOA((INT)WS_Master_Server.ws_ip[1], temp, 10));
        strcat(success, ".");
        strcat(success, (CHAR *)NU_ITOA((INT)WS_Master_Server.ws_ip[2], temp, 10));
        strcat(success, ".");
        strcat(success, (CHAR *)NU_ITOA((INT)WS_Master_Server.ws_ip[3], temp, 10));
        strcat(success, "/index.htm");
        
        WS_Write_To_Net(req, success, strlen(success), WS_FILETRNSFR);

        p->ws_master.ws_auth_state = 0;
    }
    else
    {
        /*  Enable Authentication */
        HTTP_Auth_Control(p, WS_A_ENABLE, NU_NULL);

        /*
         * Send to the Java applet the Redirection Ip address. 
         * http://XXX.XXX.XXX.XXX/failure.htm,
         */
        strcpy(fail, "http://");
        strcat(fail, (CHAR *)NU_ITOA((INT)WS_Master_Server.ws_ip[0], temp, 10));
        strcat(fail, ".");
        strcat(fail, (CHAR *)NU_ITOA((INT)WS_Master_Server.ws_ip[1], temp, 10));
        strcat(fail, ".");
        strcat(fail, (CHAR *)NU_ITOA((INT)WS_Master_Server.ws_ip[2], temp, 10));
        strcat(fail, ".");
        strcat(fail, (CHAR *)NU_ITOA((INT)WS_Master_Server.ws_ip[3], temp, 10));
        strcat(fail, "/failure.htm");

        /*  Send Response to the Network */
        WS_Write_To_Net(req, fail, strlen(fail), WS_FILETRNSFR);

        p->ws_master.ws_auth_state = 0;     
    }       
    
    return(WS_REQ_PROCEED);
}

/************************************************************************
*                                                                       
* FUNCTION                                                              
*                                                                       
*       DES_New_Key                                                      
*                                                                       
* DESCRIPTION                                                           
*              
*                                                         
*                                                                       
* INPUTS                                                                
*                                                                       
*       *env                                                              
*       *req                                                              
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       NU_SUCCESS
*                                                                       
************************************************************************/
static INT DES_New_Key(WS_REQUEST *req)
{
    CHAR            success[250];
    UINT8           cypher_a[17];   
    UINT8           xor_mask[17];
    INT             i;
    CHAR            *s;
    CHAR            key[10];
    CHAR            temp[10];

    /* Clear the Success Structure */
    UTL_Zero(success,250);

    /* get the VALUE string from the POST request */
    s = HTTP_Token_Value_by_Name("VALUE", req);

#ifdef NU_WEBSERV_DEBUG
    printf("VALUE= %s\n",s);
#endif

    /* convert the new key ( cypher_a)   
     * and the mask ( xor_mask) 
     * to binary
     */ 

    HTTP_Packed_Hex_To_Bin((CHAR *)cypher_a, s, 32);
    HTTP_Packed_Hex_To_Bin((CHAR *)xor_mask, s + 32, 32);
    
#ifdef NU_WEBSERV_DEBUG
    printf("KEY = %s\n", req->ws_server->ws_master.ws_key);
#endif

    /* decrypt each string */

    ENC_Decrypt((CHAR *)req->ws_server->ws_master.ws_key,(CHAR *)xor_mask,2);
    ENC_Decrypt((CHAR *)req->ws_server->ws_master.ws_key,(CHAR *)cypher_a,2);

    /* XOR our decrypted user and passwd with the 
     * decrypted salt
     */

    for(i = 0; i < 16; i++)
        cypher_a[i] ^= xor_mask[i];

    /* make sure there is a null */
    cypher_a[16] = 0;                                 

#ifdef NU_WEBSERV_DEBUG
    printf("string 1:%s\n",cypher_a);   
#endif

    strncpy((CHAR *)key, (CHAR *)cypher_a, 9);
    key[9] = 0;
    strcpy((CHAR *)req->ws_server->ws_master.ws_key, (CHAR *)key);

    /* 
     * Send Response to redirect Applet to a specific WebPage 
     * http://XXX.XXX.XXX.XXX/nkey.htm,
     */
    strcpy(success, "http://");
    strcat(success, (CHAR *)NU_ITOA((INT)WS_Master_Server.ws_ip[0], temp, 10));
    strcat(success, ".");
    strcat(success, (CHAR *)NU_ITOA((INT)WS_Master_Server.ws_ip[1], temp, 10));
    strcat(success, ".");
    strcat(success, (CHAR *)NU_ITOA((INT)WS_Master_Server.ws_ip[2], temp, 10));
    strcat(success, ".");
    strcat(success, (CHAR *)NU_ITOA((INT)WS_Master_Server.ws_ip[3], temp, 10));
    strcat(success, "/nkey.htm");

    WS_Write_To_Net(req, success, strlen(success), WS_FILETRNSFR);
    
    return(WS_REQ_PROCEED);
}

/************************************************************************
*                                                                       
* FUNCTION                                                              
*                                                                       
*       DES_Auth_Add                                                         
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       Adds an Authentication User ID and Password to the Doubly Linked 
*       List.  It returns an IP address of whether it was successful     
*       or not the Browser.                                              
*                                                                       
* INPUTS                                                                
*                                                                       
*       *env                                                              
*       *req                                                              
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       NU_SUCCESS
*                                                                       
************************************************************************/
static INT DES_Auth_Add(WS_REQUEST *req)
{   
    CHAR            success[250];
    CHAR            fail[250];
    UINT8           cypher_a[17];
    UINT8           cypher_b[17];
    UINT8           xor_mask[17];
    INT             i;
    CHAR            *s;
    CHAR            temp[10];
    
    /*  Initialize the Success and Fail Messages */
    UTL_Zero(success,250);
    UTL_Zero(fail,250);

    /* get the VALUE string from the POST request */
    s = HTTP_Token_Value_by_Name("VALUE", req);

#ifdef NU_WEBSERV_DEBUG
    printf("VALUE= %s\n",s);
#endif

    /* convert the user ( cypher_a)
     * and the passwd ( cypher_b)
     * and the mask ( xor_mask) 
     * to binary
     */ 

    HTTP_Packed_Hex_To_Bin((CHAR *)cypher_a, (CHAR *)s, 32);
    HTTP_Packed_Hex_To_Bin((CHAR *)cypher_b, (CHAR *)s + 32, 32);
    HTTP_Packed_Hex_To_Bin((CHAR *)xor_mask, (CHAR *)s + 64, 32);

#ifdef NU_WEBSERV_DEBUG
    printf("KEY = %s\n", req->ws_server->ws_master.ws_key);
#endif

    /* decrypt each string */

    ENC_Decrypt((CHAR *)req->ws_server->ws_master.ws_key, (CHAR *)xor_mask, 2);
    ENC_Decrypt((CHAR *)req->ws_server->ws_master.ws_key, (CHAR *)cypher_a, 2);
    ENC_Decrypt((CHAR *)req->ws_server->ws_master.ws_key, (CHAR *)cypher_b, 2);

    /* XOR our decrypted user and passwd with the 
     * decrypted salt
     */

    for(i=0; i<16; i++)
    {
        cypher_a[i] ^= xor_mask[i];
        cypher_b[i] ^= xor_mask[i];
    }

    cypher_a[16]=0;                                 /* make sure there is a null */
    cypher_b[16]=0;                                 /* in case we decrypt to garbage */

#ifdef NU_WEBSERV_DEBUG
    printf("string 1:%s\n",cypher_a);
    printf("string 2:%s\n",cypher_b);
#endif

    if(DES_Auth_Add_Entry((CHAR *)cypher_a,(CHAR *)cypher_b) != NU_SUCCESS)
    {
        /*
         * If the add entry fails then send a response. 
         * http://XXX.XXX.XXX.XXX/auserf.htm" 
         */
        strcpy(fail, "http://");
        strcat(fail, (CHAR *)NU_ITOA((INT)WS_Master_Server.ws_ip[0], temp, 10));
        strcat(fail, ".");
        strcat(fail, (CHAR *)NU_ITOA((INT)WS_Master_Server.ws_ip[1], temp, 10));
        strcat(fail, ".");
        strcat(fail, (CHAR *)NU_ITOA((INT)WS_Master_Server.ws_ip[2], temp, 10));
        strcat(fail, ".");
        strcat(fail, (CHAR *)NU_ITOA((INT)WS_Master_Server.ws_ip[3], temp, 10));
        strcat(fail, "/auserf.htm");
        
        WS_Write_To_Net(req, fail, strlen(fail), WS_FILETRNSFR);
    }
    else
    {  
        /* 
         * If successful then redirect the URL to 
         * http://XXX.XXX.XXX.XXX/addus.htm"
         */
        strcpy(success, "http://");
        strcat(success, (CHAR *)NU_ITOA((INT)WS_Master_Server.ws_ip[0], temp, 10));
        strcat(success, ".");
        strcat(success, (CHAR *)NU_ITOA((INT)WS_Master_Server.ws_ip[1], temp, 10));
        strcat(success, ".");
        strcat(success, (CHAR *)NU_ITOA((INT)WS_Master_Server.ws_ip[2], temp, 10));
        strcat(success, ".");
        strcat(success, (CHAR *)NU_ITOA((INT)WS_Master_Server.ws_ip[3], temp, 10));
        strcat(success, "/addus.htm");

        WS_Write_To_Net(req, success, strlen(success), WS_FILETRNSFR);           
    }

    return(WS_REQ_PROCEED);
}

/************************************************************************
*                                                                       
* FUNCTION                                                              
*                                                                       
*       DES_Auth_Del                                                         
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       Routine to Delete an Authentication entry from the Doubly link   
*       list.  It returns to the Java Applet an ip address to redirect   
*       the Browser to.                                                  
*                                                                       
* INPUTS                                                                
*                                                                       
*       *env                                                              
*       *req                                                              
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       NU_SUCCESS
*                                                                       
************************************************************************/
static INT DES_Auth_Del(WS_REQUEST *req)
{   
    CHAR            success[250];
    CHAR            fail[250];
    UINT8           cypher_a[17];
    UINT8           cypher_b[17];   
    UINT8           xor_mask[17];
    INT             i;
    CHAR            *s;
    CHAR            temp[10];

    UTL_Zero(success,250);
    UTL_Zero(fail,250);

    /* get the VALUE string from the POST request */
    s = HTTP_Token_Value_by_Name("VALUE", req);

#ifdef NU_WEBSERV_DEBUG
    printf("VALUE= %s\n",s);
#endif

    /* convert the user ( cypher_a)
     * and the passwd ( cypher_b)
     * and the mask ( xor_mask) 
     * to binary
     */ 

    HTTP_Packed_Hex_To_Bin((CHAR *)cypher_a, s, 32);
    HTTP_Packed_Hex_To_Bin((CHAR *)cypher_b, s + 32, 32);
    HTTP_Packed_Hex_To_Bin((CHAR *)xor_mask, s + 64, 32);

#ifdef NU_WEBSERV_DEBUG
    printf("KEY = %s\n", req->ws_server->ws_master.ws_key);
#endif

    /* decrypt each string */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -