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

📄 pgpkeyserver.cpp

📁 vc环境下的pgp源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
		
		((CKeyServer *) inKeyServerRef)->GetErrorString(outErrorString);
	}
	
	catch (PGPError exception) {
		result = MapErrors(exception);
	}
	
#if !PGP_WIN32
	catch (...) {
		result = kPGPError_UnknownError;
	}
#endif
	
	return result;
}



	PGPError
PGPQueryKeyServer(
	PGPKeyServerRef	inKeyServerRef, 
	PGPFilterRef	inFilterRef, 
	PGPKeySetRef *	outFoundKeys)
{
	PGPError		result = kPGPError_NoErr;
	
	try {
		// Validation
		PGPValidatePtr(outFoundKeys);
		*outFoundKeys = 0;
		PGPValidatePtr(inKeyServerRef);
		PGPValidateParam(PGPFilterRefIsValid(inFilterRef));
	
		StKeyServerBusy	busyKeyServer((CKeyServer *) inKeyServerRef);
		
		((CKeyServer *) inKeyServerRef)->Query(	inFilterRef,
												outFoundKeys);
	}
	
	catch (PGPError exception) {
		result = MapErrors(exception);
	}
	
#if !PGP_WIN32
	catch (...) {
		result = kPGPError_UnknownError;
	}
#endif
	
	return result;
}



	PGPError
PGPUploadToKeyServer(
	PGPKeyServerRef	inKeyServerRef, 
	PGPKeySetRef	inKeysToUpload, 
	PGPKeySetRef *	outKeysThatFailed)
{
	PGPError		result = kPGPError_NoErr;
	
	try {
		// Validation
		PGPValidatePtr(outKeysThatFailed);
		*outKeysThatFailed = 0;
		PGPValidatePtr(inKeyServerRef);
		PGPValidateParam(PGPKeySetRefIsValid(inKeysToUpload));
	
		StKeyServerBusy	busyKeyServer((CKeyServer *) inKeyServerRef);
		
		((CKeyServer *) inKeyServerRef)->Upload(	kPGPPublicKeyOnly,
													inKeysToUpload,
													outKeysThatFailed);
	}
	
	catch (PGPError exception) {
		result = MapErrors(exception);
	}
	
#if !PGP_WIN32
	catch (...) {
		result = kPGPError_UnknownError;
	}
#endif
	
	return result;
}

	PGPError
PGPDeleteFromKeyServer(
	PGPKeyServerRef	inKeyServerRef,
	PGPKeySetRef	inKeysToDelete,
	PGPKeySetRef *	outKeysThatFailed)
{
	PGPError		result = kPGPError_NoErr;
	
	try {
		// Validation
		PGPValidatePtr(outKeysThatFailed);
		*outKeysThatFailed = 0;
		PGPValidatePtr(inKeyServerRef);
		PGPValidateParam(PGPKeySetRefIsValid(inKeysToDelete));
	
		StKeyServerBusy	busyKeyServer((CKeyServer *) inKeyServerRef);
		
		((CKeyServer *) inKeyServerRef)->Delete(	inKeysToDelete,
													outKeysThatFailed);
	}
	
	catch (PGPError exception) {
		result = MapErrors(exception);
	}
	
#if !PGP_WIN32
	catch (...) {
		result = kPGPError_UnknownError;
	}
#endif
	
	return result;
}



	PGPError
PGPDisableFromKeyServer(
	PGPKeyServerRef	inKeyServerRef,
	PGPKeySetRef	inKeysToDisable,
	PGPKeySetRef *	outKeysThatFailed)
{
	PGPError		result = kPGPError_NoErr;
	
	try {
		// Validation
		PGPValidatePtr(outKeysThatFailed);
		*outKeysThatFailed = 0;
		PGPValidatePtr(inKeyServerRef);
		PGPValidateParam(PGPKeySetRefIsValid(inKeysToDisable));
	
		StKeyServerBusy	busyKeyServer((CKeyServer *) inKeyServerRef);
		
		((CKeyServer *) inKeyServerRef)->Disable(	inKeysToDisable,
													outKeysThatFailed);
	}
	
	catch (PGPError exception) {
		result = MapErrors(exception);
	}
	
#if !PGP_WIN32
	catch (...) {
		result = kPGPError_UnknownError;
	}
#endif
	
	return result;
}



	PGPError
