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

📄 dlgchpasskeyfilewizard.c

📁 文件驱动加密,功能强大,可产生加密分区,支持AES,MD2,MD4,MD5MD2, MD4, MD5, RIPEMD-128, RIPEMD-160, SHA-1, SHA-224, SHA-256,
💻 C
📖 第 1 页 / 共 5 页
字号:
                break;
                }

            case PAGE_IDX_RNGMOUSEMOVEMENT:
                {
                _dlgChpassKeyfileWizard_ResizeUserRNG(hDlg, FALSE);
                break;
                }

            }

        resizing = FALSE;
        }


    DEBUGOUTGUI(DEBUGLEV_EXIT, (TEXT("dlgChpassKeyfileWizard_HandleMsg_WM_SIZE\n")));
    return TRUE;
}


// =========================================================================
void _dlgChpassKeyfileWizard_SecZeroParams()
{
    if (G_dlgChpassKeyfileWizard_ChpassKeyfileParams.SrcUserPassword != NULL)
        {
        SecZeroAndFreeMemory(
                    G_dlgChpassKeyfileWizard_ChpassKeyfileParams.SrcUserPassword,
                    strlen(G_dlgChpassKeyfileWizard_ChpassKeyfileParams.SrcUserPassword)
                   );
        G_dlgChpassKeyfileWizard_ChpassKeyfileParams.SrcUserPassword = NULL;
        }

    if (G_dlgChpassKeyfileWizard_ChpassKeyfileParams.DestUserPassword != NULL)
        {
        SecZeroAndFreeMemory(
                    G_dlgChpassKeyfileWizard_ChpassKeyfileParams.DestUserPassword,
                    strlen(G_dlgChpassKeyfileWizard_ChpassKeyfileParams.DestUserPassword)
                   );
        G_dlgChpassKeyfileWizard_ChpassKeyfileParams.DestUserPassword = NULL;
        }

    if (G_dlgChpassKeyfileWizard_ChpassKeyfileParams.DestUserPasswordConfirm != NULL)
        {
        SecZeroAndFreeMemory(
                    G_dlgChpassKeyfileWizard_ChpassKeyfileParams.DestUserPasswordConfirm,
                    strlen(G_dlgChpassKeyfileWizard_ChpassKeyfileParams.DestUserPasswordConfirm)
                   );
        G_dlgChpassKeyfileWizard_ChpassKeyfileParams.DestUserPasswordConfirm = NULL;
        }

    SecZeroMemory(
                  &G_dlgChpassKeyfileWizard_ChpassKeyfileParams, 
                  sizeof(G_dlgChpassKeyfileWizard_ChpassKeyfileParams)
                 );
}


// =========================================================================
// Pass this the HWND for the *main* dialog
BOOL _dlgChpassKeyfileWizard_QuerySiblings(HWND hDlg)
{
    BOOL retval = FALSE;

    DEBUGOUTGUI(DEBUGLEV_ENTER, (TEXT("_dlgChpassKeyfileWizard_QuerySiblings\n")));

    G_dlgChpassKeyfileWizard_ChpassKeyfileParams.ParamsOK = TRUE;

    if (PropSheet_QuerySiblings(hDlg, 0, 0) != 0)
        {
        DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("PropSheet_QuerySiblings returned non-zero; not proceeding with new volume\n")));
        // Do nothing; retval already set to FALSE
        }
    // Not clear why, but regardless of whether the dlgProc returns
    // TRUE/FALSE for the QuerySiblings call, the above always returns zero?!
    // Therefore, we use a kludge to get the *real* result...
    else if (G_dlgChpassKeyfileWizard_ChpassKeyfileParams.ParamsOK == FALSE)
        {
        DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("ParamsOK set to FALSE; not proceeding with new volume\n")));
        // Do nothing; retval already set to FALSE
        }
    else
        {
        retval = TRUE;
        }

    DEBUGOUTGUI(DEBUGLEV_EXIT, (TEXT("_dlgChpassKeyfileWizard_QuerySiblings\n")));
    return retval;
}


// =========================================================================
// Pass this the HWND for the *main* dialog
void _dlgChpassKeyfileWizard_UpdateLastPageGlobal(HWND hDlg)
{
    // Get the latest information entered by the user...
    _dlgChpassKeyfileWizard_QuerySiblings(hDlg);

    if (G_dlgChpassKeyfileWizard_ChpassKeyfileParams.SelectedRNG.UseUserInput)
        {
        G_dlgChpassKeyfileWizard_LastPageIdx = PAGE_IDX_RNGMOUSEMOVEMENT;
        }
    else
        {
        G_dlgChpassKeyfileWizard_LastPageIdx = PAGE_IDX_RNGSELECT;
        }

    // In case any of the navigation buttsons need changing...
    _dlgChpassKeyfileWizard_SetWizardButtons(
            _dlgChpassKeyfileWizard_GetCurrPageIdx(hDlg)
           );    
}


// =========================================================================
// Dialog OK'd; change password or create keyfile
BOOL CALLBACK dlgChpassKeyfileWizard_ChpassKeyfile(HWND hDlg)
{
    BOOL retval = FALSE;
    CDB_DETAILS CDBDetails;
    CDB_METADATA CDBMetaData;
    FREEOTFEBYTE randomPool[(CRITICAL_DATA_LENGTH / 8)];

    DEBUGOUTGUI(DEBUGLEV_ENTER, (TEXT("dlgChpassKeyfileWizard_ChpassKeyfile\n")));

    memset(
           &G_dlgChpassKeyfileWizard_ChpassKeyfileParams, 
           0,
           sizeof(G_dlgChpassKeyfileWizard_ChpassKeyfileParams)
          );
    G_dlgChpassKeyfileWizard_ChpassKeyfileParams.ParamsOK = TRUE;

    // Check the user's input is OK...
    if (!(dlgChpassKeyfileWizard_ValidateAll(GetParent(hDlg))))
        {
        DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("Can't validate all of user input successfully\n")));
        // retval already set to FALSE, just switch to the appropriate tab
        PropSheet_SetCurSel(
                            GetParent(hDlg), 
                            NULL, 
                            G_dlgChpassKeyfileWizard_ChpassKeyfileParams.ErrorPageIdx
                           );
        }
    else
        {
        HCURSOR csrHourglass;
        HCURSOR csrPrevious;

        csrHourglass = LoadCursor(NULL, IDC_WAIT);
        csrPrevious = SetCursor(csrHourglass);

        // Combine random data buffers as configured by the user...
        memset(randomPool, 0, sizeof(randomPool));
        if (G_dlgChpassKeyfileWizard_ChpassKeyfileParams.SelectedRNG.UseUserInput)
            {
            XORBlock(
                     randomPool,
                     G_dlgChpassKeyfileWizard_ChpassKeyfileParams.RandomPool_UserInput,
                     randomPool,
                     (G_dlgChpassKeyfileWizard_ChpassKeyfileParams.RandomPoolFilled_UserInput / 8)
                    );
            }

        if (G_dlgChpassKeyfileWizard_ChpassKeyfileParams.SelectedRNG.UseMSCryptoAPI)
            {
            XORBlock(
                     randomPool,
                     G_dlgChpassKeyfileWizard_ChpassKeyfileParams.RandomPool_MSCryptoAPI,
                     randomPool,
                     (G_dlgChpassKeyfileWizard_ChpassKeyfileParams.RandomPoolFilled_MSCryptoAPI / 8)
                    );
            }

        retval = FALSE;
        if (G_dlgChpassKeyfileWizard_DlgMode == DLGMODE_NEWKEYFILE)
            {
            retval = driver_CreateKeyfile(
                G_dlgChpassKeyfileWizard_ChpassKeyfileParams.SrcFilename,
                G_dlgChpassKeyfileWizard_ChpassKeyfileParams.SrcOffset,
                G_dlgChpassKeyfileWizard_ChpassKeyfileParams.SrcUserPassword,
                G_dlgChpassKeyfileWizard_ChpassKeyfileParams.SrcSaltLength,
                G_dlgChpassKeyfileWizard_ChpassKeyfileParams.SrcKeyIterations,

                G_dlgChpassKeyfileWizard_ChpassKeyfileParams.DestFilename,
                G_dlgChpassKeyfileWizard_ChpassKeyfileParams.DestUserPassword,
                G_dlgChpassKeyfileWizard_ChpassKeyfileParams.DestSaltLength,
                G_dlgChpassKeyfileWizard_ChpassKeyfileParams.DestKeyIterations,

                randomPool
               );

            }
        else
            {
            retval = driver_ChangeDetails(
                G_dlgChpassKeyfileWizard_ChpassKeyfileParams.SrcFilename,
                G_dlgChpassKeyfileWizard_ChpassKeyfileParams.SrcOffset,
                G_dlgChpassKeyfileWizard_ChpassKeyfileParams.SrcUserPassword,
                G_dlgChpassKeyfileWizard_ChpassKeyfileParams.SrcSaltLength,
                G_dlgChpassKeyfileWizard_ChpassKeyfileParams.SrcKeyIterations,

                G_dlgChpassKeyfileWizard_ChpassKeyfileParams.DestUserPassword,
                G_dlgChpassKeyfileWizard_ChpassKeyfileParams.DestSaltLength,
                G_dlgChpassKeyfileWizard_ChpassKeyfileParams.DestKeyIterations,

                randomPool
               );

            }

        SetCursor(csrPrevious);
        }

    // Cleardown sensitive information
    _dlgChpassKeyfileWizard_SecZeroParams();
    SecZeroMemory(&CDBDetails, sizeof(CDBDetails));
    SecZeroMemory(&CDBMetaData, sizeof(CDBMetaData));
    SecZeroMemory(randomPool, sizeof(randomPool));

    DEBUGOUTGUI(DEBUGLEV_EXIT, (TEXT("dlgChpassKeyfileWizard_ChpassKeyfile\n")));
    return retval;
}


// =========================================================================
void _dlgChpassKeyfileWizard_EnableDisableControls(HWND hDlg)
{
    BOOL enableCtrl;

    enableCtrl = (IsDlgButtonChecked(
                                     hDlg, 
                                     IDC_RADIO_CDBINKEYFILE
                                    ) == BST_CHECKED);

    SetControlEnabled(hDlg, IDC_STATIC_KEYFILE, enableCtrl);
    SetControlEnabled(hDlg, IDC_EDIT_KEYFILE, enableCtrl);
    SetControlEnabled(hDlg, IDC_BUTTON_BROWSEKEYFILE, enableCtrl);

}


// =========================================================================
// Navigate forwards/backwards in the wizard
// PageDirection - Set to +1 to go onto the next page; -1 to go back
void CALLBACK _dlgChpassKeyfileWizard_PageChange(
    HWND hDlg, 
    int PageDirection
)
{
    int currPage;
    int newPage;
    BOOL identifiedNewPage;


    currPage = _dlgChpassKeyfileWizard_GetPageIdxOfPage(PropSheet_GetCurrentPageHwnd(GetParent(hDlg)));
    newPage = currPage;

    // Get the latest information entered by the user...
    _dlgChpassKeyfileWizard_QuerySiblings(hDlg);

    identifiedNewPage = FALSE;
    while (!(identifiedNewPage))
        {
        if (PageDirection < 0) 
            {
            newPage = max((newPage - 1), 0);
            }
        else if (PageDirection > 0)
            {
            // Note: Any error message will have been displayed to user
            //       during validation
            if (dlgChpassKeyfileWizard_ValidatePage(PropSheet_GetCurrentPageHwnd(GetParent(hDlg))))
                {
                // -1 here as NEWVOLWIZARD_STEPS is the total number; not
                // the largest page indexe
                newPage = min((newPage + 1), (CHPASS_KEYFILEWIZARD_STEPS - 1));
                }
            }

        // Check if the new page is skipped
        identifiedNewPage = TRUE;
        if (newPage == PAGE_IDX_RNGMOUSEMOVEMENT)
            {
            // Skip mouse RNG page if user doesn't want to use it
            identifiedNewPage = G_dlgChpassKeyfileWizard_ChpassKeyfileParams.SelectedRNG.UseUserInput;
            }
        else if (newPage == PAGE_IDX_DESTFILENAME)
            {
            // Skip destination filename if just changing password, otherwise
            // allow this page
            identifiedNewPage = (G_dlgChpassKeyfileWizard_DlgMode == DLGMODE_NEWKEYFILE);
            }

        }

    if (currPage != newPage)
        {
        PropSheet_SetCurSel(
                            GetParent(hDlg), 
                            NULL, 
                            newPage
                           );
                
        if (newPage == PAGE_IDX_RNGMOUSEMOVEMENT)
            {
            // Identify if the user needs instructions...
            if (
                (G_dlgChpassKeyfileWizard_ChpassKeyfileParams.RandomPoolFilled_UserInput / 8) <
                sizeof(G_dlgChpassKeyfileWizard_ChpassKeyfileParams.RandomPool_UserInput)
               )
                {
                MsgInfoString(
                              hDlg,
                              G_hInstance,
                              IDS_STRING_INSTR_RNGMOUSEMOVEMENT
                             );
                }
            }

        }

    // It would make more sense for this to be called *after* all the
    // WM_INITDIALOGs
    _dlgChpassKeyfileWizard_UpdateLastPageGlobal(GetParent(hDlg));
}


// =========================================================================
BOOL CALLBACK dlgChpassKeyfileWizard_HandleMsg_WM_COMMAND(HWND hDlg, WPARAM wParam)
{
    BOOL retval = FALSE;
    int ctrlID;

    DEBUGOUTGUI(DEBUGLEV_ENTER, (TEXT("dlgChpassKeyfileWizard_HandleMsg_WM_COMMAND\n")));
    DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("Command: %d\n"), LOWORD(wParam)));
            
    ctrlID = LOWORD(wParam);

    switch(ctrlID)
        {
        case IDOK:
            {
            // IMPORTANT: EndDialog *not* called for property sheet dialog
            // We just forward the msg received by the *page* to the owning
            // parent; the property sheet dialog
            PropSheet_PressButton(GetParent(hDlg), PSBTN_OK);
            retval = TRUE;
            break;
            }

        case IDCANCEL:
            {
            // IMPORTANT: EndDialog *not* called for property sheet dialog
            // We just forward the msg received by the *page* to the owning
            // parent; the property sheet dialog
            PropSheet_PressButton(GetParent(hDlg), PSBTN_CANCEL);
        

⌨️ 快捷键说明

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