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

📄 cnewuserpages.cpp

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	
	mQualityBar.SetRange(0, 100);
	mQualityBar.SetPos(0);

	if (mPInfo->enforcePassFlags & kEnforcePassMinQuality)
	{
		mMinQualityBar.SetRange(0, 100);
		mMinQualityBar.SetPos(mPInfo->minPassQuality);
	}
	else
	{
		mMinQualityBar.ShowWindow(SW_HIDE);
		mMinQualityText.ShowWindow(SW_HIDE);
	}

	CreateCapsLockBar();
}

void 
CNewUserAskPassPage::InitQualityPrefs()
{
	mPInfo->enforcePassFlags = 0;
	mPInfo->badPassFlags = 0;

	// We warn about min pass length by default, but not quality.
	mPInfo->minPassLength = PGPdiskUIPriv::kDiskSugMinPassLength;
	mPInfo->minPassQuality = 0;

	if(PGPclEnterprise())
	{
		// Minimum passphrase length and quality.
		CPGPclPrefs	clPrefs(mPInfo->pContext->PGPclPrefs());

		if (clPrefs.GetBoolean(kPGPPrefEnforceMinChars))
		{
			mPInfo->enforcePassFlags |= kEnforcePassMinLength;
			mPInfo->minPassLength = clPrefs.GetNumber(kPGPPrefMinChars);
		}

		if (clPrefs.GetBoolean(kPGPPrefEnforceMinQuality))
		{
			mPInfo->enforcePassFlags |= kEnforcePassMinQuality;
			mPInfo->minPassQuality = clPrefs.GetNumber(kPGPPrefMinQuality);
		}
	}
}

void 
CNewUserAskPassPage::UpdatePassphraseFlags()
{
	mPInfo->badPassFlags = 0;

	// Passphrases must match.
	if (mPassphraseEdit.Contents() != mConfirmEdit.Contents())
		mPInfo->badPassFlags |= kBadPassConfirm;

	// Check minimum length.
	if (mPassphraseEdit.ContentsLength() < mPInfo->minPassLength)
		mPInfo->badPassFlags |= kBadPassMinLength;

	// Check minimum quality.
	if (mPInfo->enforcePassFlags & kEnforcePassMinQuality)
	{
		if (static_cast<PGPUInt32>(mQualityBar.GetPos()) < 
			mPInfo->minPassQuality)
		{
			mPInfo->badPassFlags |= kBadPassMinQuality;
		}
	}
}

void 
CNewUserAskPassPage::UpdatePassphraseQuality()
{
	CSecureArray<char>	passphrase;
	mPassphraseEdit.Contents().Extract(passphrase);

	PGPUInt32	quality	= pgpEstimatePassphraseQuality(passphrase.Get());
	mQualityBar.SetPos(quality);
}

void 
CNewUserAskPassPage::SetCapsLockMessageState()
{
	if (GetKeyState(VK_CAPITAL) & 1)
		WarnCapsLock(TRUE);
	else
		WarnCapsLock(FALSE);
}

void 
CNewUserAskPassPage::WarnCapsLock(PGPBoolean warn)
{
	PGPInt32	curIndex	= mCapsLockBar.GetIndexOfId(kCapsLockStringId);

	if (warn && (curIndex == -1))
	{
		mCapsLockBar.AddString(0, UCommonStrings::Get(
			UCommonStrings::kWarnCapsLockDown), kCapsLockStringId);
		mCapsLockBar.ResizeRedraw();
	}
	else if (!warn && (curIndex != -1))
	{
		mCapsLockBar.RemoveString(curIndex);
		mCapsLockBar.ResizeRedraw();
	}
}

void 
CNewUserAskPassPage::OnHideTypeCheck()
{
	PGPBoolean	hideTyping	= (mHideTypingCheck.GetCheck() == BST_CHECKED);

	mPassphraseEdit.SetHideTypingPref(hideTyping);
	mConfirmEdit.SetHideTypingPref(hideTyping);

	mIHadFocus->SetFocus();
}

