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

📄 pnmisc.c

📁 vc环境下的pgp源码
💻 C
📖 第 1 页 / 共 2 页
字号:
{
	PGPError			err				= kPGPError_NoErr;
	CHAR				szPrompt[128];
	LPSTR				psz;
	PGPOptionListRef	optionlist;

	if (g_AOS.pnconfig.bWarnReSharedSecret)
	{
		PNMessageBox (hwnd, IDS_CAPTION, IDS_SHAREDSECRETWARNING,
				MB_OK|MB_ICONEXCLAMATION);

		g_AOS.pnconfig.bWarnReSharedSecret = FALSE;
		PNSaveConfiguration (hwnd, &g_AOS.pnconfig, FALSE);
	}

	LoadString (g_hinst, IDS_SHAREDSECRETPROMPT, szPrompt, sizeof(szPrompt));

	err = PGPBuildOptionList (g_context, &optionlist,
			PGPOUIDialogPrompt (g_context, szPrompt),
			PGPOUIOutputPassphrase (g_context, &psz),
			PGPOUIParentWindowHandle (g_context, hwnd),
			PGPOUIMinimumPassphraseLength (g_context, MIN_SECRET_LENGTH),
			PGPOUIMinimumPassphraseQuality (g_context, MIN_SECRET_QUALITY),
			PGPOLastOption (g_context));

	err = PGPConfirmationPassphraseDialog (g_context, 
					optionlist, PGPOLastOption (g_context));
	PGPFreeOptionList (optionlist);

	if (IsntPGPError (err))
	{
		if (psz) 
		{
			lstrcpyn (pszSecret, psz, uMaxSecretLength+1);
			PGPFreeData (psz);
		}
		return TRUE;
	}
	else 
		return FALSE;

}


//	_____________________________________
//
//	putup error messagebox (if necessary)

PGPError 
PNErrorBox (
		HWND			hwnd,
		PGPError		errIn) 
{
	return PGPclErrorBox (hwnd, errIn);
}

//	______________________________________________
//
//  create a shortcut file

static HRESULT 
sCreateFileLink (
		LPCSTR	pszPathFile, 
		LPSTR	pszPathLink, 
		LPSTR	pszDescription) 
{
	HRESULT		hres; 
    IShellLink*	psl;     

	// Get a pointer to the IShellLink interface. 
	hres = CoInitialize (NULL);
	hres = CoCreateInstance (&CLSID_ShellLink, NULL, 
						CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl); 
	if (SUCCEEDED (hres)) 
	{         
		IPersistFile* ppf;  

		psl->lpVtbl->SetPath (psl, pszPathFile); 
        psl->lpVtbl->SetDescription (psl, pszDescription);  

		hres = psl->lpVtbl->QueryInterface (psl, &IID_IPersistFile, &ppf);          
		if (SUCCEEDED (hres)) 
		{ 
			WORD wsz[MAX_PATH];
			MultiByteToWideChar (CP_ACP, 0, pszPathLink, -1, wsz, MAX_PATH);

			hres = ppf->lpVtbl->Save (ppf, wsz, TRUE); 
			ppf->lpVtbl->Release (ppf);         
		} 
        psl->lpVtbl->Release (psl);     
	}     

	CoUninitialize ();
	return hres; 
} 


//	___________________________________________________
//
//  Set the flags based on if we have good authentication keys

VOID
PNSetAuthKeyFlags (
		PGPContextRef	context,
		PPNCONFIG		ppnconfig,
		PBOOL			pbPGPKey,
		PBOOL			pbX509Key)
{
	PGPKeyRef	keyPGP;
	PGPKeyRef	keyX509;
	PGPSigRef	sigX509;
	PGPBoolean	b;

	*pbPGPKey = FALSE;
	*pbX509Key = FALSE;

	PGPnetGetConfiguredAuthKeys (g_context, &g_AOS.pnconfig, 
					g_AOS.keysetMain, &keyPGP, &keyX509, &sigX509);

	if (ppnconfig->uPGPAuthKeyAlg != kPGPPublicKeyAlgorithm_Invalid)
	{
		if (PGPKeyRefIsValid (keyPGP))
		{
			PGPGetKeyBoolean (keyPGP, kPGPKeyPropCanSign, &b);
			if (b)
			{
				PGPGetKeyBoolean (keyPGP, kPGPKeyPropIsSecretShared, &b);
				if (!b)
					*pbPGPKey = TRUE;
			}
		}
	}

	if (ppnconfig->uX509AuthKeyAlg != kPGPPublicKeyAlgorithm_Invalid)
	{
		if (PGPKeyRefIsValid (keyX509) &&
			PGPSigRefIsValid (sigX509))
		{
			PGPGetKeyBoolean (keyX509, kPGPKeyPropCanSign, &b);
			if (b)
			{
				PGPGetKeyBoolean (keyX509, kPGPKeyPropIsSecretShared, &b);
				if (!b)
					*pbX509Key = TRUE;
			}
		}
	}
}


//	___________________________________________________
//
//  Determine the appropriate icon for a key, based on
//	its properties

INT 
PNDetermineKeyIcon (
		PGPKeyRef	Key, 
		BOOL*		pbItalics) 
{

	PGPBoolean bRevoked, bSecret, bDisabled, bExpired, bSplit;
	PGPBoolean b, bRSADisabled;
	PGPUInt32 iIdx, iAlg;

	bRSADisabled = FALSE;
	PGPGetKeyBoolean (Key, kPGPKeyPropIsRevoked, &bRevoked);
	PGPGetKeyBoolean (Key, kPGPKeyPropIsSecret, &bSecret);
	PGPGetKeyBoolean (Key, kPGPKeyPropIsDisabled, &bDisabled);
	PGPGetKeyBoolean (Key, kPGPKeyPropIsExpired, &bExpired);
	PGPGetKeyBoolean (Key, kPGPKeyPropIsSecretShared, &bSplit);
	PGPGetKeyNumber (Key, kPGPKeyPropAlgID, &iAlg);

	if (iAlg == kPGPPublicKeyAlgorithm_RSA) {
		if (bSecret) {
			PGPGetKeyBoolean (Key, kPGPKeyPropCanSign, &b);
			if (!b) bRSADisabled = TRUE;
			if (bRevoked) iIdx = IDX_RSASECREVKEY;
			else if (bExpired) iIdx = IDX_RSASECEXPKEY;
			else if (bDisabled) iIdx = IDX_RSASECDISKEY;
			else if (bSplit) iIdx = IDX_RSASECSHRKEY;
			else iIdx = IDX_RSASECKEY;
		}
		else {
			PGPGetKeyBoolean (Key, kPGPKeyPropCanEncrypt, &b);
			if (!b) bRSADisabled = TRUE;
			if (bRevoked) iIdx = IDX_RSAPUBREVKEY;
			else if (bExpired) iIdx = IDX_RSAPUBEXPKEY;
			else if (bDisabled) iIdx = IDX_RSAPUBDISKEY;
			else iIdx = IDX_RSAPUBKEY;
		}
	}
	// DSA/ElGamal
	else {
		if (bSecret) {
			if (bRevoked) iIdx = IDX_DSASECREVKEY;
			else if (bExpired) iIdx = IDX_DSASECEXPKEY;
			else if (bDisabled) iIdx = IDX_DSASECDISKEY;
			else if (bSplit) iIdx = IDX_DSASECSHRKEY;
			else iIdx = IDX_DSASECKEY;
		}
		else {
			if (bRevoked) iIdx = IDX_DSAPUBREVKEY;
			else if (bExpired) iIdx = IDX_DSAPUBEXPKEY;
			else if (bDisabled) iIdx = IDX_DSAPUBDISKEY;
			else iIdx = IDX_DSAPUBKEY;
		}
	}

	if (pbItalics) 
		*pbItalics = bRevoked || bExpired || bDisabled || bRSADisabled;
	return iIdx;
}


//	___________________________________________________
//
//  Determine the appropriate icon for a cert, based on
//	its properties

