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

📄 verificationblock.c

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 C
字号:
/*____________________________________________________________________________
	Copyright (C) 2002 PGP Corporation
	All rights reserved.

	$Id: VerificationBlock.c,v 1.8 2002/08/06 20:10:28 dallen Exp $
____________________________________________________________________________*/

#include <windows.h>

#include "pgpEncode.h"
#include "pgpKeys.h"
#include "pgpUtilities.h"
#include "pgpDebug.h"
#include "pgpPFLPriv.h"

#include "pgpClientLib.h"

#include "Prefs.h"
#include "SharedStrings.h"

static void StdTimeToSystemTime(struct tm *ptm, SYSTEMTIME *pst) 
{
	pst->wYear = ptm->tm_year + 1900;
	pst->wMonth = ptm->tm_mon + 1;
	pst->wDay = ptm->tm_mday;
	pst->wDayOfWeek = ptm->tm_wday;
	pst->wHour = ptm->tm_hour;
	pst->wMinute = ptm->tm_min;
	pst->wSecond = ptm->tm_sec;
	pst->wMilliseconds = 0;
}


static void ConvertPGPTimeToString(PGPTime time,
								   char *dateString, 
								   PGPUInt32 dateStrLength,
								   char *timeString,
								   PGPUInt32 timeStrLength) 
{
	SYSTEMTIME	systemtime;
	time_t		ttTime;
	struct tm*	ptm;

	ttTime = PGPGetStdTimeFromPGPTime(time);
	ptm = localtime(&ttTime);

	StdTimeToSystemTime(ptm, &systemtime);

	GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &systemtime, 
		NULL, dateString, dateStrLength);

	GetTimeFormat(LOCALE_USER_DEFAULT, LOCALE_NOUSEROVERRIDE, &systemtime,
		NULL, timeString, timeStrLength);

	return;
}


static PGPBoolean GetKeyIDString(PGPKeyID keyID, 
								 char *idBuffer, 
								 PGPUInt32 bufferSize) 
{

	char tempBuffer[kPGPMaxKeyIDStringSize];

	if (bufferSize < 11) return FALSE;

	PGPGetKeyIDString(&keyID, kPGPKeyIDString_Abbreviated, tempBuffer);
	lstrcpy(idBuffer, "0x");
	lstrcat(idBuffer, &tempBuffer[2]);

	return TRUE;
}


PGPError CreateVerificationBlock(HINSTANCE hInst, 
								 PGPContextRef context,
								 PGPEventSignatureData *sigData, 
								 PGPBoolean wasEncrypted,
								 char **blockBegin,
								 char **blockEnd)
{
	PGPUInt32 validity;
	PGPBoolean isAxiomatic;
	PGPBoolean keyCanSign;
	PGPMemoryMgrRef memoryMgr;
	char dateString[256];
	char timeString[256];
	char tempString[256];
	PGPError err = kPGPError_NoErr;
	PGPBoolean bSigAlert,bInvalidAlert;
	char keyIDStr[11];

	bInvalidAlert=bSigAlert=FALSE;

	PGPValidatePtr(sigData);
	PGPValidatePtr(blockBegin);
	PGPValidatePtr(blockEnd);

	isAxiomatic = FALSE;
	keyCanSign = TRUE;

	memoryMgr = PGPPeekContextMemoryMgr(context);

	*blockBegin = (char *) PGPNewData(memoryMgr,
								1024,
								kPGPMemoryMgrFlags_Clear);
								
	if (*blockBegin == NULL)
		return kPGPError_OutOfMemory;

	*blockEnd = (char *) PGPNewData(memoryMgr,
							1024,
							kPGPMemoryMgrFlags_Clear);
								
	if (*blockEnd == NULL)
		return kPGPError_OutOfMemory;

	LoadString(hInst, IDS_SIGHEADER, tempString, sizeof(tempString));
	strcat(*blockBegin, tempString);

	LoadString(hInst, IDS_SIGSTATUS, tempString, sizeof(tempString));
	strcat(*blockBegin, tempString);

	if (sigData->signingKey != 0)
	    PGPGetKeyDBObjBooleanProperty(sigData->signingKey, 
			kPGPKeyProperty_IsSigningKey, 
			&keyCanSign);

	if (!keyCanSign)
		LoadString(hInst, IDS_ALGNOTSUPPORTED, tempString, 
			sizeof(tempString));
	else 
	{
		if (sigData->verified)
			LoadString(hInst, IDS_GOODSIG, tempString, sizeof(tempString));
		else if (sigData->signingKey == 0)
			LoadString(hInst, IDS_UNKNOWNSIG, tempString, sizeof(tempString));
		else
		{
			bSigAlert=TRUE;
			LoadString(hInst, IDS_BADSIG, tempString, sizeof(tempString));
		}

		strcat(*blockBegin, tempString);

		LoadString(hInst, IDS_SIGCR, tempString, sizeof(tempString));

		if (sigData->signingKey != 0)
		{
			PGPGetKeyDBObjNumericProperty(sigData->signingKey, 
				kPGPKeyProperty_Validity,
				&validity);

			PGPGetKeyDBObjBooleanProperty(sigData->signingKey, 
				kPGPKeyProperty_IsAxiomatic, 
				&isAxiomatic);

			if (sigData->keyRevoked)
				LoadString(hInst, IDS_REVOKEDKEY, tempString, 
					sizeof(tempString));
			else if (sigData->keyExpired)
				LoadString(hInst, IDS_EXPIREDKEY, tempString, 
					sizeof(tempString));
			else if (sigData->keyDisabled)
				LoadString(hInst, IDS_DISABLEDKEY, tempString, 
					sizeof(tempString));
			else if (!isAxiomatic)
			{
				if ((validity == kPGPValidity_Invalid) ||
					(validity == kPGPValidity_Unknown) ||
						((validity == kPGPValidity_Marginal) && 
						MarginalIsInvalid(memoryMgr)))
				{
					LoadString(hInst, IDS_INVALIDKEY, tempString, 
						sizeof(tempString));

					bInvalidAlert=TRUE;
				}
			}
		}
	}

	strcat(*blockBegin, tempString);

	if(bSigAlert)
	{
		LoadString(hInst, IDS_SIGALERT, tempString, sizeof(tempString));
		strcat(*blockBegin, tempString);
	}
	if(bInvalidAlert)
	{
		LoadString(hInst, IDS_INVALIDALERT, tempString, sizeof(tempString));
		strcat(*blockBegin, tempString);
	}

	LoadString(hInst, IDS_SIGNER, tempString, sizeof(tempString));
	strcat(*blockBegin, tempString);

	GetKeyIDString(sigData->signingKeyID, keyIDStr, sizeof(keyIDStr));

	// Get name and raw Validity number
	if (sigData->signingKey == 0)
	{
		LoadString(hInst, IDS_UNKNOWNSIGNER, tempString, 
			sizeof(tempString));
		strcat(*blockBegin, tempString);
	}
	else
	{
		int nameLength = kPGPMaxUserIDSize-1;
		char name[kPGPMaxUserIDSize];
		DWORD type;

		PGPGetKeyDBObjNumericProperty(sigData->signingKey,
			kPGPKeyDBObjProperty_ObjectType,
			&type);

		if(type==kPGPKeyDBObjType_SubKey)
		{
			// if signing key is a subkey (as allowed by RFC2440
			// and emitted by GPG) then get the name from the 
			// parent master key
			PGPKeyDBObjRef	key;
			key = PGPPeekKeyDBObjKey( sigData->signingKey );
			err = PGPclGetPrimaryUserIDName( key,
				name,sizeof( name ), &nameLength );
		}
		else
		{
			err = PGPclGetPrimaryUserIDName( sigData->signingKey,
				name,sizeof( name ), &nameLength );
		}

		if (IsPGPError (err))
		{
			err = kPGPError_NoErr;
			LoadString(hInst, IDS_UNKNOWNSIGNER, name, nameLength);
		}

		strcat(*blockBegin, name);
	}

	strcat(*blockBegin," (");
	strcat(*blockBegin, keyIDStr);
	strcat(*blockBegin,")\r\n");

	LoadString(hInst, IDS_SIGDATE, tempString, sizeof(tempString));
	strcat(*blockBegin, tempString);

	ConvertPGPTimeToString(sigData->creationTime, dateString, 
		sizeof(dateString), timeString, sizeof(timeString));

	strcat(*blockBegin, dateString);
	strcat(*blockBegin, " ");
	strcat(*blockBegin, timeString);
	strcat(*blockBegin, "\r\n");

	LoadString(hInst, IDS_VERIFIED, tempString, sizeof(tempString));
	strcat(*blockBegin, tempString);

	ConvertPGPTimeToString(PGPGetTime(), dateString, sizeof(dateString),
		timeString, sizeof(timeString));

	strcat(*blockBegin, dateString);
	strcat(*blockBegin, " ");
	strcat(*blockBegin, timeString);
	strcat(*blockBegin, "\r\n");

	if (wasEncrypted)
	{
		LoadString(hInst, IDS_BEGINDECRYPTED, tempString, 
			sizeof(tempString));
		strcat(*blockBegin, tempString);
		LoadString(hInst, IDS_ENDDECRYPTED, tempString, 
			sizeof(tempString));
		strcpy(*blockEnd, tempString);
	}
	else
	{
		LoadString(hInst, IDS_BEGINVERIFIED, tempString, 
			sizeof(tempString));
		strcat(*blockBegin, tempString);
		LoadString(hInst, IDS_ENDVERIFIED, tempString, 
			sizeof(tempString));
		strcpy(*blockEnd, tempString);
	}

	return err;
}

/*__Editor_settings____

	Local Variables:
	tab-width: 4
	End:
	vi: ts=4 sw=4
	vim: si
_____________________*/

⌨️ 快捷键说明

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