📄 searchproc.c
字号:
PGPFreeTLSSession( tls );
tls = kInvalidPGPtlsSessionRef;
}
if( IsntPGPError( error ) )
{
EnterCriticalSection(keyserverLock);
ComboBox_SetItemData( hwndLocation,
lastSearchIndex,
*pKeySetOut);
LeaveCriticalSection(keyserverLock);
break;
}
}
}
PGPDisposeKeyServerPath(keyserverList);
}
PGPclCloseClientPrefs (prefs, FALSE);
}
if(searchString)
{
free(searchString);
}
}
// peform search on a local KeySet (keyring or mem)
else if(locationSelection == localSearchIndex ||
locationSelection == lastSearchIndex)
{
localKeySet = (PGPKeySetRef) lParam;
if(locationSelection == lastSearchIndex)
{
*flags = lastSearchType;
}
else
{
*flags = FLAG_SEARCH_LOCAL_KEYSET;
SetProp( hwndLocation, "LastSearchType",(HANDLE) *flags);
}
if(localKeySet != kPGPInvalidRef)
{
error = PGPFilterKeySet( localKeySet, psts->filter, pKeySetOut);
if( IsPGPError(error) )
{
*pKeySetOut = kPGPInvalidRef;
}
}
else
{
*pKeySetOut = kPGPInvalidRef;
}
EnterCriticalSection(keyserverLock);
ComboBox_SetItemData(hwndLocation, lastSearchIndex, *pKeySetOut);
LeaveCriticalSection(keyserverLock);
}
// perform search on specified keyserver
else
{
PGPtlsSessionRef tls = kInvalidPGPtlsSessionRef;
PGPKeyServerEntry* entry = NULL;
*flags = FLAG_SEARCH_MEMORY;
SetProp( hwndLocation, "LastSearchType",(HANDLE) *flags);
// retrieve keyserver entry from control
entry = (PGPKeyServerEntry*)lParam;
if( entry )
{
error = PGPNewKeyServerFromHostName(
g_Context,
entry->serverDNS,
entry->serverPort,
entry->protocol,
accessType,
(bPending ? kPGPKeyServerKeySpace_Pending :
kPGPKeyServerKeySpace_Default),
&psts->server );
memcpy(&(psts->keyserverEntry),
entry, sizeof(PGPKeyServerEntry));
}
else
{
error = kPGPError_OutOfMemory;
}
if( IsntPGPError( error ) )
{
error = PGPSetKeyServerEventHandler( psts->server,
SearchEventHandler, psts );
if ( IsntPGPError( error ) )
{
if( kPGPKeyServerType_LDAPS == entry->protocol ||
kPGPKeyServerType_HTTPS == entry->protocol)
{
error = PGPNewTLSSession( g_TLSContext,
&tls );
if( IsPGPError(error) )
{
// warn beyond the icon?
tls = kInvalidPGPtlsSessionRef;
}
}
error = PGPKeyServerOpen( psts->server, tls );
if ( IsntPGPError(error) )
{
error = PGPQueryKeyServer( psts->server,
psts->filter,
pKeySetOut);
PGPKeyServerClose ( psts->server );
}
}
PGPFreeKeyServer( psts->server );
psts->server = kInvalidPGPKeyServerRef;
if( PGPtlsSessionRefIsValid(tls) )
{
PGPFreeTLSSession( tls );
tls = kInvalidPGPtlsSessionRef;
}
if( (IsntPGPError( error )) ||
(error == kPGPError_ServerPartialSearchResults ))
{
EnterCriticalSection(keyserverLock);
ComboBox_SetItemData( hwndLocation,
lastSearchIndex,
*pKeySetOut);
LeaveCriticalSection(keyserverLock);
}
}
}
PGPKeyServerDisposeThreadStorage(previousStorage);
PGPKeyServerCleanup();
return error;
}
DWORD WINAPI SearchThreadRoutine (LPVOID lpvoid)
{
PSEARCHTHREADSTRUCT psts = (PSEARCHTHREADSTRUCT) lpvoid;
SEARCHRESULT result;
PGPKeySetRef keySet = kPGPInvalidRef;
HWND hwnd = psts->hwnd;
HWND hwndLocation = NULL;
HWND hwndSearch = NULL;
HWND hwndStop = NULL;
HWND hwndPending = NULL;
long flags = 0;
BOOL bPending = FALSE;
PGPError error = kPGPError_NoErr;
hwndLocation = GetDlgItem(hwnd, IDC_LOCATION);
hwndSearch = GetDlgItem(hwnd, IDC_SEARCH);
hwndStop = GetDlgItem(hwnd, IDC_STOP);
hwndPending = GetDlgItem(hwnd, IDC_PENDING);
bPending = Button_GetCheck(hwndPending);
error = PerformSearch( hwndLocation,
psts,
bPending,
&flags,
&keySet);
memset(&result, 0x00, sizeof(result));
if( IsntPGPError(error) ||
(error == kPGPError_ServerPartialSearchResults))
{
result.pData = keySet;
result.flags = flags;
result.error = error;
memcpy(&(result.keyserver),
&(psts->keyserverEntry),
sizeof(PGPKeyServerEntry));
if(bPending)
{
result.flags |= FLAG_AREA_PENDING;
}
}
else
{
result.pData = NULL;
result.flags = 0;
result.error = error;
}
result.nmhdr.hwndFrom = hwnd;
result.nmhdr.idFrom = IDD_SEARCH;
result.nmhdr.code = SEARCH_DISPLAY_KEYSET;
SendMessage(GetParent(hwnd),
WM_NOTIFY,
(WPARAM)hwnd,
(LPARAM)&result);
if ( psts->filter )
PGPFreeFilter ( psts->filter );
memset(psts, 0x00, sizeof(SEARCHTHREADSTRUCT));
EnableWindow(hwndStop, FALSE);
ShowWindow(hwndStop, SW_HIDE);
ShowWindow(hwndSearch, SW_SHOW);
EnableWindow(hwndSearch, TRUE);
return 0;
}
// ____________________________________
//
// translate keyserver state to string index
static INT
sTranslateKSMessage (INT iKSmessage)
{
switch (iKSmessage) {
case kPGPKeyServerState_Opening :
return IDS_SEARCH_MESSAGE_CONNECTING;
case kPGPKeyServerState_Querying:
return IDS_SEARCH_MESSAGE_QUERYING;
case kPGPKeyServerState_ReceivingResults :
return IDS_SEARCH_MESSAGE_RECEIVING;
case kPGPKeyServerState_ProcessingResults :
return IDS_SEARCH_MESSAGE_PROCESSING;
case kPGPKeyServerState_Uploading :
return IDS_SEARCH_MESSAGE_SENDING;
case kPGPKeyServerState_Deleting :
return IDS_SEARCH_MESSAGE_DELETING;
case kPGPKeyServerState_Disabling :
return IDS_SEARCH_MESSAGE_DISABLING;
case kPGPKeyServerState_Closing :
return IDS_SEARCH_MESSAGE_CLOSING;
default :
// case kPGPKeyServerState_TLSUnableToSecureConnection :
// case kPGPKeyServerState_TLSConnectionSecured :
return IDS_SEARCH_MESSAGE_BASE;
}
}
PGPError SearchEventHandler(PGPContextRef context,
PGPEvent *event,
PGPUserValue userValue)
{
PGPError error = kPGPError_NoErr;
PSEARCHTHREADSTRUCT psts;
psts = (PSEARCHTHREADSTRUCT) userValue;
switch(event->type)
{
case kPGPEvent_ErrorEvent:
{
PGPEventErrorData data = event->data.errorData;
if(data.error == kPGPError_UserAbort)
{
psts->bCancel = TRUE;
return kPGPError_NoErr;
}
break;
}
case kPGPEvent_KeyServerEvent:
{
PGPEventKeyServerData data = event->data.keyServerData;
SEARCHPROGRESS progress;
int index;
memset(&progress, 0x00, sizeof(progress));
progress.nmhdr.hwndFrom = psts->hwnd;
progress.nmhdr.idFrom = IDD_SEARCH;
progress.nmhdr.code = SEARCH_PROGRESS;
progress.step = SEARCH_PROGRESS_INFINITE; // data.soFar;//
progress.total = SEARCH_PROGRESS_INFINITE;// data.total;//
if(!psts->bCancel)
{
index = data.state;
}
else
{
index = IDS_SEARCH_MESSAGE_CANCEL;
progress.step = 0;
progress.total = 0;
}
index = sTranslateKSMessage (index);
LoadString( g_hInst,
index,
progress.message,
sizeof(progress.message));
SendMessage(GetParent(psts->hwnd),
WM_NOTIFY,
(WPARAM)psts->hwnd,
(LPARAM)&progress);
break;
}
case kPGPEvent_KeyServerTLSEvent:
{
PGPEventKeyServerTLSData data = event->data.keyServerTLSData;
SEARCHSECURE secure;
memset(&secure, 0x00, sizeof(secure));
secure.nmhdr.hwndFrom = psts->hwnd;
secure.nmhdr.idFrom = IDD_SEARCH;
secure.nmhdr.code = SEARCH_SECURE_STATUS;
secure.secure = FALSE;
if(data.state == kPGPKeyServerState_TLSConnectionSecured)
{
PGPtlsSessionRef tls =
event->data.keyServerTLSData.tlsSession;
PGPInt32 remoteKeyAlg;
PGPKeyID keyID,
expectedID;
PGPError error;
error =
PGPtlsGetRemoteAuthenticatedKey( tls,
&secure.keyAuth, NULL );
if( IsPGPError( error ) )
break;
error =
PGPtlsGetNegotiatedCipherSuite( tls,
&secure.tlsCipher );
if( IsPGPError( error ) )
break;
PGPGetKeyServerURL(&(psts->keyserverEntry),
secure.szServerName);
error = PGPGetKeyIDFromKey( secure.keyAuth, &keyID );
if( IsPGPError( error ) )
break;
error = PGPGetKeyNumber( secure.keyAuth, kPGPKeyPropAlgID,
&remoteKeyAlg );
if( IsPGPError( error ) )
break;
// check if we already have an auth key from this server
if( psts->keyserverEntry.authAlg !=
kPGPPublicKeyAlgorithm_Invalid )
{
error = PGPGetKeyIDFromString(
psts->keyserverEntry.authKeyIDString,
&expectedID );
if( IsPGPError( error ) )
break;
if( PGPCompareKeyIDs( &expectedID, &keyID ) )
{
error = PGPclConfirmRemoteAuthentication (
g_Context,
psts->hwnd,
secure.szServerName,
secure.keyAuth,
secure.tlsCipher,
psts->keySet,
PGPCL_AUTHUNEXPECTEDKEY);
// if user approve
if(IsntPGPError(error))
{
NMHDR nmhdr;
error = PGPGetKeyIDString( &keyID,
kPGPKeyIDString_Full,
psts->keyserverEntry.authKeyIDString );
if( IsPGPError( error ) )
break;
psts->keyserverEntry.authAlg =
(PGPPublicKeyAlgorithm) remoteKeyAlg;
PGPclSyncKeyserverPrefs(g_Context,
&(psts->keyserverEntry));
secure.secure = TRUE;
nmhdr.hwndFrom = psts->hwnd;
nmhdr.idFrom = IDD_SEARCH;
nmhdr.code = REFRESH_KEYSERVER_LIST;
SendMessage(psts->hwnd,
WM_NOTIFY,
(WPARAM)psts->hwnd,
(LPARAM)&nmhdr);
}
}
else
{
error = PGPclConfirmRemoteAuthentication (
g_Context,
psts->hwnd,
secure.szServerName,
secure.keyAuth,
secure.tlsCipher,
psts->keySet,
PGPCL_AUTHEXPECTEDKEY);
// if user approve
if(IsntPGPError(error))
{
secure.secure = TRUE;
}
}
}
// this is the first time we're talking to this server
else
{
error = PGPclConfirmRemoteAuthentication (
g_Context,
psts->hwnd,
secure.szServerName,
secure.keyAuth,
secure.tlsCipher,
psts->keySet,
PGPCL_AUTHNEWKEY);
// if user approve
if(IsntPGPError(error))
{
NMHDR nmhdr;
error = PGPGetKeyIDString( &keyID,
kPGPKeyIDString_Full,
psts->keyserverEntry.authKeyIDString );
if( IsPGPError( error ) )
break;
psts->keyserverEntry.authAlg =
(PGPPublicKeyAlgorithm) remoteKeyAlg;
PGPclSyncKeyserverPrefs(g_Context,
&(psts->keyserverEntry));
secure.secure = TRUE;
nmhdr.hwndFrom = psts->hwnd;
nmhdr.idFrom = IDD_SEARCH;
nmhdr.code = REFRESH_KEYSERVER_LIST;
SendMessage(psts->hwnd,
WM_NOTIFY,
(WPARAM)psts->hwnd,
(LPARAM)&nmhdr);
}
}
if (secure.secure != TRUE)
{
SEARCHABORT abort;
psts->bCancel = TRUE;
memset(&abort, 0x00, sizeof(abort));
abort.nmhdr.hwndFrom = psts->hwnd;
abort.nmhdr.idFrom = IDD_SEARCH;
abort.nmhdr.code = SEARCH_ABORT;
abort.error = kPGPError_UserAbort;
SendMessage(GetParent(psts->hwnd),
WM_NOTIFY,
(WPARAM)psts->hwnd,
(LPARAM)&abort);
}
}
else if(data.state ==
kPGPKeyServerState_TLSUnableToSecureConnection)
{
secure.secure = FALSE;
}
SendMessage(GetParent(psts->hwnd),
WM_NOTIFY,
(WPARAM)psts->hwnd,
(LPARAM)&secure);
break;
}
case kPGPEvent_FinalEvent:
{
psts->bAlreadyAsked = FALSE;
break;
}
}
if( psts->bCancel )
{
error = kPGPError_UserAbort;
}
return error;
}
void GrabUserIdStrings(HWND hwnd,
char** string,
int* length)
{
PCHOICE choice = NULL;
HWND hwndEdit = NULL;
HWND hwndAttribute = NULL;
int AttributeSelection = 0;
int userIdSelection = 0;
*string = NULL;
*length = 0;
hwndAttribute = GetDlgItem(hwnd, IDC_ATTRIBUTE);
hwndEdit = GetDlgItem(hwnd, IDC_SPECIFIER_EDIT);
AttributeSelection = ComboBox_GetCurSel(hwndAttribute);
if(AttributeSelection == 0) // User Id
{
*length = Edit_GetTextLength(hwndEdit) + 1;
*string = (char*)malloc(*length);
if( *string )
{
Edit_GetText( hwndEdit,
*string,
*length);
}
}
// now iterate the children if there are any
choice = FirstChoice(hwnd);
while( choice )
{
hwndAttribute = GetDlgItem(choice->hwnd, IDC_ATTRIBUTE);
hwndEdit = GetDlgItem(choice->hwnd, IDC_SPECIFIER_EDIT);
AttributeSelection = ComboBox_GetCurSel(hwndAttribute);
if(AttributeSelection == 0) // User Id
{
int tempLength = 0;
tempLength = *length + Edit_GetTextLength(hwndEdit) + 1;
if(!(*string))
{
*string = (char*)malloc(tempLength);
}
else
{
*string = (char*)realloc(*string, tempLength);
}
if( *string )
{
if(*length)
{
*(*string + *length - 1) = 0x20; // add space
}
Edit_GetText( hwndEdit,
*string + *length,
tempLength);
*length = tempLength;
}
}
choice = NextChoice(hwnd, choice);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -