icqkeyop.c
来自「PGP8.0源码 请认真阅读您的文件包然后写出其具体功能」· C语言 代码 · 共 470 行
C
470 行
/*__________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
$Id: ICQkeyop.c,v 1.19 2002/10/12 22:19:12 wjb Exp $
__________________________________________________________________________*/
#include "precomp.h"
extern UINT g_uAddedKeysMessage;
//----------------------------------------------------|
// free passphrase for key
VOID
KMFreePhrase (LPSTR pszPhrase)
{
if (pszPhrase) {
PGPFreeData (pszPhrase);
}
}
BOOL CreateUserID(HWND hwnd,ICQWIZINFO *iwi)
{
PGPByte* pPasskey = NULL;
PGPSize sizePasskey;
PGPError err;
char szUserID[500];
BOOL bRetVal;
bRetVal=FALSE;
sprintf(szUserID,"%s <ICQ:%s>",iwi->NameBuff,iwi->NumBuff);
err = PGPclGetKeyPhrase (iwi->Context, iwi->tlsContext,
hwnd, "Please enter your passphrase",
iwi->KeyDB, iwi->DefaultKey,
NULL, &pPasskey, &sizePasskey);
if(IsntPGPError(err))
{
// make sure we have enough entropy
PGPclRandom (iwi->Context, hwnd, 0);
if (pPasskey)
{
err = PGPAddUserID (iwi->DefaultKey, szUserID,
PGPOPasskeyBuffer (iwi->Context,
pPasskey, sizePasskey),
PGPOLastOption (iwi->Context));
}
else
{
err = PGPAddUserID (iwi->DefaultKey, szUserID,
PGPOLastOption (iwi->Context));
}
if (IsntPGPError (err))
{
PostMessage (HWND_BROADCAST, g_uAddedKeysMessage,0,0);
bRetVal=TRUE;
}
}
if (pPasskey)
{
PGPFreeData (pPasskey);
}
return bRetVal;
}
PGPKeyDBObjRef GetICQUserID(PGPKeyDBObjRef Key,PGPKeyDBRef xKeyDB)
{
PGPKeyDBObjRef UserID,ICQUserID;
PGPBoolean bAttrib;
UINT u;
char sz[500];
UINT uLen=500;
PGPError err;
ICQUserID=NULL;
if (PGPKeyDBObjRefIsValid (Key))
{
err=PGPKeyIterSeek (g_KeyIter, Key);
PGPKeyIterNextKeyDBObj (g_KeyIter,
kPGPKeyDBObjType_UserID, &UserID);
while (UserID)
{
PGPGetKeyDBObjBooleanProperty (UserID,
kPGPUserIDProperty_IsAttribute, &bAttrib);
if (!bAttrib)
{
PGPclGetUserIDName (UserID, sz, uLen, &u);
if(strstr(sz,"<ICQ:")!=0)
{
ICQUserID=UserID;
}
}
PGPKeyIterNextKeyDBObj (g_KeyIter,
kPGPKeyDBObjType_UserID, &UserID);
}
}
return ICQUserID;
}
PGPKeyDBObjRef MatchICQWithKey(char *szUserID,PGPKeyDBRef KeyDB,PGPBoolean bMustSign)
{
PGPKeyDBObjRef UserID;
PGPBoolean bAttrib;
UINT u;
char sz[500];
UINT uLen=500;
PGPKeyDBObjRef theKey;
PGPKeyDBObjRef MatchingKey;
PGPKeyIterRef keyIter;
PGPBoolean fRevoked,
fExpired,
fDisabled,
fCanSign;
MatchingKey=NULL;
if(KeyDB==NULL)
{
keyIter=g_KeyIter;
}
else
{
PGPNewKeyIterFromKeyDB (KeyDB, &keyIter);
}
PGPKeyIterRewind( keyIter, kPGPKeyDBObjType_Key );
PGPKeyIterNextKeyDBObj (keyIter,
kPGPKeyDBObjType_Key, &theKey);
while(theKey)
{
PGPGetKeyDBObjBooleanProperty(theKey,
kPGPKeyProperty_IsRevoked,&fRevoked);
PGPGetKeyDBObjBooleanProperty(theKey,
kPGPKeyProperty_IsDisabled,&fDisabled);
PGPGetKeyDBObjBooleanProperty(theKey,
kPGPKeyProperty_IsExpired,&fExpired);
PGPGetKeyDBObjBooleanProperty(theKey,
kPGPKeyProperty_CanSign,&fCanSign);
if(!(fRevoked||fExpired||fDisabled))
{
if(!((bMustSign)&&(!fCanSign)))
{
PGPKeyIterNextKeyDBObj (keyIter,
kPGPKeyDBObjType_UserID, &UserID);
while (UserID)
{
PGPGetKeyDBObjBooleanProperty (UserID,
kPGPUserIDProperty_IsAttribute, &bAttrib);
if (!bAttrib)
{
PGPclGetUserIDName (UserID, sz, uLen, &u);
if(strstr(sz,szUserID)!=0)
{
MatchingKey=theKey;
}
}
PGPKeyIterNextKeyDBObj (keyIter,
kPGPKeyDBObjType_UserID, &UserID);
}
}
}
PGPKeyIterNextKeyDBObj (keyIter,
kPGPKeyDBObjType_Key, &theKey);
}
if(KeyDB==NULL)
{
;
}
else
{
PGPFreeKeyIter(keyIter);
}
return MatchingKey;
}
BOOL ICQUserIDExists(PGPKeyDBObjRef Key,PGPKeyDBRef xKeyDB)
{
PGPKeyDBObjRef UserID;
UserID=GetICQUserID(Key,g_KeyDB);
if(UserID!=NULL)
return TRUE;
return FALSE;
}
BOOL ICQMatchExists(char *szUserID,PGPKeyDBRef xKeyDB)
{
PGPKeyDBObjRef Key;
Key=MatchICQWithKey(szUserID,NULL,FALSE);
if(Key!=NULL)
return TRUE;
return FALSE;
}
BOOL CheckForICQMatch(HWND hwnd,void *PGPsc,void *PGPtls,char *szUserID)
{
// PGPKeyDBObjRef DefaultKey;
// PGPError err;
BOOL Rst;
PGPContextRef Context;
PGPtlsContextRef tlsContext;
// We need to ensure we are not using the global keydb
// or key iter at the same time in any one function
WaitForSingleObject(hGlobalMutex,INFINITE);
Rst=FALSE;
Context=(PGPContextRef)PGPsc;
tlsContext=(PGPtlsContextRef)PGPtls;
if(!PGPKeyDBRefIsValid(g_KeyDB))
{
/* Errors silently so user isn't bugged if PGP
isn't configured correctly.
MessageBox(hwnd,
"The keyrings could not be opened.\n\n"
"You probably have PGPkeys open. The\n"
"new version of the SDK will solve this\n"
"problem. Until then, close PGPkeys.\n\n"
"Thank You.","PGP Error",
MB_OK|MB_SETFOREGROUND|MB_ICONINFORMATION);*/
}
else
{
// err=PGPclGetDefaultPrivateKey(g_KeyDB,&DefaultKey);
// if(IsPGPError(err))
// {
/*
MessageBox(hwnd,
"No default key was found.\n\n"
"Please set a default key using PGPkeys",
"PGP Error",
MB_OK|MB_SETFOREGROUND|MB_ICONSTOP);*/
// }
// else
// {
if(ICQMatchExists(szUserID,g_KeyDB))
{
Rst=TRUE;
}
// }
}
// Release Global Mutext on keydb and keyiter
ReleaseMutex(hGlobalMutex);
return Rst;
}
BOOL CheckForICQUserID(HWND hwnd,void *PGPsc,void *PGPtls)
{
PGPKeyDBObjRef DefaultKey;
PGPError err;
BOOL Rst;
PGPContextRef Context;
PGPtlsContextRef tlsContext;
// We need to ensure we are not using the global keydb
// or key iter at the same time in any one function
WaitForSingleObject(hGlobalMutex,INFINITE);
Rst=FALSE;
Context=(PGPContextRef)PGPsc;
tlsContext=(PGPtlsContextRef)PGPtls;
if(!PGPKeyDBRefIsValid(g_KeyDB))
{
MessageBox(hwnd,
"The keyrings could not be opened.\n\n"
"You probably have PGPkeys open. The\n"
"new version of the SDK will solve this\n"
"problem. Until then, close PGPkeys.\n\n"
"Thank You.","PGP Error",
MB_OK|MB_SETFOREGROUND|MB_ICONINFORMATION);
}
else
{
// err=PGPclGetDefaultPrivateKey(g_KeyDB,&DefaultKey);
err=GetLocalUserKey(g_KeyDB,&DefaultKey);
if(IsPGPError(err))
{
MessageBox(hwnd,
"No default key was found.\n\n"
"Please set a default key using PGPkeys",
"PGP Error",
MB_OK|MB_SETFOREGROUND|MB_ICONSTOP);
}
else
{
if(ICQUserIDExists(DefaultKey,g_KeyDB))
{
Rst=TRUE;
}
}
}
// Release Global Mutext on keydb and keyiter
ReleaseMutex(hGlobalMutex);
return Rst;
}
BOOL ICQWizard(HWND hwnd,void *PGPsc,void *PGPtls)
{
BOOL Rst;
PGPKeyDBRef KeyDB;
PGPError err;
PGPContextRef Context;
PGPtlsContextRef tlsContext;
PGPKeyDBObjRef DefaultKey;
Context=(PGPContextRef)PGPsc;
tlsContext=(PGPtlsContextRef)PGPtls;
Rst=FALSE;
err=PGPclOpenDefaultKeyrings(Context,
kPGPOpenKeyDBFileOptions_Mutable,&KeyDB);
if(IsPGPError(err))
{
MessageBox(hwnd,
"The keyrings could not be opened for writable\n"
"access. Therefore, an ICQ user ID cannot not be\n"
"created on your key. Please check your keyring\n"
"file permissions","PGPicq User ID Wizard",
MB_OK|MB_SETFOREGROUND|MB_ICONSTOP);
}
else
{
//err=PGPclGetDefaultPrivateKey(KeyDB,&DefaultKey);
err=GetLocalUserKey(KeyDB,&DefaultKey);
if((IsntPGPError(err))&&(DefaultKey!=NULL))
{
Rst=ICQUserIDWizard(hwnd,Context,tlsContext,
DefaultKey,KeyDB);
}
else
{
MessageBox(hwnd,
"There is no default key selected for your keyring.\n"
"Please select a default key using PGPkeys",
"PGPicq User ID Wizard",
MB_OK|MB_SETFOREGROUND|MB_ICONSTOP);
}
PGPFreeKeyDB(KeyDB);
}
return Rst;
}
void *ExportICQUserID(HWND hwnd,void *PGPsc,void *PGPtls)
{
PGPKeyDBObjRef DefaultKey;
PGPError err;
BOOL Rst;
PGPContextRef Context;
PGPtlsContextRef tlsContext;
PGPKeyDBObjRef UserID;
void *pOutput;
DWORD dwOutput;
// We need to ensure we are not using the global keydb
// or key iter at the same time in any one function
WaitForSingleObject(hGlobalMutex,INFINITE);
pOutput=NULL;
Rst=FALSE;
Context=(PGPContextRef)PGPsc;
tlsContext=(PGPtlsContextRef)PGPtls;
if(!PGPKeyDBRefIsValid(g_KeyDB))
{
MessageBox(hwnd,
"The keyrings could not be opened.\n\n"
"You probably have PGPkeys open. The\n"
"new version of the SDK will solve this\n"
"problem. Until then, close PGPkeys.\n\n"
"Thank You.","PGP Error",
MB_OK|MB_SETFOREGROUND|MB_ICONINFORMATION);
}
else
{
err=GetLocalUserKey(g_KeyDB,&DefaultKey);
if(IsPGPError(err))
{
MessageBox(hwnd,
"No default key was found.\n\n"
"Please set a default key using PGPkeys",
"PGP Error",
MB_OK|MB_SETFOREGROUND|MB_ICONSTOP);
}
else
{
UserID=GetICQUserID(DefaultKey,g_KeyDB);
if(UserID==NULL)
{
MessageBox(hwnd,
"No ICQ user ID was found on your default key!",
"PGP Error",
MB_OK|MB_SETFOREGROUND|MB_ICONSTOP);
}
else
{
PGPExport(Context,
PGPOExportKeyDBObj(Context,UserID ),
PGPOAllocatedOutputBuffer(
Context, &pOutput, MAX_PGPSize,
&dwOutput),
PGPOLastOption(Context));
}
}
}
// Release Global Mutext on keydb and keyiter
ReleaseMutex(hGlobalMutex);
return pOutput;
}
/*__Editor_settings____
Local Variables:
tab-width: 4
End:
vi: ts=4 sw=4
vim: si
_____________________*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?