LPSTR __cdecl _pgp_decrypt_key(LPCSTR szEncMsg, LPCSTR pgpKey) { #if defined(_WIN64) return 0; #else LPSTR szPlainMsg = 0; PGPSize dwPlainMsgLen; PGPUInt32 dwKeys; PGPKeyDBRef PrivateKeyDB; if (CheckPGPError(_pgp_import_key(&PrivateKeyDB,pgpKey))) return 0; PGPCountKeysInKeyDB(PrivateKeyDB, &dwKeys); if(dwKeys==0) { PGPFreeKeyDB(PrivateKeyDB); return 0; } int iTry = 0; do { if (!pszPassphrase && PGPPassphraseDialog(pgpContext, PGPOUIOutputPassphrase(pgpContext, &pszPassphrase), PGPOLastOption(pgpContext)) == kPGPError_UserAbort) { iTry = 3; break; } PGPError err = PGPDecode(pgpContext, PGPOInputBuffer(pgpContext, szEncMsg, lstrlen(szEncMsg)), PGPOAllocatedOutputBuffer(pgpContext, (LPVOID *)&szPlainMsg, 16384, &dwPlainMsgLen), PGPOKeyDBRef(pgpContext, PrivateKeyDB), PGPOPassphrase(pgpContext, pszPassphrase), PGPOLastOption(pgpContext)); if (CheckPGPError(err)) iTry = 3; else if (!dwPlainMsgLen) { PGPFreeData(pszPassphrase); pszPassphrase = 0; iTry++; } } while(!dwPlainMsgLen && iTry<3); PGPFreeKeyDB(PrivateKeyDB); if(iTry == 3) return 0; LPSTR szMsg = (LPSTR) LocalAlloc(LPTR,dwPlainMsgLen+1); _pgp_memcpy(szMsg, szPlainMsg, dwPlainMsgLen); szMsg[dwPlainMsgLen] = 0; PGPFreeData((LPVOID)szPlainMsg); return szMsg; #endif }
LPSTR __cdecl _pgp_encrypt_key(LPCSTR szPlainMsg, LPCSTR pgpKey) { #if defined(_WIN64) return 0; #else LPSTR szEncMsg = 0; PGPSize dwEncMsgLen; PGPUInt32 dwKeys; PGPKeyDBRef PublicKeyDB; if (CheckPGPError(_pgp_import_key(&PublicKeyDB,pgpKey))) return 0; PGPKeyIterRef KeyIterRef; PGPNewKeyIterFromKeyDB(PublicKeyDB, &KeyIterRef); PGPKeyDBObjRef PublicKey; PGPKeyIterNextKeyDBObj(KeyIterRef, kPGPKeyDBObjType_Key, &PublicKey); PGPCountKeysInKeyDB(PublicKeyDB, &dwKeys); if(dwKeys==0) { PGPFreeKeyIter(KeyIterRef); PGPFreeKeyDB(PublicKeyDB); return 0; } PGPError err = PGPEncode(pgpContext, PGPOInputBuffer(pgpContext, szPlainMsg, lstrlen(szPlainMsg)), PGPOArmorOutput(pgpContext, TRUE), PGPOAllocatedOutputBuffer(pgpContext, (LPVOID *)&szEncMsg, 16384, &dwEncMsgLen), PGPOEncryptToKeyDBObj(pgpContext, PublicKey), PGPOVersionString(pgpContext, szVersionStr), PGPOLastOption(pgpContext)); PGPFreeKeyIter(KeyIterRef); PGPFreeKeyDB(PublicKeyDB); if (CheckPGPError(err)) return 0; LPSTR szMsg = (LPSTR) LocalAlloc(LPTR,dwEncMsgLen+1); _pgp_memcpy(szMsg, szEncMsg, dwEncMsgLen); szMsg[dwEncMsgLen] = 0; PGPFreeData((LPVOID)szEncMsg); return szMsg; #endif }
int __cdecl _pgp_close_keyrings() { #if !defined(_WIN64) if (pgpKeyDB) { PGPFreeKeyDB(pgpKeyDB); pgpKeyDB = 0; } #endif return 1; }
int __cdecl _pgp_close_keyrings() { #if (PGP_WIN32 < 0x700) if (pgpKeyDB) { PGPFreeKeySet(pgpKeyDB); pgpKeyDB = 0; } #else if (pgpKeyDB) { PGPFreeKeyDB(pgpKeyDB); pgpKeyDB = 0; } #endif return 1; }
PVOID __cdecl _pgp_select_keyid(HWND hDlg,LPSTR szKeyID) { #if defined(_WIN64) return 0; #else PGPKeyDBRef ContactKeyDB; PGPError err; err = PGPRecipientDialog(pgpContext, pgpKeyDB, TRUE, &ContactKeyDB, PGPOUIParentWindowHandle(pgpContext, hDlg), PGPOUIWindowTitle(pgpContext, "Select Contact's Key"), PGPOLastOption(pgpContext)); if (err == kPGPError_UserAbort) return 0; PGPUInt32 dwKeys; PGPCountKeysInKeyDB(ContactKeyDB, &dwKeys); if (!dwKeys) return 0; if (dwKeys > 1) MessageBox(hDlg, "You selected more than one key. Only the first key will be used.", szModuleName, MB_ICONINFORMATION); static PGPKeyID KeyID; PGPKeyIterRef KeyIterRef; PGPNewKeyIterFromKeyDB(ContactKeyDB, &KeyIterRef); PGPKeyDBObjRef KeyDBObjRef; PGPKeyIterNextKeyDBObj(KeyIterRef, kPGPKeyDBObjType_Key, &KeyDBObjRef); PGPSize dwFilled; PGPGetKeyDBObjDataProperty(KeyDBObjRef, kPGPKeyProperty_KeyID, &KeyID, sizeof(PGPKeyID), &dwFilled); PGPGetKeyIDString(&KeyID, kPGPKeyIDString_Abbreviated, szKeyID); PGPFreeKeyIter(KeyIterRef); PGPFreeKeyDB(ContactKeyDB); return (PVOID)&KeyID; #endif }
int __cdecl _pgp_done() { pgpVer = 0; #if defined(_WIN64) return 0; #else __try { if(pgpErrMsg) LocalFree(pgpErrMsg); if (pszPassphrase) PGPFreeData(pszPassphrase); if (pgpKeyDB) PGPFreeKeyDB(pgpKeyDB); PGPFreeContext(pgpContext); PGPsdkUILibCleanup(); PGPsdkCleanup(); pszPassphrase = pgpErrMsg = 0; pgpKeyDB = 0; pgpContext = 0; } __except ( EXCEPTION_EXECUTE_HANDLER ) { return 0; } return 1; #endif }
LPSTR __cdecl _pgp_decrypt_key(LPCSTR szEncMsg, LPCSTR pgpKey) { LPSTR szPlainMsg = 0; DWORD dwPlainMsgLen; PGPUInt32 dwKeys; #if (PGP_WIN32 < 0x700) PGPKeySetRef PrivateKeyDB; if (CheckPGPError(_pgp_import_key(&PrivateKeyDB,pgpKey))) return 0; PGPCountKeys(PrivateKeyDB, &dwKeys); #else PGPKeyDBRef PrivateKeyDB; if (CheckPGPError(_pgp_import_key(&PrivateKeyDB,pgpKey))) return 0; PGPCountKeysInKeyDB(PrivateKeyDB, &dwKeys); #endif if(dwKeys==0) { #if (PGP_WIN32 < 0x700) PGPFreeKeySet(PrivateKeyDB); #else PGPFreeKeyDB(PrivateKeyDB); #endif return 0; } int iTry = 0; do { if (!pszPassphrase && PGPPassphraseDialog(pgpContext, PGPOUIOutputPassphrase(pgpContext, &pszPassphrase), PGPOLastOption(pgpContext)) == kPGPError_UserAbort) { iTry = 3; break; } /* #if (PGP_WIN32 < 0x700) PGPKeyListRef PrivateKeyList; PGPOrderKeySet(PrivateKeyDB, kPGPKeyIDOrdering, &PrivateKeyList); PGPKeyIterRef KeyIterRef; PGPNewKeyIter(PrivateKeyList, &KeyIterRef); PGPKeyRef PrivateKey; for(int i=0;i<dwKeys;i++) { PGPKeyIterNext(KeyIterRef, &PrivateKey); PGPOPassphraseIsValid(PrivateKey, PGPOPassphrase(pgpContext, pszPassphrase), PGPOLastOption(pgpContext)); } PGPFreeKeyList(PrivateKeyList); PGPFreeKeyIter(KeyIterRef); #else PGPKeyIterRef KeyIterRef; PGPNewKeyIterFromKeyDB(PrivateKeyDB, &KeyIterRef); PGPKeyDBObjRef KeyDBObjRef; for(int i=0;i<dwKeys;i++) { PGPKeyIterNextKeyDBObj(KeyIterRef, kPGPKeyDBObjType_Key, &KeyDBObjRef); PGPOPassphraseIsValid(PrivateKey, PGPOPassphrase(pgpContext, pszPassphrase), PGPOLastOption(pgpContext)); } PGPFreeKeyIter(KeyIterRef); #endif */ PGPError err = PGPDecode(pgpContext, PGPOInputBuffer(pgpContext, szEncMsg, lstrlen(szEncMsg)), PGPOAllocatedOutputBuffer(pgpContext, (LPVOID *)&szPlainMsg, 16384, (PGPUInt32 *)&dwPlainMsgLen), #if (PGP_WIN32 < 0x700) PGPOKeySetRef(pgpContext, PrivateKeyDB), #else PGPOKeyDBRef(pgpContext, PrivateKeyDB), #endif PGPOPassphrase(pgpContext, pszPassphrase), PGPOLastOption(pgpContext)); if (CheckPGPError(err)) iTry = 3; else if (!dwPlainMsgLen) { PGPFreeData(pszPassphrase); pszPassphrase = 0; iTry++; } } while(!dwPlainMsgLen && iTry<3); #if (PGP_WIN32 < 0x700) PGPFreeKeySet(PrivateKeyDB); #else PGPFreeKeyDB(PrivateKeyDB); #endif if(iTry == 3) return 0; LPSTR szMsg = (LPSTR) LocalAlloc(LPTR,dwPlainMsgLen+1); _pgp_memcpy(szMsg, szPlainMsg, dwPlainMsgLen); szMsg[dwPlainMsgLen] = 0; PGPFreeData((LPVOID)szPlainMsg); return szMsg; }
BOOL EncryptSignRichEditText(char** ppBuffer, long* pLength, BOOL bEncrypt, BOOL bSign, char** pAddresses, long NumAddresses, char* pAttachments, char** ppOutAttachments) { BOOL ReturnValue = FALSE; void* pOutput = NULL; long outSize = 0; PGPError error = kPGPError_NoErr; PGPOptionListRef userOptions = NULL; PGPclRecipientDialogStruct *prds = NULL; char szExe[256]; char szDll[256]; LoadString(g_hinst, IDS_EXE, szExe, sizeof(szExe)); LoadString(g_hinst, IDS_DLL, szDll, sizeof(szDll)); // allocate a recipient dialog structure prds = (PGPclRecipientDialogStruct *) calloc(sizeof(PGPclRecipientDialogStruct), 1); if (!prds) { PGPclErrorBox(g_hwndEudoraMainWindow, kPGPError_OutOfMemory); return FALSE; } error = PGPclOpenDefaultKeyrings(g_pgpContext, kPGPOpenKeyDBFileOptions_Mutable, &(prds->keydbOriginal)); if (IsPGPError(error)) error = PGPclOpenDefaultKeyrings(g_pgpContext, kPGPOpenKeyDBFileOptions_None, &(prds->keydbOriginal)); if (IsPGPError(error)) { char szTitle[255]; char szBuffer[1024]; LoadString(g_hinst, IDS_DLL, szTitle, 254); LoadString(g_hinst, IDS_Q_NOKEYRINGS, szBuffer, 1023); if (MessageBox(g_hwndEudoraMainWindow, szBuffer, szTitle, MB_YESNO)) { char szPath[MAX_PATH]; PGPclGetPath(kPGPclPGPkeysExeFile, szPath, MAX_PATH-1); PGPclExecute(szPath, SW_SHOW); } return S_FALSE; } if(prds && bEncrypt) { char szTitle[256] = {0x00}; // title for recipient dialog UINT recipientReturn = FALSE; // recipient dialog result LoadString(GetModuleHandle("PGPplugin.dll"), IDS_TITLE_RECIPIENTDIALOG, szTitle, sizeof(szTitle)); if( IsntPGPError(error) ) { prds->context = g_pgpContext; prds->tlsContext = g_tlsContext; prds->Version = kPGPCurrentRecipVersion; prds->hwndParent = g_hwndEudoraMainWindow; prds->szTitle = szTitle; prds->dwOptions = kPGPclASCIIArmor; prds->dwDisableFlags = kPGPclDisableWipeOriginal | kPGPclDisableASCIIArmor | kPGPclDisableSelfDecryptingArchive | kPGPclDisableInputIsText; prds->dwNumRecipients = NumAddresses; prds->szRecipientArray = pAddresses; // If shift is pressed, force the dialog to pop. if (GetAsyncKeyState( VK_CONTROL) & 0x8000) prds->dwDisableFlags |= kPGPclDisableAutoMode; // See who we wish to encrypt this to recipientReturn = PGPclRecipientDialog( prds ); } if (prds->keydbAdded != NULL) { PGPUInt32 numKeys; PGPKeySetRef keySet; PGPNewKeySet(prds->keydbAdded, &keySet); PGPCountKeys(keySet, &numKeys); if (numKeys > 0) PGPclImportKeys(g_pgpContext, g_tlsContext, prds->hwndParent, keySet, prds->keydbOriginal, kPGPclNoDialogForValidSingletons); PGPFreeKeySet(keySet); PGPFreeKeyDB(prds->keydbAdded); prds->keydbAdded = NULL; } if (!recipientReturn) { if (prds->keydbSelected != NULL) PGPFreeKeyDB(prds->keydbSelected); PGPFreeKeyDB(prds->keydbOriginal); free(prds); return FALSE; } } if( IsntPGPError(error) ) { error = EncryptSignBuffer(g_hinst, g_hwndEudoraMainWindow, g_pgpContext, g_tlsContext, szExe, szDll, *ppBuffer, *pLength, prds, NULL, &userOptions, &pOutput, &outSize, bEncrypt, bSign, FALSE, FALSE); } else { PGPclEncDecErrorBox(g_hwndEudoraMainWindow, error); } *pLength = outSize; if( IsntPGPError(error) ) { if( pOutput ) { *ppBuffer = (char*)HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, *ppBuffer, *pLength + 1); if(*ppBuffer) { ReturnValue = TRUE; memcpy(*ppBuffer, (char*)pOutput, *pLength); *(*ppBuffer + *pLength) = 0x00; // NULL terminate the string memset(pOutput, 0x00, *pLength); } else { error = kPGPError_OutOfMemory; } PGPFreeData(pOutput); } } // are there attachments? if(IsntPGPError(error) && pAttachments && *pAttachments) { error = EncryptAttachments( pAttachments, ppOutAttachments, prds, userOptions, bEncrypt, bSign); } if(userOptions != NULL) { PGPFreeOptionList(userOptions); } if (prds) { if (prds->keydbSelected != NULL) PGPFreeKeyDB(prds->keydbSelected); PGPFreeKeyDB(prds->keydbOriginal); free(prds); } return ReturnValue; }