⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pgphandling.c

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 C
📖 第 1 页 / 共 2 页
字号:
/*______________________________________________________________________________
	Copyright (C) 2002 PGP Corporation
	All rights reserved.


	$Id: PgpHandling.c,v 1.19 2002/11/21 22:59:34 sdas Exp $
______________________________________________________________________________*/

/*::: MODULE OVERVIEW :::::::::::::
Module provides a staging area from which calls into regular PGP source code 
may be made. Customized to the needs of the Lotus Notes PGP Plug-In.

--- revision history --------
11/13/02 Version 1.1.6.1 Paul Ryan
+ logic enhancement to fix bug in ei_FindAndDecodePgpBlock()

10/30/02 Version 1.1.6 Paul Ryan
+ signature change to ei_ResolveEncryptionKeys() in conjunction with 
  finer-grained handling of PGP key-server searches
+ logic adjustment of ei_PgpLookupEmailViaServers() to support better 
  user-cancelation and timeout of key-server searches
+ listing format adjustment, documentation adjustment, token renaming

9/6/02 Version 1.1.5 Paul Ryan
+ workarounds to PGP decoding-engine oddities in ei_TestForPgpAscii(), 
  i_GetPgpAsciiCoords(), i_DecryptVerify() & ei_FindAndDecodePgpBlock()
+ listing format adjustment, minor documentation adjustment, token renaming

7/2/01 Version 1.1.4.1 Paul Ryan
+ minor string adjustment

9/16/00 Version 1.1.4 Paul Ryan
+ added functions for PGP wiping & decoding files

8/9/00 Version 1.1.3 Paul Ryan
+ accommodated recent change made to the DecodeEventData structure used in 
  the PGP shared code, whose functionality is somewhat reproduced in this 
  module

3/20/00 Version 1.1.2 Paul Ryan
+ adjustment to support PGP 7.0

9/26/99 Version 1.1.1 Paul Ryan
+ worked around minor bug in PGP client code (see ei_FindAndDecodePgpBlock() 
  for details)

9/12/99 Version 1.1 Paul Ryan
+ PGP 6.5.1 compatibility
+ logic enhancements
+ documentation updates

12/18/98 Version 1.0 Paul Ryan
::::::::::::::::::::::::::::::::::::*/

#include "PgpHandling.h"


//global-scope declarations
char  epc_APPNM[] = "PGP Lotus Notes Plugin";
const int  ei_USER_ABORT = kPGPError_UserAbort;

HWND  eh_mainWnd;


//module-scope declarations
static char  mpc_PLUGIN_APP[] = "Notes", mpc_MODULENM[] = "ndbPGP.dll";

static PGPContextRef  m_pgpContext = kInvalidPGPContextRef;
static PGPtlsContextRef  m_pgpTlsContext = kInvalidPGPtlsContextRef;


