コード例 #1
0
ファイル: FileOperations.cpp プロジェクト: TecSec/OpenVEIL
bool  FileVEILOperationsImpl::EncryptFileAndStreams(const tscrypto::tsCryptoString& sFile, const tscrypto::tsCryptoString& sEncrFile, std::shared_ptr<ICmsHeader> header, CompressionType comp, TS_ALG_ID algorithm, TS_ALG_ID hashAlgorithm, bool SignHeader, bool bindData, CMSFileFormatIds DataFormat, bool randomIvec, SymmetricPaddingType paddingType, int blockSize)
{
	TSDECLARE_FUNCTIONExt(true);

	bool retVal = false;
	tscrypto::tsCryptoStringList streamList = CreateTsAsciiList();
	tscrypto::tsCryptoString sTempFile;

	m_taskCount = 1;
	m_currentTask = 1;
	// Delete temp file, in case it exists.
	sTempFile = sEncrFile;
	sTempFile += ".tmp";
	xp_DeleteFile(sTempFile.c_str());

	// Enumerate all streams associated with given file.
	if (::GetStreamNames(sFile, streamList))
	{
		// Encrypt each stream.
		size_t Pos;
		tscrypto::tsCryptoString sStream;
		tscrypto::tsCryptoString sEncrStream;
		tscrypto::tsCryptoString sTempStream;
		tscrypto::tsCryptoString sNamedStream;
		size_t streamCount;

		streamCount = streamList->size();
		m_taskCount += (DWORD)streamCount;

		for (Pos = 0; Pos < streamCount; Pos++)
		{
			sNamedStream = streamList->at(Pos);
			sStream = sFile + sNamedStream;
			sEncrStream = sEncrFile + sNamedStream;
			sTempStream = sTempFile + sNamedStream;
			retVal = EncryptSignFile(sStream, sEncrStream, sTempStream, header, comp, algorithm, hashAlgorithm, SignHeader, bindData, DataFormat, randomIvec, paddingType, blockSize);
			m_currentTask++;
		}
	}

	// Encrypt main stream last, for proper copying/deleting of temp file.
	retVal = EncryptSignFile(sFile, sEncrFile, "", header, comp, algorithm, hashAlgorithm, SignHeader, bindData, DataFormat, randomIvec, paddingType, blockSize);

	return TSRETURN(("Returns ~~"), retVal);
}
コード例 #2
0
ファイル: FileOperations.cpp プロジェクト: TecSec/OpenVEIL
bool  FileVEILOperationsImpl::EncryptFile(const tscrypto::tsCryptoString& sFile, const tscrypto::tsCryptoString& sEncrFile, std::shared_ptr<ICmsHeader> header, CompressionType comp, TS_ALG_ID algorithm, TS_ALG_ID hashAlgorithm, bool SignHeader, bool bindData, CMSFileFormatIds DataFormat, bool randomIvec, SymmetricPaddingType paddingType, int blockSize)
{
	bool retVal = false;
	tscrypto::tsCryptoString sTempFile;

	// Delete temp file, in case it exists.
	sTempFile = sEncrFile;
	sTempFile += ".tmp";
	xp_DeleteFile(sTempFile.c_str());

	m_taskCount = 1;
	m_currentTask = 1;

	// Encrypt main stream
	retVal = EncryptSignFile(sFile, sEncrFile, "", header, comp, algorithm, hashAlgorithm, SignHeader, bindData, DataFormat, randomIvec, paddingType, blockSize);

	return retVal;
}
コード例 #3
0
PluginError PerformTranslation(
	short trans_id, 
	char* in_file, 
	char* out_file, 
	char** addresses, 
	emsMIMEtypeP  in_mime,
	emsMIMEtypeP* out_mime
)
{
	PluginError pluginReturn			= EMSR_UNKNOWN_FAIL;
	BOOL		bSign					= FALSE;
	PGPError	error					= 0;
	PGPSize		mimeBodyOffset			= 0;
	char		szExe[256];
	char		szDll[256];

	assert(in_file);
	assert(out_file);

	LoadString(g_hinst, IDS_EXE, szExe, sizeof(szExe));
	LoadString(g_hinst, IDS_DLL, szDll, sizeof(szDll));

	switch( trans_id )
	{
		case kEncryptTranslatorID:
		case kSignTranslatorID:
		case kEncryptAndSignTranslatorID:
		{
			char** RecipientList = NULL;
			unsigned long numRecipients = 0;
			PGPOptionListRef pgpOptions = NULL;
			PGPOptionListRef signOptions = NULL;
			char mimeSeparator[kPGPMimeSeparatorSize];
			PRECIPIENTDIALOGSTRUCT prds = NULL;	
		
			// allocate a recipient dialog structure
			prds = (PRECIPIENTDIALOGSTRUCT) 
					calloc(sizeof(RECIPIENTDIALOGSTRUCT), 1);

			if(prds)
			{
				char szTitle[256] = {0x00};		// title for recipient dialog
				UINT recipientReturn = FALSE;	// recipient dialog result

				error = PGPsdkLoadDefaultPrefs(g_pgpContext);
				if (IsPGPError(error))
				{
					PGPclEncDecErrorBox(g_hwndEudoraMainWindow, error);
					return EMSR_UNKNOWN_FAIL;
				}

				error = PGPOpenDefaultKeyRings(g_pgpContext, 
							(PGPKeyRingOpenFlags)0, 
							&(prds->OriginalKeySetRef));

				if (IsPGPError(error))
				{
					PGPclEncDecErrorBox(g_hwndEudoraMainWindow, error);
					return EMSR_UNKNOWN_FAIL;
				}

				if ((trans_id == kEncryptTranslatorID) ||
					(trans_id == kEncryptAndSignTranslatorID))
				{
					if(addresses) // do we have addresses to pass along
					{
						numRecipients = CreateRecipientList(addresses, 
															&RecipientList);
					}

					LoadString(GetModuleHandle("PGPplugin.dll"), 
						IDS_TITLE_RECIPIENTDIALOG, szTitle, sizeof(szTitle));

					prds->Context			= g_pgpContext;
					prds->tlsContext		= g_tlsContext;
					prds->Version			= CurrentPGPrecipVersion;
					prds->hwndParent		= g_hwndEudoraMainWindow;			
					prds->szTitle			= szTitle;
					prds->dwOptions			= PGPCL_ASCIIARMOR;	
			
					prds->dwDisableFlags	= PGPCL_DISABLE_WIPEORIG |
											  PGPCL_DISABLE_ASCIIARMOR |
											  PGPCL_DISABLE_SDA;

					prds->dwNumRecipients	= numRecipients;	
					prds->szRecipientArray	= RecipientList;

					/* Disable FYEO if there's an attachment or HTML */

					if (in_mime && !match_mime_type(in_mime, "text", "plain"))
						prds->dwDisableFlags |= PGPCL_DISABLE_FYEO;

					// If shift is pressed, force the dialog to pop.
					if (GetAsyncKeyState( VK_CONTROL) & 0x8000)
						prds->dwDisableFlags|=PGPCL_DISABLE_AUTOMODE;

					// See who we wish to encrypt this to
					recipientReturn = PGPclRecipientDialog( prds );
				
					if (prds->AddedKeys != NULL)
					{
						PGPUInt32 numKeys;
					
						PGPCountKeys(prds->AddedKeys, &numKeys);
						if (numKeys > 0)
							PGPclQueryAddKeys(g_pgpContext, g_tlsContext, 
								g_hwndEudoraMainWindow, prds->AddedKeys, 
								NULL);
					
						PGPFreeKeySet(prds->AddedKeys);
						prds->AddedKeys = NULL;
					}

					if (!recipientReturn)
					{
						if (RecipientList)
							FreeRecipientList(RecipientList, numRecipients);
						if (prds->SelectedKeySetRef != NULL)
							PGPFreeKeySet(prds->SelectedKeySetRef);
						PGPFreeKeySet(prds->OriginalKeySetRef);
						free(prds);
						return EMSR_UNKNOWN_FAIL;
					}
				}

				if( IsntPGPError(error) )
				{
					error = PGPBuildOptionList(g_pgpContext, &pgpOptions,
								PGPOOutputLineEndType(g_pgpContext, 
									kPGPLineEnd_CRLF),
								PGPOPGPMIMEEncoding(g_pgpContext, 
									TRUE, 
									&mimeBodyOffset, 
									mimeSeparator),     
								PGPOLastOption(g_pgpContext) );
				}

				if(IsntPGPError( error))
				{
					error = EncryptSignFile(g_hinst, g_hwndEudoraMainWindow, 
								g_pgpContext, g_tlsContext, szExe, 
								szDll, in_file, prds, pgpOptions, 
								&signOptions, out_file, 
								((trans_id == 
									kSignTranslatorID) ? FALSE : TRUE ),
								((trans_id == 
									kEncryptTranslatorID) ? FALSE : TRUE ),
								FALSE);

					PGPFreeOptionList(pgpOptions);
					PGPFreeOptionList(signOptions);
				}
				else
				{
					PGPclEncDecErrorBox (NULL, error);
				}

				if (RecipientList)
					FreeRecipientList(RecipientList, numRecipients);
				if (prds->SelectedKeySetRef != NULL)
					PGPFreeKeySet(prds->SelectedKeySetRef);
				PGPFreeKeySet(prds->OriginalKeySetRef);
				free(prds);

				if( IsntPGPError(error) )
				{
					if( out_mime )
					{
						pluginReturn = BuildEncryptedPGPMIMEType( 
													out_mime, 
													mimeSeparator );

						if(EMSR_OK == pluginReturn)
						{
							pluginReturn = AddMIMEParam(*out_mime, 
														"PGPFormat", 
														"PGPMIME-encrypted" );
						}
					}
				}
			}

			break;
		}

		case kDecryptTranslatorID:
		case kVerifyTranslatorID:
		{
			char *szTempFile = NULL;
			BOOL bFYEO = FALSE;
			void *pOutput = NULL;
			PGPSize outSize = 0;

			error = DecryptVerifyFile(g_hinst, g_hwndEudoraMainWindow, 
						g_pgpContext, g_tlsContext, szExe, szDll, in_file, 
						TRUE, FALSE, &szTempFile, &pOutput, &outSize, &bFYEO);

			if( IsntPGPError(error) ) 
			{
				if ((bFYEO)||(GetSecureViewerPref((void *)g_pgpContext)))
					TempestViewer((void *)g_pgpContext,NULL,pOutput,outSize,
						bFYEO);

				CopyFile(szTempFile, out_file, FALSE);
				DeleteFile(szTempFile);

				if( out_mime )
				{
					ParseFileForMIMEType( out_file, out_mime );
				}

				if ((bFYEO)||(GetSecureViewerPref((void *)g_pgpContext)))
					pluginReturn = EMSR_UNKNOWN_FAIL;
				else
					pluginReturn = EMSR_OK;
			}

			if (szTempFile != NULL)
				PGPFreeData(szTempFile);
			if (pOutput != NULL)
				PGPFreeData(pOutput);
			break;
		}

	}

	return pluginReturn;
}
コード例 #4
0
PGPError EncryptAttachments(char* pInAttachments, 
							char** ppOutAttachments,
							PGPclRecipientDialogStruct *prds,
							PGPOptionListRef userOptions,
							BOOL bEncrypt,
							BOOL bSign)
{
	PGPError error = kPGPError_NoErr;
	char in_file[MAX_PATH] = {0x00};
	char out_file[MAX_PATH] = {0x00};
	char* pInAttachBackup = NULL;
	char* token = NULL;
	long size = 0;
	char szExe[256];
	char szDll[256];

	LoadString(g_hinst, IDS_EXE, szExe, sizeof(szExe));
	LoadString(g_hinst, IDS_DLL, szDll, sizeof(szDll));

	size = strlen(pInAttachments);

	pInAttachBackup = malloc(size + 1);

	if( !pInAttachBackup )
	{
		return kPGPError_OutOfMemory;
	}
	else
	{
		strcpy(pInAttachBackup, pInAttachments);
	}

	*ppOutAttachments = malloc(size*2);

	if( !*ppOutAttachments )
	{
		free(pInAttachBackup);
		return kPGPError_OutOfMemory;
	}

	// NULL terminate
	**ppOutAttachments = 0x00;

	token = strtok(pInAttachments,";");

	while(token)
	{
		// strip off leading spaces or tabs
		while( *token == ' ' || *token == '\t')
		{
			token++;
		}

		strcpy(in_file, token);
		strcpy(out_file, token);
		strcat(out_file, ".pgp");

		if(VerifyOutputFileName(out_file))
		{
			strcat(*ppOutAttachments, out_file);
			strcat(*ppOutAttachments, ";");

			error = EncryptSignFile(g_hinst, g_hwndEudoraMainWindow, 
						g_pgpContext, g_tlsContext, szExe, szDll, in_file,
						prds, NULL, &userOptions, out_file, bEncrypt, bSign,
						TRUE);
		}
		else
		{
			strcpy(*ppOutAttachments, pInAttachBackup);
			error = kPGPError_UserAbort;
			break;
		}

		token = strtok(NULL,";");	
	}

	if(pInAttachBackup)
	{
		free(pInAttachBackup);
	}

	return error;
}