PGPSendGroupsToServer(
	PGPKeyServerRef	inKeyServerRef,
	PGPGroupSetRef	inGroupSetRef)
{
	PGPError		result = kPGPError_NoErr;
	
	try {
		// Validation
		PGPValidatePtr(inKeyServerRef);
		PGPValidateParam(PGPGroupSetRefIsValid(inGroupSetRef));
	
		StKeyServerBusy	busyKeyServer((CKeyServer *) inKeyServerRef);
		
		((CKeyServer *) inKeyServerRef)->SendGroups(inGroupSetRef);
	}
	
	catch (PGPError exception) {
		result = MapErrors(exception);
	}
	
#if !PGP_WIN32
	catch (...) {
		result = kPGPError_UnknownError;
	}
#endif
	
	return result;
}
						
	PGPError
PGPRetrieveGroupsFromServer(
	PGPKeyServerRef		inKeyServerRef,
	PGPGroupSetRef *	outGroupSetRef)
{
	PGPError		result = kPGPError_NoErr;
	
	try {
		// Validation
		PGPValidatePtr(outGroupSetRef);
		*outGroupSetRef = 0;
		PGPValidatePtr(inKeyServerRef);
	
		StKeyServerBusy	busyKeyServer((CKeyServer *) inKeyServerRef);
		
		((CKeyServer *) inKeyServerRef)->RetrieveGroups(outGroupSetRef);
	}
	
	catch (PGPError exception) {
		result = MapErrors(exception);
	}
	
#if !PGP_WIN32
	catch (...) {
		result = kPGPError_UnknownError;
	}
#endif
	
	return result;
}



	PGPError
PGPNewServerMonitor(
	PGPKeyServerRef			inKeyServerRef,
	PGPKeyServerMonitor **	outMonitor)
{
	PGPError		result = kPGPError_NoErr;
	
	try {
		// Validation
		PGPValidatePtr(outMonitor);
		*outMonitor = 0;
		PGPValidatePtr(inKeyServerRef);
	
		StKeyServerBusy	busyKeyServer((CKeyServer *) inKeyServerRef);
		
		((CKeyServer *) inKeyServerRef)->NewMonitor(outMonitor);
	}
	
	catch (PGPError exception) {
		result = MapErrors(exception);
	}
	
#if !PGP_WIN32
	catch (...) {
		result = kPGPError_UnknownError;
	}
#endif
	
	return result;
}

						

	PGPError
PGPFreeServerMonitor(
	PGPKeyServerMonitor *	inMonitor)
{
	PGPError		result = kPGPError_NoErr;
	
	try {
		// Validation
		PGPValidatePtr(inMonitor);
		PGPValidatePtr(inMonitor->keyServerRef);
	
		StKeyServerBusy	busyKeyServer((CKeyServer *) inMonitor->keyServerRef);
		
		((CKeyServer *) inMonitor->keyServerRef)->FreeMonitor(inMonitor);
	}
	
	catch (PGPError exception) {
		result = MapErrors(exception);
	}
	
#if !PGP_WIN32
	catch (...) {
		result = kPGPError_UnknownError;
	}
#endif
	
	return result;
}




	PGPError
PGPCancelKeyServerCall(
	PGPKeyServerRef	inKeyServerRef)
{
	PGPError	result = kPGPError_NoErr;
	
	try {
#if PGP_WIN32 || PGP_UNIX
		PGPRMWOLockStartWriting(&sCancelLock);
#endif

		// Validation
		PGPValidatePtr(inKeyServerRef);
		
		((CKeyServer *) inKeyServerRef)->Cancel();

#if PGP_WIN32 || PGP_UNIX
		PGPRMWOLockStopWriting(&sCancelLock);
#endif
	}
	
	catch (PGPError exception) {
		result = MapErrors(exception);
	}
	
#if !PGP_WIN32
	catch (...) {
		result = kPGPError_UnknownError;
	}
#endif
	
	return result;
}

	PGPContextRef
PGPGetKeyServerContext(PGPKeyServerRef inKeyServerRef)
{
	PGPContextRef context = kInvalidPGPContextRef;
	
	if( PGPKeyServerRefIsValid( inKeyServerRef ) )
	{
		context = ((CKeyServer *) inKeyServerRef)->GetContext();
	}

	return( context );
}		


	static PGPError