BOOL 
CNewUserAskPassPage::OnCommand(
	PGPUInt16	notifyCode, 
	PGPUInt16	itemId, 
	HWND		ctrl)
{
	switch (notifyCode)
	{
	case BN_CLICKED:
		switch (itemId)
		{
		case IDC_HIDETYPE_CHECK:
			OnHideTypeCheck();
			return TRUE;
		}
		break;

	case EN_CHANGE:
		UpdatePassphraseQuality();
		break;

	case EN_KILLFOCUS:
		switch (itemId)
		{
		case IDC_PASSPHRASE_EDIT:
			mIHadFocus = &mPassphraseEdit;
			break;

		case IDC_CONFIRM_EDIT:
			mIHadFocus = &mConfirmEdit;
			break;
		}
		break;

	case EN_SETFOCUS:
		SetCapsLockMessageState();
		break;
	}

	return CPGPdiskPage::OnCommand(notifyCode, itemId, ctrl);
}

BOOL 
CNewUserAskPassPage::OnInitDialog(HWND focusCtrl)
{
	CPGPdiskPage::OnInitDialog(focusCtrl);

	// Attach controls.
	mHideTypingCheck.Subclass(GetDlgItem(IDC_HIDETYPE_CHECK));
	mMinQualityBar.Subclass(GetDlgItem(IDC_MINQUALITY_BAR));
	mQualityBar.Subclass(GetDlgItem(IDC_QUALITY_BAR));
	mPassphraseEdit.Subclass(GetDlgItem(IDC_PASSPHRASE_EDIT),mPInfo->pContext->PGPContext());
	mConfirmEdit.Subclass(GetDlgItem(IDC_CONFIRM_EDIT),mPInfo->pContext->PGPContext());
	mMinQualityText.Subclass(GetDlgItem(IDC_MINQUALITY_CAPTION));
	mPhraseLengthText.Subclass(GetDlgItem(IDC_PHRASELENGTH_TEXT));

	// Initialize page.
	InitQualityPrefs();
	InitControls();
	InitDialogText();

	return TRUE;
}

void 
CNewUserAskPassPage::OnKeyUp(PGPUInt32 vKey, PGPUInt32 keyData)
{
	SetCapsLockMessageState();
	CPGPdiskPage::OnKeyUp(vKey, keyData);
}

PGPInt32 
CNewUserAskPassPage::OnPsnSetActive()
{
	PGPInt32	result	= CPGPdiskPage::OnPsnSetActive();

	if (result != 0)
		return result;

	if (mPInfo->userChosePub)
		return -1;

	SetWizButtons(PSWIZB_BACK | PSWIZB_NEXT);
	SetCapsLockMessageState();

	mConfirmEdit.ClearContents();
	mPassphraseEdit.ClearContents();

	return 0;
}

PGPInt32 
CNewUserAskPassPage::OnPsnWizNext()
{
	PGPInt32	result	= CPGPdiskPage::OnPsnWizNext();

	if (result != 0)
		return result;

	if (mPassphraseEdit.Contents().Length() == 0)
	{
		using namespace UCommonStrings;

		CMessageBox	messageBox;
		messageBox.Display(Get(kTellPassphraseEmpty), mPInfo->warnDlgTitle, 
			Handle());

		mPassphraseEdit.SetFocus();

		result = -1;
	}
	else
	{
		mPInfo->securePass = mPassphraseEdit.Contents();
		UpdatePassphraseFlags();

		if (mPInfo->badPassFlags == 0)
			mPInfo->isFinished = TRUE;
	}

	return result;
}

PGPUInt32 
CNewUserAskPassPage::OnSecureEditEvent(HWND view, PGPUInt32 event)
{
	switch (event)
	{
	case CSecureRichEdit::kContentsChangedEvent:
		UpdatePassphraseQuality();
		break;

	case CSecureRichEdit::kSawCapsLockKeyEvent:
		SetCapsLockMessageState();
		break;

	case CSecureRichEdit::kSawReturnKeyEvent:
		PressButton(PSBTN_NEXT);
		break;
	}

	return TRUE;
}

