📄 sigevent.c
字号:
/*____________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
$Id: SigEvent.c,v 1.7 2002/10/29 20:14:07 wjb Exp $
____________________________________________________________________________*/
#include <windows.h>
#include <stdio.h>
#include "pgpEncode.h"
#include "pgpKeys.h"
#include "pgpUtilities.h"
#include "PGPsc.h"
#include "pgpClientLib.h"
void SigTimeToSystemTime (
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;
}
void ConvertSigTimeToString (
PGPTime Time,
LPSTR sz,
INT iLen)
{
SYSTEMTIME systemtime;
time_t ttTime;
struct tm* ptm;
ttTime = PGPGetStdTimeFromPGPTime (Time);
ptm = localtime (&ttTime);
SigTimeToSystemTime (ptm, &systemtime);
GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &systemtime,
NULL, sz, iLen);
strcat(sz," ");
GetTimeFormat(LOCALE_USER_DEFAULT, LOCALE_NOUSEROVERRIDE, &systemtime,
NULL, &(sz[strlen(sz)]),iLen-strlen(sz));
}
BOOL SEGetKeyIDString(PGPKeyID KeyID, LPSTR sz, UINT u)
{
CHAR szID[kPGPMaxKeyIDStringSize];
if (u < 11) return FALSE;
PGPGetKeyIDString (&KeyID, kPGPKeyIDString_Abbreviated, szID);
lstrcpy (sz, "0x");
lstrcat (sz, &szID[2]);
return TRUE;
}
// SigEvent
//
// Call after kPGPEvent_SignatureEvent. Must link to PGPsc.
//
// Params:
// d Event data (cast)
// fileName fileName (or application name)
void SigEvent(HWND hwnd,PGPContextRef context,
PGPEventSignatureData *d,char *fileName)
{
DWORD Type,Validity;
PGPBoolean bAxiomatic,bKeyCanVerify;
char szMsgStr[500];
BOOL bMarginalInvalid;
PGPError err;
char keyidstr[11];
Validity = kPGPValidity_Unknown;
bAxiomatic=FALSE;
bKeyCanVerify=FALSE;
// Icon information for PGPlog
if(d->verified)
strcpy(szMsgStr,"Good Signature\n");
else
strcpy(szMsgStr,"Bad Signature\n");
// Filename (or Clipboard... or Eudora.. etc)
sprintf(&(szMsgStr[strlen(szMsgStr)]),"%s\n",
PGPscJustFile(fileName));
// Get name and raw Validity number
if((d->signingKey)==0)
{
strcat(szMsgStr,"Unknown\n");
}
else
{
int namelen=kPGPMaxUserIDSize-1;
char name[kPGPMaxUserIDSize];
PGPKeyDBObjRef key;
PGPGetKeyDBObjNumericProperty(d->signingKey,
kPGPKeyDBObjProperty_ObjectType,
&Type);
// if signing key is a subkey (as allowed by RFC2440
// and emitted by GPG) then get the name from the
// parent master key
// see if this subkey can verify the signature
PGPGetKeyDBObjBooleanProperty (d->signingKey,
kPGPKeyProperty_CanVerify,
&bKeyCanVerify);
if(Type==kPGPKeyDBObjType_SubKey)
key = PGPPeekKeyDBObjKey( d->signingKey );
else
key = d->signingKey;
err = PGPclGetPrimaryUserIDNameUTF8( key, name, sizeof( name ), &namelen );
if (IsPGPError (err))
strcpy (name,"<unknown signer>");
sprintf(&(szMsgStr[strlen(szMsgStr)]),"%s\n",name);
PGPGetKeyDBObjNumericProperty(key,
kPGPKeyProperty_Validity,
&Validity);
PGPGetKeyDBObjBooleanProperty (key,
kPGPKeyProperty_IsAxiomatic,
&bAxiomatic);
}
SEGetKeyIDString(d->signingKeyID,keyidstr,sizeof(keyidstr));
strcat(szMsgStr,keyidstr);
strcat(szMsgStr,"\n");
// Decode validity into string
if(bAxiomatic)
strcat(szMsgStr,"Implicit Trust\n"); // Axiomatic
else switch(Validity)
{
case kPGPValidity_Marginal :
strcat(szMsgStr,"Marginal Key\n");
break;
case kPGPValidity_Complete :
strcat(szMsgStr,"Valid Key\n");
break;
default :
strcat(szMsgStr,"Invalid Key\n");
break;
}
// Output date and/or extra info
if(!bKeyCanVerify)
strcat(szMsgStr,"Signing algorithm not supported");
else if((d->verified==0)&&(d->signingKey!=0))
strcat(szMsgStr,"Bad Signature\n");
else
{
/* sprintf(&(szMsgStr[strlen(szMsgStr)]),
"%s", ctime((time_t *)&d->creationTime));
// Get rid of ctime \n
szMsgStr[strlen(szMsgStr)-1]=0;*/
PGPscGetMarginalInvalidPref(context,&bMarginalInvalid);
ConvertSigTimeToString (
d->creationTime,
&(szMsgStr[strlen(szMsgStr)]),
500-strlen(szMsgStr));
if(d->signingKey==0)
strcat(szMsgStr," (Unknown Key)");
else if (d->keyRevoked)
strcat(szMsgStr," (Revoked Key)");
else if (d->keyExpired)
strcat(szMsgStr," (Expired Key)");
else if (d->keyDisabled)
strcat(szMsgStr," (Disabled Key)");
else if((Validity==kPGPValidity_Unknown)||
(Validity==kPGPValidity_Invalid))
strcat(szMsgStr," (Invalid Key)");
else if((bMarginalInvalid)&&
(Validity==kPGPValidity_Marginal))
strcat(szMsgStr," (Invalid Key)");
else if( Type == kPGPKeyDBObjType_SubKey )
strcat(szMsgStr," by subkey");
}
// Send DDEML msg to PGPlog
PGPscSendPGPlogMsg(hwnd,szMsgStr);
}
/*__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 + -