SaveDataToFile(
	PFLFileSpecRef	fileSpecRef,
	const void		*buffer,
	PGPSize			bufferSize,
	PGPBoolean		appendOutput)
{
	PGPIORef	fileIORef = 0;
	PGPError	err;
	
	if( ! appendOutput )
		(void) PFLFileSpecDelete( fileSpecRef );
		
	err = PGPOpenFileSpec( fileSpecRef, kPFLFileOpenFlags_ReadWrite,
				(PGPFileIORef *) &fileIORef );
	if( IsntPGPError( err ) )
	{
		if( appendOutput )
		{
			PGPFileOffset	eof;
			
			err = PGPIOGetEOF( fileIORef, &eof );
			if( IsntPGPError( err ) )
			{
				err = PGPIOSetPos( fileIORef, eof );		
			}
		}

		if( IsntPGPError( err ) )
		{
			err = PGPIOWrite( fileIORef, bufferSize, buffer );
		}
		
		PGPFreeIO( fileIORef );
	}
	
	return( err );
}

typedef struct SendCertRequestOptions
{
	PFLFileSpecRef	inFileSpecRef;
	PFLFileSpecRef	outFileSpecRef;
	
	PGPKeyRef		caKey;
	PGPKeyRef		requestKey;
		
	void			*inBuffer;
	PGPSize			inBufferSize;

	void			*outBuffer;
	PGPSize			maxOutBufferSize;
	PGPSize			*outBufferSize;
	
	void			**allocatedOutBuffer;
	
	PGPBoolean		appendOutput;
	
} SendCertRequestOptions;


	static PGPError
GatherSendCertRequestOptions(
	PGPOptionListRef		optionList,
	SendCertRequestOptions	*options)
{
	PGPError	err 				= kPGPError_NoErr;
	PGPUInt32	numInputOptions		= 0;
	PGPUInt32	numOutputOptions	= 0;
	PGPInt32	tempInt;
	
	pgpAssert( pgpOptionListIsValid( optionList ) );
	pgpAssert( IsntNull( options ) );
	
	pgpClearMemory( options, sizeof( *options ) );
	
	/* Find inputs */
	
	err = pgpFindOptionArgs( optionList,
				kPGPOptionType_InputFileRef, FALSE, "%f",
				&options->inFileSpecRef );
	if( PFLFileSpecRefIsValid( options->inFileSpecRef ) )
	{
		++numInputOptions;
	}
	
	if( IsntPGPError( err ) )
	{
		err = pgpFindOptionArgs( optionList,
					kPGPOptionType_InputBuffer, FALSE, "%p%l",
					&options->inBuffer, &options->inBufferSize );
		if( IsntNull( options->inBuffer ) )
		{
			++numInputOptions;
		}
	}
	
	/* Find CA key */
	if ( IsntPGPError( err ) )
	{
		err = pgpFindOptionArgs( optionList,
					kPGPOptionType_KeyServerCAKey, FALSE, "%p",
					&options->caKey);
	}

	/* Find requesting key */
	if ( IsntPGPError( err ) )
	{
		err = pgpFindOptionArgs( optionList,
					kPGPOptionType_KeyServerRequestKey, FALSE, "%p",
					&options->requestKey);
	}

	/* Find outputs */
	
	if( IsntPGPError( err ) )
	{
		err = pgpFindOptionArgs( optionList,
					kPGPOptionType_OutputFileRef, FALSE, "%f",
					&options->outFileSpecRef );
		if( PFLFileSpecRefIsValid( options->outFileSpecRef ) )
		{
			++numOutputOptions;
		}
	}

	if( IsntPGPError( err ) )
	{
		PGPOOutputBufferDesc	*desc;
		
		err = pgpFindOptionArgs( optionList,
					kPGPOptionType_OutputBuffer, FALSE, "%p", &desc );
		if( IsntNull( options->outBuffer ) )
		{
			options->outBuffer 			= desc->buffer;
			options->maxOutBufferSize 	= desc->bufferSize;
			options->outBufferSize 		= desc->outputDataLength;
			
			*(options->outBufferSize) = 0;

			++numOutputOptions;
		}
	}

	if( IsntPGPError( err ) )
	{
		PGPOAllocatedOutputBufferDesc	*desc;
		
		err = pgpFindOptionArgs( optionList,
					kPGPOptionType_OutputAllocatedBuffer, FALSE, "%p", &desc );
		if( IsntNull( desc ) )
		{
			options->allocatedOutBuffer = desc->buffer;
			options->maxOutBufferSize 	= desc->maximumBufferSize;
			options->outBufferSize 		= desc->actualBufferSize;
			
			*(options->allocatedOutBuffer) 	= 0;
			*(options->outBufferSize) 		= 0;
			
			++numOutputOptions;
		}
	}

	if( IsntPGPError( err ) )
	{
		err = pgpFindOptionArgs( optionList,
					kPGPOptionType_AppendOutput, FALSE, "%d", &tempInt );
		if( tempInt != 0 )
		{
			options->appendOutput = TRUE;
			
			++numOutputOptions;
		}
	}

	/* Check for exactly one input and at most one output */
	
	if( IsntPGPError( err ) && 
		( numInputOptions != 1 || numOutputOptions > 1 ) )
	{
		pgpDebugMsg( "Invalid input or output specification" );
		err = kPGPError_BadParams;
	}
	
	return err;
}