PGPBoolean 
CNewUserAskPassPage::PreProcess(const CMessage& msg, LRESULT& result)
{
	if (msg.Message() == CSecureRichEdit::WM_SECUREEDIT_EVENT)
	{
		result = OnSecureEditEvent(reinterpret_cast<HWND>(msg.WParam()), 
			msg.LParam());
		return TRUE;
	}

	return FALSE;
}


// Class CNewUserAskPubKeyPage member functions

void 
CNewUserAskPubKeyPage::InitPublicKeysView()
{
	// Initialize the keys view.
	CPGPclPrefs	clPrefs(mPInfo->pContext->PGPclPrefs());

	mPubKeysView.Initialize(mPInfo->pContext, mPInfo->singleSelect, 
		clPrefs.GetBoolean(kPGPPrefMarginalIsInvalid), 
		clPrefs.GetBoolean(kPGPPrefDisplayMarginalValidity));

	// Add keys to choose.
	CPGPKeyList	keyList(mPInfo->keysToChoose, kPGPKeyOrdering_Any);
	CPGPKeyIter	keyIter(keyList);
	CPGPKey		key;

	while (keyIter.Next(key))
	{
		CPGPKey	subKey;
		if (key.GetKeyForUsage(subKey))
			mPubKeysView.AddKey(key, subKey);
	}

	mPubKeysView.SortOnColumn(0);

	// Select default key.
	PGPInt32	index	= -1;
	
	if (mPInfo->defKeyPrefExists && mPInfo->defKeySeen)
		index = mPubKeysView.FindKeyIDIndex(mPInfo->defKeyID);

	if (index == -1)
		index = 0;

	mPubKeysView.SelectIndex(index);
	mPubKeysView.EnsureVisable(index, FALSE);
}

BOOL 
CNewUserAskPubKeyPage::OnInitDialog(HWND focusCtrl)
{
	CPGPdiskPage::OnInitDialog(focusCtrl);

	mPubKeysView.Subclass(GetDlgItem(IDC_KEYS_VIEW));
	InitPublicKeysView();

	return TRUE;
}

PGPUInt32 
CNewUserAskPubKeyPage::OnNotify(PGPUInt16 ctrlId, LPNMHDR pNMHDR)
{
	switch (pNMHDR->code)
	{
	case NM_DBLCLK:
	{
		NMITEMACTIVATE	*pNMIA	= reinterpret_cast<NMITEMACTIVATE *>(pNMHDR);

		if (mPubKeysView.GetSelectedCount() > 0)
			PressButton(PSBTN_NEXT);
	}
	break;

	default:
		return CPGPdiskPage::OnNotify(ctrlId, pNMHDR);
	}

	return 0;
}

PGPInt32 
CNewUserAskPubKeyPage::OnPsnSetActive()
{
	PGPInt32	result	= CPGPdiskPage::OnPsnSetActive();

	if (result != 0)
		return result;

	if (!mPInfo->userChosePub)
		return -1;

	if (mPInfo->autoUseDefKey)
	{
		// default key was attached earlier
		mPInfo->isFinished = TRUE;
		return -1;
	}

	SetWizButtons(PSWIZB_BACK | PSWIZB_NEXT);

	return 0;
}

PGPInt32 
CNewUserAskPubKeyPage::OnPsnWizNext()
{
	PGPInt32	result	= CPGPdiskPage::OnPsnWizNext();

	if (result != 0)
		return result;

	// Get the key the user selected.
	CArray<CPublicKeysView::PubKeyItem>	items;
	PGPUInt32							numItems;

	mPubKeysView.GetSelectedItems(items, numItems);

	if (numItems == 0)
	{
		using namespace UCommonStrings;

		CMessageBox	messageBox;
		messageBox.Display(Get(kTellNoPubKeySelected), mPInfo->warnDlgTitle, 
			Handle());

		result = -1;
	}
	else if (numItems > 100)
	{
		CMessageBox	messageBox;
		messageBox.Display("Cannot select more than 100 keys at a time", 
			mPInfo->warnDlgTitle, 
			Handle());

//		pgpAssert(FALSE);	// should be single-selection control
		result = -1;
	}
	else
	{
		PGPUInt32 i;

		mPInfo->uNumPubKeys=numItems;

		for(i=0;i<mPInfo->uNumPubKeys;i++)
		{
			mPInfo->pgpKey[i].Attach(items[i].key);
		}
		mPInfo->isFinished = TRUE;
	}

	return result;
}


