LRESULT CPasskeyEntry::OnInsertBuffer(WPARAM, LPARAM) { // Update the variables UpdateData(TRUE); // Get the buffer CSecString vkbuffer = m_pVKeyBoardDlg->GetPassphrase(); // Find the selected characters - if any int nStartChar, nEndChar; m_pctlPasskey->GetSel(nStartChar, nEndChar); // If any characters selected - delete them if (nStartChar != nEndChar) m_passkey.Delete(nStartChar, nEndChar - nStartChar); // Insert the buffer m_passkey.Insert(nStartChar, vkbuffer); // Update the dialog UpdateData(FALSE); // Put cursor at end of inserted text m_pctlPasskey->SetSel(nStartChar + vkbuffer.GetLength(), nStartChar + vkbuffer.GetLength()); return 0L; }
LRESULT CPasskeySetup::OnInsertBuffer(WPARAM, LPARAM) { // Update the variables UpdateData(TRUE); // Get the buffer CSecString vkbuffer = m_pVKeyBoardDlg->GetPassphrase(); CSecEditExtn *m_pSecCtl(NULL); CSecString *m_pSecString; switch (m_LastFocus) { case IDC_PASSKEY: m_pSecCtl = m_pctlPasskey; m_pSecString = &m_passkey; break; case IDC_VERIFY: m_pSecCtl = m_pctlVerify; m_pSecString = &m_verify; break; default: // Error! ASSERT(0); return 0L; } // Find the selected characters - if any int nStartChar, nEndChar; m_pSecCtl->GetSel(nStartChar, nEndChar); // If any characters selected - delete them if (nStartChar != nEndChar) m_pSecString->Delete(nStartChar, nEndChar - nStartChar); // Insert the buffer m_pSecString->Insert(nStartChar, vkbuffer); // Update the dialog UpdateData(FALSE); // Put cursor at end of inserted text m_pSecCtl->SetSel(nStartChar + vkbuffer.GetLength(), nStartChar + vkbuffer.GetLength()); // Make us on top SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE); return 0L; }
void CYubiMixin::yubiRequestHMACSha1(const CSecString &challenge) { if (m_pending) { // no-op if a request's already in the air } else { CSingleLock singeLock(&m_mutex); singeLock.Lock(); // open key // if zero or >1 key, we'll fail if (m_yk.openKey() != YKLIB_OK) { return; } // Prepare the HMAC-SHA1 challenge here BYTE chalBuf[SHA1_MAX_BLOCK_SIZE]; BYTE chalLength = BYTE(challenge.GetLength()*sizeof(TCHAR)); memset(chalBuf, 0, SHA1_MAX_BLOCK_SIZE); if (chalLength > SHA1_MAX_BLOCK_SIZE) chalLength = SHA1_MAX_BLOCK_SIZE; memcpy(chalBuf, challenge, chalLength); // Initiate HMAC-SHA1 operation now if (m_yk.writeChallengeBegin(YKLIB_SECOND_SLOT, YKLIB_CHAL_HMAC, chalBuf, chalLength) == YKLIB_OK) { m_pending = true; yubiShowChallengeSent(); // request's in the air, setup GUI to wait for reply } else { TRACE(_T("m_yk.writeChallengeBegin() failed")); } trashMemory(chalBuf, chalLength); } }
void CCreateShortcutDlg::OnOK() { if (UpdateData(TRUE) == FALSE) return; CGeneralMsgBox gmb; m_group.EmptyIfOnlyWhiteSpace(); m_title.EmptyIfOnlyWhiteSpace(); m_username.EmptyIfOnlyWhiteSpace(); //Check that data is valid if (m_title.IsEmpty()) { gmb.AfxMessageBox(IDS_MUSTHAVETITLE); ((CEdit*)GetDlgItem(IDC_TITLE))->SetFocus(); return; } if (!m_group.IsEmpty() && m_group[0] == '.') { gmb.AfxMessageBox(IDS_DOTINVALID); ((CEdit*)GetDlgItem(IDC_GROUP))->SetFocus(); return; } // If there is a matching entry in our list, tell the user to try again. if (GetMainDlg()->Find(m_group, m_title, m_username) != app.GetMainDlg()->End()) { CSecString temp; if (m_group.IsEmpty()) temp.Format(IDS_ENTRYEXISTS2, m_title, m_username); else temp.Format(IDS_ENTRYEXISTS, m_group, m_title, m_username); gmb.AfxMessageBox(temp); ((CEdit*)GetDlgItem(IDC_TITLE))->SetSel(MAKEWORD(-1, 0)); ((CEdit*)GetDlgItem(IDC_TITLE))->SetFocus(); return; } //End check CPWDialog::OnOK(); }
void CSecEditExtn::SetSecureText(const CSecString &str) { m_pImpl->m_field.Set(str, m_pImpl->m_bf); if (::IsWindow(m_hWnd)) { if (!m_secure) { SetWindowText(str); } else { CString blanks; for (int i = 0; i < str.GetLength(); i++) blanks += FILLER; SetWindowText(blanks); } } }
BOOL CAddEdit_Basic::OnApply() { if (M_uicaller() == IDS_VIEWENTRY || M_protected() != 0) return FALSE; //CAddEdit_PropertyPage::OnApply(); CWnd *pFocus(NULL); CGeneralMsgBox gmb; ItemListIter listindex; bool brc, b_msg_issued; UpdateData(TRUE); M_group().EmptyIfOnlyWhiteSpace(); M_title().EmptyIfOnlyWhiteSpace(); M_username().EmptyIfOnlyWhiteSpace(); M_URL().EmptyIfOnlyWhiteSpace(); M_email().EmptyIfOnlyWhiteSpace(); M_symbols().EmptyIfOnlyWhiteSpace(); m_notes.EmptyIfOnlyWhiteSpace(); if (m_password.IsOnlyWhiteSpace()) { m_password.Empty(); if (m_isPWHidden) m_password2.Empty(); } if (!m_isPWHidden || m_password != HIDDEN_PASSWORD) M_realpassword() = m_password; if (!m_isNotesHidden) M_realnotes() = m_notes; UpdateData(FALSE); //Check that data is valid if (M_title().IsEmpty()) { gmb.AfxMessageBox(IDS_MUSTHAVETITLE); pFocus = &m_ex_title; goto error; } if (M_realpassword().IsEmpty()) { gmb.AfxMessageBox(IDS_MUSTHAVEPASSWORD); pFocus = &m_ex_password; goto error; } if (!M_group().IsEmpty() && M_group()[0] == '.') { gmb.AfxMessageBox(IDS_DOTINVALID); pFocus = &m_ex_group; goto error; } if (m_isPWHidden && (m_password.Compare(m_password2) != 0)) { gmb.AfxMessageBox(IDS_PASSWORDSNOTMATCH); UpdateData(FALSE); pFocus = &m_ex_password; goto error; } // If there is a matching entry in our list, tell the user to try again. listindex = GetMainDlg()->Find(M_group(), M_title(), M_username()); if (M_uicaller() == IDS_ADDENTRY) { // Add entry if (listindex != GetMainDlg()->End()) { CSecString temp; if (M_group().IsEmpty()) if (M_username().IsEmpty()) temp.Format(IDS_ENTRYEXISTS3, M_title()); else temp.Format(IDS_ENTRYEXISTS2, M_title(), M_username()); else if (M_username().IsEmpty()) temp.Format(IDS_ENTRYEXISTS1, M_group(), M_title()); else temp.Format(IDS_ENTRYEXISTS, M_group(), M_title(), M_username()); gmb.AfxMessageBox(temp); pFocus = &m_ex_title; goto error; } } else { // Edit entry if (listindex != GetMainDlg()->End()) { const CItemData &listItem = GetMainDlg()->GetEntryAt(listindex); if (listItem.GetUUID() != M_pci()->GetUUID()) { CSecString temp; temp.Format(IDS_ENTRYEXISTS, M_group(), M_title(), M_username()); gmb.AfxMessageBox(temp); pFocus = &m_ex_title; goto error; } } } brc = CheckNewPassword(M_group(), M_title(), M_username(), M_realpassword(), M_uicaller() != IDS_ADDENTRY, CItemData::ET_ALIAS, M_base_uuid(), M_ibasedata(), b_msg_issued); if (!brc && M_ibasedata() != 0) { if (!b_msg_issued) gmb.AfxMessageBox(IDS_MUSTHAVETARGET, MB_OK); UpdateData(FALSE); pFocus = &m_ex_password; goto error; } //End check return CAddEdit_PropertyPage::OnApply(); error: // Are we the current page, if not activate this page if (m_ae_psh->GetActivePage() != (CAddEdit_PropertyPage *)this) m_ae_psh->SetActivePage(this); if (pFocus != NULL) pFocus->SetFocus(); if (pFocus == &m_ex_title) m_ex_title.SetSel(MAKEWORD(-1, 0)); return FALSE; }
void CInfoDisplay::OnPaint() { CPaintDC dc(this); // device context for painting CFont *pFont = GetFont(); dc.SelectObject(pFont); // First, we compute the maximum line width, and set the rectangle wide enough to // hold this. Then we use DrawText/DT_CALCRECT to compute the height CSecString text; GetWindowText(text); CSize box = CSize(0, 0); // First replace all "\r\n" by"\n" then any remaining "\r" to "\n" text.Replace(L"\r\n", L"\n"); text.Replace(L'\r', L'\n'); TEXTMETRIC tm; dc.GetTextMetrics(&tm); int inf; // inflation factor { /* compute box size */ CSecString s = text; while(TRUE) { /* scan string */ CSecString line; int p = s.Find(L"\n"); if (p < 0) line = s; else { /* one line */ line = s.Left(p); s = s.Mid(p + 1); } /* one line */ CSize sz = dc.GetTextExtent(line); box.cx = max(box.cx, sz.cx); box.cy += tm.tmHeight + tm.tmInternalLeading; if (p < 0) break; } /* scan string */ // Having computed the width, allow for the borders and extra space for margins inf = 4 * ::GetSystemMetrics(SM_CXBORDER); box.cx += 2 * inf; box.cy += 2 * inf; CRect rc(0, 0, 0, 0); rc.right = box.cx; rc.bottom = box.cy; bool bMoveWindow(false); int x = 0, y = 0; // Get area of potentially multiple monitors! - defined in DboxMain.cpp as extern // if use_current_monitor was set in constructor, we'll check only screen where mouse is located HRGN hrgn; POINT mouse_pt; GetCursorPos(&mouse_pt); if (m_use_current_monitor){ MONITORINFO mi; mi.cbSize = sizeof(mi); GetMonitorInfo(MonitorFromPoint(mouse_pt, MONITOR_DEFAULTTONEAREST), &mi); hrgn = CreateRectRgn(mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom); } else hrgn = GetWorkAreaRegion(); if (hrgn != NULL) { // Test that all tip window is visible in the desktop rectangle. CRect rs(rc); // Convert to screen co-ordinates ClientToScreen(rs); if (!PtInRegion(hrgn, rs.right, rs.bottom) || !PtInRegion(hrgn, rs.left, rs.top)) { // Not in region - move Window RECT hr; if (GetRgnBox(hrgn, &hr)){ if (rs.right > hr.right) { if (mouse_pt.x - rs.Width() - 1 >= hr.left) // can flip left? x = mouse_pt.x - rs.Width() - 1; else if (hr.right - rs.Width() >= hr.left) // can shift left and fit width? x = hr.right - rs.Width(); else // press to left border x = hr.left; } else // no need to move x = rs.left; if (rs.bottom > hr.bottom) { if (mouse_pt.y - rs.Height() - 1 >= hr.top) // can flip up? y = mouse_pt.y - rs.Height() - 1; else if (hr.bottom - rs.Height() >= hr.top) // can shift up and fit height? y = hr.bottom - rs.Height(); else // press to top border y = hr.top; } else // no need to move y = rs.top; bMoveWindow = true; // Check that mouse pointer isn't on infowindow: when it is, window isn't displayed (treated somewhere as focus/mouse move?) if ((mouse_pt.x >= x) && (mouse_pt.x <= x + rs.Width()) && (mouse_pt.y >= y) && (mouse_pt.y <= y + rs.Height())) { if (mouse_pt.y == y) y++; else if (mouse_pt.y == y + rs.Height()) y--; else if (mouse_pt.x == x) x++; else if (mouse_pt.x == x + rs.Width()) x--; else if ((mouse_pt.y >= y) && (mouse_pt.y <= y + rs.Height())) // show top part of the message and trim/split bottom y = mouse_pt.y + 1; } } } DeleteObject(hrgn); } // Set the window size SetWindowPos(NULL, x, y, rc.Width(), rc.Height(), (bMoveWindow ? 0: SWP_NOMOVE) | SWP_NOZORDER | SWP_NOACTIVATE); } /* compute box size */ CRect r; GetClientRect(&r); r.InflateRect(-inf, -inf); dc.SetBkMode(TRANSPARENT); CSecString s = text; int y = r.top; while(TRUE) { /* scan string */ CSecString line; int p = s.Find(L"\n"); if (p < 0) { line = s; } else { /* one line */ line = s.Left(p); s = s.Mid(p + 1); } /* one line */ dc.TextOut(r.left, y, line); y += tm.tmHeight + tm.tmInternalLeading; if (p < 0) break; } /* scan string */ // Do not call CWnd::OnPaint() for painting messages }
void CEditShortcutDlg::OnOK() { ItemListIter listindex; if (m_Edit_IsReadOnly) { CPWDialog::OnOK(); return; } UpdateData(TRUE); m_group.EmptyIfOnlyWhiteSpace(); m_title.EmptyIfOnlyWhiteSpace(); m_username.EmptyIfOnlyWhiteSpace(); m_bIsModified |= (m_group != m_pci->GetGroup() || m_title != m_pci->GetTitle() || m_username != m_pci->GetUser()); //Check that data is valid if (m_title.IsEmpty()) { CGeneralMsgBox gmb; gmb.AfxMessageBox(IDS_MUSTHAVETITLE); ((CEdit*)GetDlgItem(IDC_TITLE))->SetFocus(); goto dont_close; } if (!m_group.IsEmpty() && m_group[0] == '.') { CGeneralMsgBox gmb; gmb.AfxMessageBox(IDS_DOTINVALID); ((CEdit*)GetDlgItem(IDC_GROUP))->SetFocus(); goto dont_close; } listindex = GetMainDlg()->Find(m_group, m_title, m_username); /* * If there is a matching entry in our list, and that * entry is not the same one we started editing, tell the * user to try again. */ if (listindex != GetMainDlg()->End()) { const CItemData &listItem = GetMainDlg()->GetEntryAt(listindex); bool notSame = listItem.GetUUID() != m_pci->GetUUID(); if (notSame) { CGeneralMsgBox gmb; CSecString temp; temp.Format(IDS_ENTRYEXISTS, m_group, m_title, m_username); gmb.AfxMessageBox(temp); ((CEdit*)GetDlgItem(IDC_TITLE))->SetSel(MAKEWORD(-1, 0)); ((CEdit*)GetDlgItem(IDC_TITLE))->SetFocus(); goto dont_close; } } //End check // Everything OK, update fields m_pci->SetGroup(m_group); m_pci->SetTitle(m_title); m_pci->SetUser(m_username.IsEmpty() ? m_defusername : m_username); time_t t; time(&t); if (m_bIsModified) m_pci->SetRMTime(t); CPWDialog::OnOK(); return; // If we don't close, then update controls, as some of the fields // may have been modified (e.g., spaces removed). dont_close: UpdateData(FALSE); }