static const PGPOptionType sSendCertificateReqOptionSet[] =
{
	kPGPOptionType_InputFileRef,
	kPGPOptionType_InputBuffer,
	kPGPOptionType_KeyServerCAKey,
	kPGPOptionType_KeyServerRequestKey,
	kPGPOptionType_OutputFileRef,
	kPGPOptionType_OutputBuffer,
	kPGPOptionType_OutputAllocatedBuffer,
	kPGPOptionType_AppendOutput,
	kPGPOptionType_DiscardOutput
};

	static PGPError
pgpSendCertificateRequestInternal(
	PGPKeyServerRef 	keyServerRef,
	PGPKeyRef			caKey,
	PGPKeyRef			requestKey,
	const void			*inBuffer,
	PGPSize				inBufferSize,
	void				**outBuffer,
	PGPSize				*outBufferSize)
{
	PGPError		result = kPGPError_NoErr;
	
	(void) requestKey;
	
	try {
		*outBuffer 		= 0;
		*outBufferSize	= 0;
	
		StKeyServerBusy	busyKeyServer((CKeyServer *) keyServerRef);
		
		((CKeyServer *) keyServerRef)->SendCertificateRequest(	caKey,
																requestKey,
																inBuffer,
																inBufferSize,
																outBuffer,
																outBufferSize);
	}
	
	catch (PGPError exception) {
		result = MapErrors(exception);
	}
	
#if !PGP_WIN32
	catch (...) {
		result = kPGPError_UnknownError;
	}
#endif
	
	return result;
}

	static PGPError
pgpSendCertificateRequest(
	PGPContextRef		context,
	PGPKeyServerRef 	keyServerRef,
	PGPOptionListRef	optionList)
{
	PGPError		err;
	PGPMemoryMgrRef	memoryMgr = PGPGetContextMemoryMgr( context );
	
	pgpAssert( pgpContextIsValid( context ) );
	pgpAssert( PGPKeyServerRefIsValid( keyServerRef ) );
	pgpAssert( pgpOptionListIsValid( optionList ) );
	
	err = pgpGetOptionListError( optionList );
	if( IsntPGPError( err ) )
	{
		err = pgpCheckOptionsInSet( optionList, sSendCertificateReqOptionSet,
					elemsof( sSendCertificateReqOptionSet ) );
		if( IsntPGPError( err ) )
		{
			SendCertRequestOptions	options;
			
			err = GatherSendCertRequestOptions( optionList, &options );
			if( IsntPGPError( err ) )
			{
				void		*inBuffer 			= 0;
				PGPSize		inBufferSize		= 0;
				void		*outBuffer 			= 0;
				PGPSize		outBufferSize		= 0;
				PGPBoolean	freeInputBuffer		= TRUE;
				PGPBoolean	freeOutputBuffer	= TRUE;
				
				if( PFLFileSpecRefIsValid( options.inFileSpecRef ) )
				{
					PGPIORef	fileIORef;
					
					err = PGPOpenFileSpec( options.inFileSpecRef,
								kPFLFileOpenFlags_ReadOnly,
								(PGPFileIORef *) &fileIORef );
					if( IsntPGPError( err ) )
					{
						PGPFileOffset	fileSize;
						
						err = PGPIOGetEOF( fileIORef, &fileSize );
						if( IsntPGPError( err ) )
						{
							inBuffer = PGPNewData( memoryMgr, (PGPSize) fileSize,
											0 );
							if( IsntNull( inBuffer ) )
							{
								err = PGPIORead( fileIORef, (PGPSize) fileSize,

⌨️ 快捷键说明

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