INT 
PNDetermineCertIcon (
		PGPSigRef	cert, 
		BOOL*		pbItalics) 
{
	PGPBoolean	bRevoked, bVerified, bTried, bExpired;
	PGPBoolean	bNotCorrupt, bExportable, bX509;
	PGPUInt32	uTrustLevel;
	INT			idx;

	PGPGetSigBoolean (cert, kPGPSigPropIsRevoked, &bRevoked);
	PGPGetSigBoolean (cert, kPGPSigPropIsExpired, &bExpired);
	PGPGetSigBoolean (cert, kPGPSigPropIsVerified, &bVerified);
	PGPGetSigBoolean (cert, kPGPSigPropIsTried, &bTried);
	PGPGetSigBoolean (cert, kPGPSigPropIsNotCorrupt, &bNotCorrupt);
	PGPGetSigBoolean (cert, kPGPSigPropIsExportable, &bExportable);
	PGPGetSigBoolean (cert, kPGPSigPropIsX509, &bX509);
	PGPGetSigNumber  (cert, kPGPSigPropTrustLevel, &uTrustLevel);

	if (bX509) {
		if (bRevoked)
			idx = IDX_X509REVCERT;
		else if (bExpired)
			idx = IDX_X509EXPCERT;
		else
			idx = IDX_X509CERT;
	}
	else if (bRevoked) 
		idx = IDX_REVCERT;
	else if (bExpired) 
		idx = IDX_EXPCERT;
	else if (bVerified) {
		if (bExportable) {
			if (uTrustLevel == 1) 
				idx = IDX_TRUSTEDCERT;
			else 
				idx = IDX_EXPORTCERT;
		}
		else {
			if (uTrustLevel == 2) 
				idx = IDX_METACERT;
			else 
				idx = IDX_CERT;
		}
	}
	else if (bTried) 
		idx = IDX_BADCERT;
	else if (bNotCorrupt) {
		if (bExportable) 
			idx = IDX_EXPORTCERT;
		else 
			idx = IDX_CERT;
	}
	else 
		idx = IDX_BADCERT;

	if ((idx == IDX_BADCERT) || (idx == IDX_REVCERT) || (idx == IDX_EXPCERT)) 
	{
		if (pbItalics)
			*pbItalics = TRUE;
	}

	return idx;
}


//	___________________________________________________
//
//  save the configuration data and signal service

VOID 
PNSaveConfiguration (
		HWND			hwnd,
		PPNCONFIG		pPNConfig,
		BOOL			bKeyringsUpdated) 
{
	UINT uStatus;

	PGPnetSaveConfiguration (g_context, pPNConfig);
	if (bKeyringsUpdated)
	{
		PNSendServiceMessage (PGPNET_M_APPMESSAGE,
					PGPNET_CONFIGANDKEYRINGSUPDATED, (LPARAM)hwnd);
	}
	else
	{
		PNSendServiceMessage (PGPNET_M_APPMESSAGE,
					PGPNET_CONFIGUPDATED, (LPARAM)hwnd);
	}

	uStatus = PNDisplayStatusBarText ();
	if ((uStatus != PGPNET_DRIVERENABLED) && 
		(uStatus != PGPNET_DRIVERDISABLED) &&
		(hwnd != NULL))
	{
		PNMessageBox (hwnd, IDS_CAPTION, IDS_OPTIONNOSERVICE, 
						MB_OK|MB_ICONEXCLAMATION);
	}
}

//	____________________________________
//
//	save On/Off pref to file

VOID
PNSaveOnOffButtons (
		HWND			hwnd,
		PGPContextRef	context)
{
	PGPPrefRef			prefref			= kInvalidPGPPrefRef;
	PGPError			err;
	UINT				uStatus;

	if (IsDlgButtonChecked (hwnd, IDC_PGPNETON) == BST_CHECKED)
		g_AOS.pnconfig.bPGPnetEnabled = TRUE;
	else
		g_AOS.pnconfig.bPGPnetEnabled = FALSE;

	err = PGPnetOpenPrefs (PGPGetContextMemoryMgr (context), &prefref);
	if (IsntPGPError (err))
	{
		// save on/off value to pref file 
		PGPSetPrefBoolean (prefref, kPGPNetPrefEnablePGPnet, 
				g_AOS.pnconfig.bPGPnetEnabled); 
		PGPnetClosePrefs (prefref, TRUE);

		PNSendServiceMessage (
					PGPNET_M_APPMESSAGE, PGPNET_CONFIGUPDATED, (LPARAM)hwnd);

		uStatus = PNDisplayStatusBarText ();
		if ((uStatus != PGPNET_DRIVERENABLED) &&
			(uStatus != PGPNET_DRIVERDISABLED))
		{
			PNMessageBox (hwnd, IDS_CAPTION, IDS_OPTIONNOSERVICE, 
							MB_OK|MB_ICONEXCLAMATION);
		}

		// signal tray app to reload from registry
		PNSendTrayAppMessage (
					PGPNET_M_APPMESSAGE, PGPNET_CONFIGUPDATED, (LPARAM)hwnd);
	}
}


⌨️ 快捷键说明

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