// Class CNewUserPages member functions

CNewUserPages::CNewUserPages() : 

	mIsCreated(FALSE), mPInfo(new PagesInfo), mPAskChoicePage(NULL), 
		mPAskPassPage(NULL), mPBadPassPage(NULL), mPAskPubKeyPage(NULL)
{
}

CNewUserPages::~CNewUserPages()
{
	try
	{
		Clear();
		delete mPInfo;
	}
	catch (CComboError&) { }
}

CPGPdiskPage * 
CNewUserPages::GetAskChoicePage()
{
	return mPAskChoicePage;
}

CPGPdiskPage * 
CNewUserPages::GetAskPassPage()
{
	return mPAskPassPage;
}

CPGPdiskPage * 
CNewUserPages::GetBadPassPage()
{
	return mPBadPassPage;
}

CPGPdiskPage * 
CNewUserPages::GetAskPubKeyPage()
{
	return mPAskPubKeyPage;
}

void 
CNewUserPages::Create(
	const CPGPdiskContext	*pContext, 
	const CPGPdiskUserSet	*pDiskUsers, 
	const char				*title, 
	const char				*warnDlgTitle,
	PGPBoolean				singleSelect,
	PGPBoolean				isForAdminUser, 
	PGPBoolean				ignoreDiskADK)
{
	pgpAssert(!IsCreated());
	pgpAssertAddrValid(pContext, CPGPdiskContext);
	pgpAssertAddrValid(pDiskUsers, CPGPdiskUserSet);
	pgpAssertStrValid(title);
	pgpAssertStrValid(warnDlgTitle);

	Clear();

	try
	{
		mPInfo->isFinished		= FALSE;
		mPInfo->pContext		= pContext;
		mPInfo->pDiskUsers		= pDiskUsers;
		mPInfo->isForAdminUser	= isForAdminUser;
		mPInfo->warnDlgTitle	= warnDlgTitle;
		mPInfo->uNumPubKeys		= 0;
		mPInfo->singleSelect	= singleSelect;

		mPAskChoicePage		= new CNewUserAskChoicePage(mPInfo);
		mPAskPassPage		= new CNewUserAskPassPage(mPInfo);
		mPBadPassPage		= new CNewUserBadPassPage(mPInfo);
		mPAskPubKeyPage		= new CNewUserAskPubKeyPage(mPInfo);

		PreCalcKeysToChoose();

		mPAskChoicePage->Create(title);
		mPBadPassPage->Create(title);
		mPAskPassPage->Create(title);
		mPAskPubKeyPage->Create(title);

		mIsCreated = TRUE;
	}
	catch (CComboError&)
	{
		Clear();
		throw;
	}
}

void 
CNewUserPages::GetChoices(
	PGPBoolean&		userChosePub, 
	CPGPKey*		pubKey, 
	PGPUInt32&		uNumPubKeys,
	CString&		userName, 
	CSecureString&	securePass, 
	PGPBoolean		&readOnly)
{
	pgpAssert(mPInfo->isFinished);

	if (mPInfo->userChosePub)
	{
		PGPUInt32 i;

		for(i=0;i<mPInfo->uNumPubKeys;i++)
		{
			pubKey[i].Attach(mPInfo->pgpKey[i].Get());
		}

		uNumPubKeys=mPInfo->uNumPubKeys;
	}

	userChosePub	= mPInfo->userChosePub;
	userName		= mPInfo->userName;
	securePass		= mPInfo->securePass;
	readOnly		= mPInfo->userChoseRO;
}

void 
CNewUserPages::Clear()
{
	if (IsntNull(mPAskChoicePage))
		delete mPAskChoicePage;

	if (IsntNull(mPAskPassPage))
		delete mPAskPassPage;

	if (IsntNull(mPBadPassPage))
		delete mPBadPassPage;

	if (IsntNull(mPAskPubKeyPage))
		delete mPAskPubKeyPage;

	mPAskChoicePage		= NULL;
	mPAskPassPage		= NULL;
	mPBadPassPage		= NULL;
	mPAskPubKeyPage		= NULL;

	mIsCreated = FALSE;
}

void 
CNewUserPages::PreCalcKeysToChoose()
{
	mPInfo->pContext->ReloadPGPKeyDB();
	mPInfo->keysToChoose.CreateEmpty(mPInfo->pContext->PGPKeyDB());

	// Get PGPdisk ADK key info.
	PGPBoolean	isDiskADK	= mPInfo->pContext->IsThereADK();
	CPGPKeyID	adkKeyID;

	if (isDiskADK && mPInfo->isForAdminUser)
	{
		CPGPKey	adkKey;

		mPInfo->pContext->GetADK(adkKey);
		adkKey.GetKeyID(adkKeyID);
	}

	// Get default key info
	CPGPclPrefs	clPrefs(mPInfo->pContext->PGPclPrefs());
	CPGPData	defKeyIDData;

	mPInfo->autoUseDefKey = FALSE;

	try
	{
		if(PGPclEnterprise())
		{
			if (mPInfo->isForAdminUser)
			{
				mPInfo->autoUseDefKey = clPrefs.GetBoolean(
					kPGPPrefDiskUseDefaultKey);
			}
		}
	}
	catch (CComboError&) {}

	try
	{
		clPrefs.GetData(kPGPPrefDefaultKeyID, defKeyIDData);

		mPInfo->defKeyID = *static_cast<PGPKeyID *>(defKeyIDData.Get());
		mPInfo->defKeyPrefExists = TRUE;
	}
	catch (CComboError&)
	{
		mPInfo->defKeyPrefExists = FALSE;
	}

	mPInfo->defKeySeen = FALSE;

	// Add appropriate public keys to the choice set.
	CPGPKeySet	pgpKeys(mPInfo->pContext->PGPKeyDB());
	CPGPKeyList	keyList(pgpKeys, kPGPKeyOrdering_Any);
	CPGPKeyIter	keyIter(keyList);
	CPGPKey		key;

	CPGPdiskUserIter	diskUserIter(*mPInfo->pDiskUsers);
	CPGPdiskUser		diskUser;

	while (keyIter.Next(key))
	{
		try
		{
			CPGPKeyID	keyID;
			key.GetKeyID(keyID);

			// Skip revoked, disabled, etc. keys.
			if (key.GetBooleanProp(kPGPKeyProperty_IsRevoked) || 
				key.GetBooleanProp(kPGPKeyProperty_IsDisabled) || 
				key.GetBooleanProp(kPGPKeyProperty_IsExpired) || 
				!key.GetBooleanProp(kPGPKeyProperty_IsEncryptionKey))
			{
				continue;
			}

			// Skip non-private keys if adding for admin user.
			if (mPInfo->isForAdminUser && 
				!key.GetBooleanProp(kPGPKeyProperty_CanDecrypt))
			{
				continue;
			}

			// Skip ADK if choosing for admin.
			if (isDiskADK && mPInfo->isForAdminUser)
			{
				if (keyID.IsEqual(adkKeyID))
					continue;
			}

			// Remember if saw default key.
			if (mPInfo->defKeyPrefExists && 
				!mPInfo->defKeySeen && 
				keyID.IsEqual(mPInfo->defKeyID))
			{
				mPInfo->defKeySeen = TRUE;
				mPInfo->pgpKey[0].Attach(key);
				mPInfo->uNumPubKeys=1;
			}

			// Skip keys already on disk.
			diskUserIter.Rewind();
			PGPBoolean	sawEqualKey	= FALSE;

			while (diskUserIter.Next(diskUser))
			{
				if (diskUser.HasPublicKey())
				{
					CPGPKeyID	diskKeyID;
					diskUser.GetPGPKeyID(diskKeyID);

					if (keyID.IsEqual(diskKeyID))
					{
						sawEqualKey = TRUE;
						break;
					}
				}
			}

			if (sawEqualKey)
				continue;

			// Add the key.
			mPInfo->keysToChoose.Add(key);
		}
		catch (CComboError&)
		{
			pgpAssert(FALSE);
		}
	}
}

⌨️ 快捷键说明

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