/** ei_InitializePgpContext( ***
Purpose is to set up the ability for this DLL to make calls into the PGP SDK 
and related functionality.

--- return -------------
RETURN: kPGPError_NoErr if no error occurred; a PGP error code otherwise.

--- revision history ---
7/2/01 PR: listing format adjustment
3/20/00 PR: adjustment to support Notes R5 and PGP 7.0
9/12/99 PR: documentation adjustment
11/23/98 PR: created		*/
PGPError ei_InitializePgpContext()	{
	const char  pc_CLASSNM_NOTES[] = "NOTES", 
				pc_CLASSNM_NOTES_FRAME[] = "NOTESframe";

	HWND  h;
	char pc[ sizeof( pc_CLASSNM_NOTES_FRAME) > sizeof( pc_CLASSNM_NOTES) ? 
											sizeof( pc_CLASSNM_NOTES_FRAME) : 
											sizeof( pc_CLASSNM_NOTES)];
	PGPError  i_err;
	static BOOL  ef_LicenseExpired = FALSE;//static to suppress too much nagging
										   //when user is using the notes after
										   //license for the plugin has expired

	//if we have expired we just get out with error
	if(TRUE == ef_LicenseExpired)
		return kPGPError_Win32_Expired;

	//if the PGP environment has already been loaded, don't do it again
	if (PGPContextRefIsValid( m_pgpContext))
		return kPGPError_NoErr;

	//Store the handle of the main window associated with the rich-text 
	//	window currently being operated on by user. Loop is used because 
	//	the different releases of Notes have different window hierarchies.
	if (h = GetFocus())	{
		do
			if (GetClassName( h, pc, sizeof( pc)))
				if (strcmp( pc, pc_CLASSNM_NOTES) == ei_SAME || strcmp( pc, 
										pc_CLASSNM_NOTES_FRAME) == ei_SAME)	{
					eh_mainWnd = h;
					break;
				}
		while (h = GetParent( h));
		if (!eh_mainWnd)
			MessageBox( NULL, "The parent Lotus Notes window\ncould not be "
													"determined", epc_APPNM, 
													MB_OK | MB_ICONEXCLAMATION);
	} //if (h = GetFocus())

	//create a new PGP context to use in this DLL & initialize the 
	//	PGP Common Libraries
	if (IsPGPError( i_err = PGPclInitLibrary( &m_pgpContext, 
														(PGPUInt32) NULL)))	{
		if (i_err == kPGPError_FeatureNotAvailable)	{
			const char  pc_EXPIRED_MSG[] = "The evaluation period for PGP has "
											"passed.\nThe Lotus Notes Plug-In "
											"will no longer function.", 
						pc_EXPIRED_TITLE[] = "PGP Plug-In Expired";

			MessageBox( eh_mainWnd, pc_EXPIRED_MSG, pc_EXPIRED_TITLE, MB_OK);
		}else
			PGPclErrorBox( eh_mainWnd, i_err);

		PGPclCloseLibrary();
		m_pgpContext = kInvalidPGPContextRef;
		return i_err;
	} //if (IsPGPError( i_err = PGPclInitLibrary(

	//if this license has expired, return failure
	if (IsPGPError( i_err = PGPclIsExpired( eh_mainWnd, 
													kPGPclDefaultExpired)))	{
		ef_LicenseExpired = TRUE;//remember the license has expired
		PGPclCloseLibrary();
		m_pgpContext = kInvalidPGPContextRef;
		return i_err;
	}

	if (IsPGPError( i_err = PGPNewTLSContext( m_pgpContext, 
														&m_pgpTlsContext)))	{
		PGPclCloseLibrary();
		m_pgpContext = kInvalidPGPContextRef;
		return i_err;
	}

	return IsPGPError( i_err) ? i_err : kPGPError_NoErr;
} //ei_InitializePgpContext(


/** ei_PgpEncodeBuffer( ***
PGP encode the content buffer provided.

--- parameters & return ----
PC: Address of the input content to be encoded. If content is ASCII, content 
	should be null-terminated.
ul_LEN: length of the input content to be encoded
pt_context: Input & Output. Address of information structure
f_BINARY: flag telling whether the input content is	binary in nature, not 
	ASCII
pl_lenOutput: Optional. Pointer to the variable in which to store the length 
	of the PGP-encoded output content. If passed in null, this functionality 
	will be ignored by the procedure.
ppc_output: Memory address of the pointer in which to store the address of 
	the memory buffer allocated to accommodate the null-terminated 
	PGP-encoded output. Caller is responsible for freeing this memory buffer. 
	In case of an error, the pointer is guaranteed to be null.
RETURN: kPGPError_NoErr if no error occurred; a PGP error code otherwise.

--- revision history -------
3/20/00 PR
+ logic adjustment to support PGP 7.0
+ standard documentation completed

12/10/98 PR: created		*/
PGPError ei_PgpEncodeBuffer( char *const  PC, 
								const DWORD  ul_LEN, 
								PgpEncodeContext *const  pt_context, 
								const BOOL  f_BINARY, 
								long *const  pl_lenOutput, 
								char * *const  ppc_output)	{
	PGPOptionListRef  oneTimeOptions;
	long  l_lenOutput;
	PGPError  i_err, i_error;

	if (!( PC && pt_context && (pt_context->f_Sign || 
										pt_context->f_Encrypt) && ppc_output))
		return !kPGPError_NoErr;

	if (pl_lenOutput)
		*pl_lenOutput = (DWORD) NULL;
	*ppc_output = NULL;

	//if this is a buffer of binary data and it just needs to be signed, 
	//	have it encoded with ASCII Armor
	if (f_BINARY && pt_context->f_Sign && !pt_context->f_Encrypt)
		i_err = PGPBuildOptionList( m_pgpContext, &oneTimeOptions, 
										PGPOArmorOutput( m_pgpContext, TRUE), 
										PGPOLastOption( m_pgpContext));
	else
		i_err = PGPBuildOptionList( m_pgpContext, &oneTimeOptions, 
											PGPOLastOption( m_pgpContext));
	if (IsPGPError( i_err))	{
		DisplayPgpError( __FILE__, __LINE__, mpc_MODULENM, i_err);
		return i_err;
	}
		
	i_err = EncryptSignBuffer( eh_Instance, eh_mainWnd, m_pgpContext, 
								m_pgpTlsContext, mpc_PLUGIN_APP, 
								mpc_MODULENM, PC, ul_LEN, 
								&pt_context->t_recipients, oneTimeOptions, 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -