Esempio n. 1
0
VOID CALLBACK UpdateTimerProc(HWND hwnd, 
							  UINT uMsg, 
							  UINT idEvent, 
							  DWORD dwTime)
{
	PGPMemoryMgrRef memoryMgr;
	PGPBoolean		bUpdateAllKeys;
	PGPBoolean		bUpdateTrustedIntroducers;
	PGPBoolean		bUpdateCRLs;
	PGPError		err = kPGPError_NoErr;

	if (idEvent != LAUNCHKEYS_TIMER)
		return;

	err = PGPNewMemoryMgr(0, &memoryMgr);
	if (IsPGPError(err))
	{
		PGPclErrorBox(hwnd, err);
		return;
	}

	err = PGPclCheckAutoUpdate(memoryMgr, FALSE, 
			&bUpdateAllKeys, &bUpdateTrustedIntroducers, &bUpdateCRLs);
	if (IsPGPError(err))
	{
		PGPclErrorBox(hwnd, err);
		return;
	}

	if (bUpdateAllKeys || bUpdateTrustedIntroducers || bUpdateCRLs)
		DoLaunchKeys(hwnd);

	PGPFreeMemoryMgr(memoryMgr);
	return;
}
Esempio n. 2
0
	PGPError
pgpWarnUser(
	PGPContextRef	 	 context,		/* Input parameters */
	PGPOptionListRef	 optionList,
	PGPError			 errCode,
	void				*warnArg
	)
{
	PGPError			 err;
	PGPEventHandlerProcPtr handler;
	PGPUserValue		 arg;
	PGPOptionListRef	dummyOptionList = NULL;

	if( IsPGPError( err = pgpFindOptionArgs( optionList,
						 kPGPOptionType_EventHandler, FALSE,
						 "%p%p", &handler, &arg ) ) )
		goto error;

	if( NULL!=(int)( handler ) ) {
		if( IsPGPError( err = pgpEventWarning( context, &dummyOptionList,
								  handler, arg, errCode, warnArg ) ) )
			goto error;
		pgpCleanupOptionList( &dummyOptionList );
	}
	return kPGPError_NoErr;

error:
	return err;
}
Esempio n. 3
0
PGPError PGPclExport 
PGPclIsExpired(HWND hwnd)
{
	PGPError err = kPGPError_NoErr;
#if BETA_TIMEOUT > 0
	unsigned short month, day, year;
	struct tm tm, *ptm;
	time_t TimeNow, TimeoutTime;

	//Get the compile date, in usable form:
	TranslateDate(&month, &day, &year, __DATE__);

	//Seed the tm structure with the current time:
	time(&TimeNow);
	ptm = localtime(&TimeNow);
	memcpy(&tm, ptm, sizeof(tm));

	//Set the dates to the compile time:
	tm.tm_mon = month - 1;
	tm.tm_mday = day;
	tm.tm_year = year - 1900;

	//Turn the compile time into number of secs since 1/1/1970:
	TimeoutTime = mktime(&tm);

	//Increment it plus the number of days in the beta timeout times the 
	TimeoutTime += BETA_TIMEOUT * (60 * 60 * 24); //number of seconds in a day

	if(TimeoutTime < TimeNow)
	{
		err = kPGPError_FeatureNotAvailable;
		DisplayTimeoutMessage(hwnd);
	}
#endif	// BETA_TIMEOUT > 0

#if PGP_DEMO

	// The timeout starts at 30 days, which only disables encrypt and sign
	// After 30 days, display nag screen
	// After 60 days (TimeOut + 30 days), time out everything and 
	//										delete library DLL's
	
	err = PGPclEvalExpired(hwnd, PGPCOMDLG_ALLEXPIRED);
	if (IsPGPError (err))
	{
		pgpFixBeforeShip ("eval version file deletion");
///???		DeleteTimeoutFile("pgpsdk.dll");
///???		DeleteTimeoutFile("pgp.dll");
		DisplayTimeoutMessage(hwnd);
	}

	if (IsPGPError(PGPclEvalExpired(hwnd, PGPCOMDLG_ENCRYPTSIGNEXPIRED)) && 
			!IsntPGPError (err))
		PGPclNag(hwnd, NULL, NULL);

#endif	// PGP_DEMO

	return err;
}
Esempio n. 4
0
	PGPError
PGPNewFlattenedGroupFromGroup(
	PGPGroupSetRef	sourceSet,
	PGPGroupID		sourceID,
	PGPGroupSetRef	destSet,
	PGPGroupID		*destID)
{
	PGPError	err;

	PGPValidatePtr( destID );
	*destID	= kPGPInvalidGroupID;
	PGPValidateGroupSet( sourceSet );
	PGPValidateGroupSet( destSet );
	PGPValidateParam( sourceSet != destSet );

	err = PGPNewGroup( destSet, "", "", destID );
	if( IsntPGPError( err ) )
	{
		PGPGroupItemIterRef	iterator;
		
		err	= PGPNewGroupItemIter( sourceSet, sourceID,
					kPGPGroupIterFlags_Recursive | kPGPGroupIterFlags_Keys,
					&iterator );
		if ( IsntPGPError( err )  )
		{
			PGPGroupItem	item;
			
			err = PGPGroupItemIterNext( iterator, &item );
			while( IsntPGPError( err ) )
			{
				err = PGPAddItemToGroup( destSet, &item, *destID );
				if( err == kPGPError_ItemAlreadyExists )
					err = kPGPError_NoErr;
				
				if( IsPGPError( err ) )
					break;
						
				err = PGPGroupItemIterNext( iterator, &item );
			}
			
			if ( err == kPGPError_EndOfIteration )
				err	= kPGPError_NoErr;
				
			PGPFreeGroupItemIter( iterator );
		}
		
		if( IsPGPError( err ) )
		{
			(void) PGPDeleteGroup( destSet, *destID );
			*destID = kPGPInvalidGroupID;
		}
	}
	
	return( err );
}
Esempio n. 5
0
/*
 * See if optionList specifies PGPMIME encoding, and if so, get MIME body
 * offset and return it to caller.
 */
	PGPError
pgpGetPGPMIMEBodyOffset(
	PGPPipeline			*pipeBuf,
	PGPOptionListRef	 optionList)
{
	PGPSize				*mimeBodyOffPtr;
	PGPSize				 mimeBodyOff;
	char				*mimeSeparator;
	PGPUInt32	 		 mimeHeaderLines;
	PGPUInt32			 mimeFlag;
	PGPUInt32			 lineEndFlag;
	PGPLineEndType		 lineEnd;
	PGPUInt32			 uintLineEnd;
	PGPError			 err = kPGPError_NoErr;

	if( IsPGPError( err = pgpFindOptionArgs( optionList,
							 kPGPOptionType_PGPMIMEEncoding, FALSE,
							 "%d%p%p", &mimeFlag, &mimeBodyOffPtr,
									   &mimeSeparator) ) )
		goto error;
	if( mimeFlag ) {
		if( NULL!=(int)( mimeBodyOffPtr ) ) {
			if( IsPGPError( err = pipeBuf->annotate( pipeBuf, NULL,
					 PGPANN_PGPMIME_HEADER_SIZE,
					 (unsigned char *)&mimeBodyOff, sizeof(mimeBodyOff) ) ) )
			   goto error;
			if( IsPGPError( err = pgpFindOptionArgs( optionList,
								  kPGPOptionType_OutputLineEndType, FALSE,
								  "%b%d", &lineEndFlag, &uintLineEnd ) ) )
				goto error;
			if( lineEndFlag )
				lineEnd = (PGPLineEndType)uintLineEnd;
			else
				lineEnd = pgpGetDefaultLineEndType ();
			if( lineEnd == kPGPLineEnd_CRLF ) {
				if( IsPGPError( err = pipeBuf->annotate( pipeBuf, NULL,
									PGPANN_PGPMIME_HEADER_LINES,
									(unsigned char *)&mimeHeaderLines,
									sizeof(mimeHeaderLines) ) ) )
					goto error;
				mimeBodyOff += mimeHeaderLines;
			}
			*mimeBodyOffPtr = mimeBodyOff;
		}
		if( NULL!=(int)( mimeSeparator ) ) {
			if( IsPGPError( err = pipeBuf->annotate( pipeBuf, NULL,
					 PGPANN_PGPMIME_SEPARATOR,
					 (unsigned char *)mimeSeparator,
					 kPGPMimeSeparatorSize ) ) )
				goto error;
		}
	}
error:
	return err;
}
Esempio n. 6
0
/*____________________________________________________________________________
____________________________________________________________________________*/
PGPError
PGPCopyCFBContext(
    PGPCFBContextRef	inRef,
    PGPCFBContextRef *	outRef )
{
    PGPError					err	= kPGPError_NoErr;
    PGPCFBContextRef	newRef	= NULL;

    PGPValidatePtr( outRef );
    *outRef	= NULL;
    PGPValidateCFB( inRef );

    newRef	= (PGPCFBContextRef)
              PGPNewData( inRef->memoryMgr,
                          CalcContextSize( inRef->interleave ), 0);
    if ( NULL!=(int)( newRef ) )
    {
        PGPUInt32	cfbIndex;

        *newRef		= *inRef;

        /* clear each symmetric cipher in case later allocation fails */
        for ( cfbIndex = 0; cfbIndex < inRef->interleave; ++cfbIndex )
        {
            IndCFB( newRef, cfbIndex ).symmetricRef	= NULL;
        }

        /* copy each symmetric cipher */
        for ( cfbIndex = 0; cfbIndex < inRef->interleave; ++cfbIndex )
        {
            err	= PGPCopySymmetricCipherContext(
                      IndCFB( inRef, cfbIndex ).symmetricRef,
                      &IndCFB( newRef, cfbIndex ).symmetricRef );
            if ( IsPGPError( err ) )
            {
                break;
            }
        }

        if ( IsPGPError( err ) )
        {
            PGPFreeCFBContext( newRef );
            newRef	= NULL;
        }
    }
    else
    {
        err	= kPGPError_OutOfMemory;
    }

    *outRef	= newRef;
    return( err );
}
	PGPError
pgpCreateStandardMemoryMgr( PGPMemoryMgrRef *newMemoryMgr )
{
	PGPError				err	= kPGPError_NoErr;
	MyData *				pmyData	= NULL;
	
	PGPValidatePtr( newMemoryMgr );
	*newMemoryMgr	= NULL;
	
	/* allocate private data which we will store as the customValue */
	pmyData	= (MyData *)sInternalAlloc( sizeof( MyData ) );
	if ( IsntNull( pmyData ) )
	{
		PGPNewMemoryMgrStruct	custom;
		
		pgpClearMemory( pmyData, sizeof( MyData ) );
		err	= sInitMyData( pmyData );
		if ( IsntPGPError( err ) )
		{
			pgpClearMemory( &custom, sizeof( custom ) );
		
			custom.customValue	= (PGPUserValue)pmyData;
			
			custom.sizeofStruct		= sizeof( custom );
			custom.allocProc		= sWin32MemoryAllocationProc;
			custom.reallocProc		= sWin32MemoryReallocationProc;
			custom.deallocProc		= sWin32MemoryDeallocationProc;
			
			custom.secureAllocProc		= sWin32SecureMemoryAllocationProc;
			custom.secureDeallocProc	= sWin32SecureMemoryDeallocationProc;
			
			err	= PGPNewMemoryMgrCustom( &custom, newMemoryMgr );
			if ( IsPGPError( err ) )
			{
				sCleanupMyData( pmyData );
			}
		}
		
		if ( IsPGPError( err ) )
		{
			/* creation failed...dispose our private data */
			sInternalFree( pmyData );
		}
	}
	else
	{
		err	= kPGPError_OutOfMemory;
	}
	
	return( err );
}
Esempio n. 8
0
BOOL AddKeyFileList(HWND hwnd,void *PGPsc,void *PGPtls,FILELIST *ListHead)
{
	PGPContextRef context;
	PGPtlsContextRef tls;
	MYSTATE *ms;
	PGPError err;

	err=kPGPError_NoErr;

	context=(PGPContextRef)PGPsc;
	tls=(PGPtlsContextRef)PGPtls;

	if(IsPGPError(PGPclEvalExpired(hwnd, PGPCL_ALLEXPIRED)))
		return FALSE;

	ms=(MYSTATE *)malloc(sizeof(MYSTATE));

	if(ms)
	{
		memset(ms, 0x00, sizeof(MYSTATE) );

		ms->context=context;
		ms->tlsContext=tls;
		ms->ListHead=ListHead;
		ms->Operation=MS_ADDKEYFILELIST;

		if(OpenRings(hwnd,context,&(ms->KeySet)))
		{
			err=SCProgressDialog(hwnd,DoWorkThread,ms,
						  0,"Adding Keys from File(s)...",
						  "","",IDR_PROGAVI);

			if(!(ms->FoundPGPData))
				PGPscMessageBox (hwnd,IDS_PGPERROR,IDS_NOPGPKEYSINFILE,
					MB_OK|MB_ICONEXCLAMATION);	
	
			PGPFreeKeySet(ms->KeySet);
		}
		free(ms);
	}

	FreeFileList(ListHead);

	if(IsPGPError(err))
		return FALSE;

	return TRUE;
}
Esempio n. 9
0
/* Create a new big num with same value as src */
	PGPError
PGPCopyBigNum(
	PGPBigNumRef	src,
	PGPBigNumRef * 	dest )
{
	PGPError		err	= kPGPError_NoErr;
	PGPBigNumRef	temp	= NULL;
	
	PGPValidatePtr( dest );
	*dest	= NULL;
	pgpValidateBigNum( src );
	
	err	= PGPNewBigNum( src->bn.mgr, src->bn.isSecure, &temp );
	if ( IsntPGPError( err ) )
	{
		err	= PGPAssignBigNum( src, temp );
		if ( IsPGPError( err ) )
		{
			PGPFreeBigNum( temp );
			temp	= NULL;
		}
	}
	
	*dest	= temp;
	
	return( err );
}
Esempio n. 10
0
PGPError
PGPSocketsCreateThreadStorage(
	PGPSocketsThreadStorageRef *	outPreviousStorage)
{
	PGPError				err = kPGPError_NoErr;
	struct SThreadContext *	context = NULL;

	PGPValidatePtr(outPreviousStorage);
	*outPreviousStorage = NULL;

	context = malloc(sizeof(struct SThreadContext));
	if (context != NULL) {
		err = PGPGetSocketsIdleEventHandler(&context->callback,
					&context->callbackData);
	} else {
		err = kPGPError_OutOfMemory;
	}

	if (IsPGPError(err) && (context != NULL)) {
		free(context);
	} else {
		*outPreviousStorage = (PGPSocketsThreadStorageRef) context;
	}
	
	return err;
}
Esempio n. 11
0
/*
 * Create a singleton enumerated key set
 */
	PGPError
PGPNewSingletonKeySet(
	PGPKeyRef			key,
	PGPKeySetRef *		newSet)
{
	PGPContextRef			context	= PGPGetKeyContext(key);
	EnumeratedSubsetPriv *	priv;
	PGPKeySetRef			set;
	PGPError				err	= kPGPError_NoErr;

	PGPValidatePtr( newSet );
	*newSet = NULL;			/* In case there's an error */
	PGPValidateKey( key );

	err = NewEnumeratedSubsetInternal(key->keyDB, &set);
	if (IsPGPError(err))
		return err;

	priv = (EnumeratedSubsetPriv *)set->priv;
	priv->keyArray = (RingObject **)pgpContextMemAlloc(context,
											sizeof(RingObject *), 0);
	if (NULL==(int)(priv->keyArray))
	{
		PGPFreeKeySet(set);
		return kPGPError_OutOfMemory;
	}
	priv->numKeys = 1;
	priv->keyArray[0] = key->key;

	*newSet = set;
	pgpAssertErrWithPtr( err, *newSet );
	return err;
}
Esempio n. 12
0
PGPCFBContextRef
pgpCFBCreate(
    PGPMemoryMgrRef			memoryMgr,
    PGPCipherVTBL const *	vtbl)
{
    PGPError						err				= kPGPError_NoErr;
    PGPCFBContextRef		newRef			= NULL;
    PGPSymmetricCipherContextRef	symmetricRef	= NULL;

    pgpAssert( vtbl->blocksize <= PGP_CFB_MAXBLOCKSIZE );
    pgpAssert( PGPMemoryMgrIsValid( memoryMgr ) );

    err	= PGPNewSymmetricCipherContext( memoryMgr,
                                        vtbl->algorithm, vtbl->keysize, &symmetricRef );
    if ( IsntPGPError( err ) )
    {
        err	= PGPNewCFBContext( symmetricRef, 1, &newRef );
        if ( IsPGPError( err ) )
        {
            PGPFreeSymmetricCipherContext( symmetricRef );
            symmetricRef	= NULL;
            pgpAssert( NULL==(int)( newRef ) );
        }
    }

    return newRef;
}
Esempio n. 13
0
	static PGPError
NewEnumeratedSubsetInternal(
	PGPKeyDBRef			db,
	PGPKeySetRef *		newSet)
{
	PGPContextRef			context	= pgpGetKeyDBContext(db);
	EnumeratedSubsetPriv *	priv;
	PGPKeySetRef			set;
	PGPError				err	= kPGPError_NoErr;

	*newSet = NULL;		/* In case there's an error */

	priv = (EnumeratedSubsetPriv *)pgpContextMemAlloc(context,
							sizeof(*priv), kPGPMemoryMgrFlags_Clear);
	if (NULL==(int)(priv))
		return kPGPError_OutOfMemory;

	priv->keyArray = NULL;
	priv->numKeys = 0;

	err = pgpNewKeySetInternal(db, &set);
	if (IsPGPError(err))
		return err;
	
	pgpAssertAddrValid(set, PGPKeySet);

	set->priv = priv;
	set->isMember = IsMemberOfEnumeratedSubset;
	set->makeUnion = MakeUnionOfEnumeratedSubsets;
	set->removeKey = RemoveKeyFromEnumeratedSubset;
	set->destroy = DestroyEnumeratedSubset;

	*newSet = set;
	return kPGPError_NoErr;
}
Esempio n. 14
0
BOOL 
KMDisableOnServer (PKEYMAN pKM) 
{
	PGPKeySetRef			keysetDisable	= kInvalidPGPKeySetRef;
	PGPError				err				= kPGPError_BadParams;
	PGPKeyServerKeySpace	space;

	if (pKM->ulOptionFlags & KMF_PENDINGBUCKET)
		space = kPGPKeyServerKeySpace_Normal;
	else
		space = kPGPKeyServerKeySpace_Default;

	KMGetSelectedKeys (pKM, &keysetDisable, NULL);
	if (PGPRefIsValid (keysetDisable)) {
		err = PGPclDisableKeysOnServer (pKM->Context, pKM->tlsContext,
					pKM->hWndParent, &pKM->keyserver, 
					space, pKM->KeySetMain, keysetDisable);
		PGPFreeKeySet (keysetDisable);
	}

	if (IsPGPError (err)) PGPclErrorBox (NULL, err);
	else {
		KMMessageBox (pKM->hWndParent, IDS_PGP, IDS_DISABLEONSERVEROK,
								MB_OK|MB_ICONINFORMATION);
	}

	return TRUE;
}
Esempio n. 15
0
BOOL WINAPI
SocketsBlockingHook()
{
	PGPEventHandlerProcPtr	eventHandler = NULL;
	PGPUserValue		userValue;
	PGPError			pgpError;
	
	PGPRMWOLockStartReading(&sIdleEventHandlerLock);
	(void) PGPThreadGetSpecific(sIdleEventHandlerIndex, (void**)&eventHandler);
	(void) PGPThreadGetSpecific(sIdleEventHandlerDataIndex, &userValue);
	PGPRMWOLockStopReading(&sIdleEventHandlerLock);
	
	if (eventHandler != NULL) {
		PGPEvent theEvent;
	
		pgpClearMemory(&theEvent, sizeof(theEvent));
		theEvent.type = kPGPEvent_SocketsIdleEvent;
		pgpError = eventHandler(NULL, &theEvent, userValue);
		if (IsPGPError(pgpError)) {
			WSACancelBlockingCall();
		}
		
	}
	
	return FALSE;
}
Esempio n. 16
0
	PGPError
pgpSetupCallback(
	PGPOptionListRef	  optionList,
	PGPEventHandlerProcPtr *func,		/* Output params */
	PGPUserValue		 *userValue,
	PGPBoolean			 *fNullEvents
	)
{
	PGPError			  err;
	PGPBoolean			  lNullEvents;

	/* Init return data to default states */
	pgpa( pgpaAddrValid( func, PGPEventHandlerProcPtr ) );
	pgpa( pgpaAddrValid( userValue, PGPUserValue ) );
	pgpa( pgpaAddrValid( fNullEvents, PGPBoolean ) );
	*func = NULL;
	*userValue = (PGPUserValue)0;
	*fNullEvents = FALSE;

	if( IsPGPError( err = pgpFindOptionArgs( optionList,
						 kPGPOptionType_EventHandler, FALSE,
						 "%p%p", func, userValue ) ) )
		goto error;

	if( IsPGPError( err = pgpFindOptionArgs( optionList,
						 kPGPOptionType_SendNullEvents, FALSE,
						 "%b", &lNullEvents ) ) )
		goto error;
	if( lNullEvents ) {
		/* Wants notification of null events */
		if( NULL==(int) (*func) ) {
			pgpDebugMsg(
				   "Error: Null events requested without event handler" );
			err = kPGPError_BadParams;
			goto error;
		}
		*fNullEvents = TRUE;
	}
	return kPGPError_NoErr;

error:
	*func = NULL;
	*userValue = (PGPUserValue)0;
	*fNullEvents = FALSE;

	return err;
}
Esempio n. 17
0
PGPError PGPclExport 
PGPclSplash (
		PGPContextRef	Context,
		HWND			hWndParent, 
		UINT			uMS) 
{
	PGPTime			LastSplash			= 0;
	PGPTime			Today;
	DWORD			dwID;
	PGPPrefRef		PrefRef;
	struct tm *		stm;
	PGPError		err;
	INT				iYear, iDay;
	time_t			tt;
	BOOL			bShowSplash;

	MemMgr = PGPGetContextMemoryMgr (Context);
	PGPclOpenClientPrefs (MemMgr, &PrefRef);

	Today = PGPGetTime ();
	tt = PGPGetStdTimeFromPGPTime (Today);
	stm = localtime (&tt);
	iYear = stm->tm_year;
	iDay = stm->tm_yday;

	if (PGPRefIsValid (PrefRef)) {
		err = PGPGetPrefNumber (PrefRef, kPGPPrefDateOfLastSplashScreen, 
						&LastSplash);
		if (IsPGPError (err)) LastSplash = 0;
	}
	tt = PGPGetStdTimeFromPGPTime (LastSplash);
	stm = localtime (&tt);

	bShowSplash = FALSE;
	if (uMS == 0) {
		bShowSplash = TRUE;
	}
	if ((stm != NULL) &&
		((stm->tm_year != iYear) || 
		 (stm->tm_yday != iDay))) bShowSplash = TRUE;

	if (bShowSplash)
	{
		if (g_hWndSplash) return kPGPError_Win32_AlreadyOpen;
		g_hWndSplash = (HWND)1;

		hWndSplashParent = hWndParent;

		_beginthreadex (NULL, 0, sSplashThread, (PVOID)uMS, 0, &dwID); 

		PGPSetPrefNumber (PrefRef, kPGPPrefDateOfLastSplashScreen, Today);
		Sleep (MAINWINDOWDELAY);
	}

	PGPclCloseClientPrefs (PrefRef, TRUE);

	return kPGPError_NoErr;
}
Esempio n. 18
0
/*
 * Given a bunch of signatures, setup a string of hash modules and
 * hashes in order to process the signatures.
 */
int
pgpSigSetupHashes (PGPContextRef cdkContext,
	PGPPipeline **tail,
	PGPEnv const *env,
	PGPHashListRef *hashlist,
	PGPSig const *siglist,
	PGPUICb const *ui,
	void *ui_arg)
{
	PGPUInt16 len;
	int err;
	PGPByte *buf;
	PGPHashListRef hashes;
	PGPByte const *charmap;
	PGPByte const *extra;
	unsigned extralen;

	if (!tail || !siglist || !hashlist || !ui)
		return kPGPError_BadParams;

	*hashlist = NULL;

	len = pgpSigDistinctHashCount (siglist);
	buf = (PGPByte *)pgpContextMemAlloc( cdkContext,
		len, kPGPMemoryMgrFlags_Clear);
	if (!buf)
		return kPGPError_OutOfMemory;
	pgpSigDistinctHashes (siglist, buf);

	if (!pgpDevNullCreate (cdkContext, tail)) {
		ui->message (ui_arg, kPGPError_OutOfMemory, PGPMSG_DEVNULL_CREATE, 0);
		pgpContextMemFree( cdkContext, buf);
		return kPGPError_OutOfMemory;
	}

	extra = pgpSigExtra (siglist, &extralen);
	charmap = (PGPByte const *)pgpenvGetPointer (env, PGPENV_CHARMAPTOLATIN1,
						  NULL);
	err = pgpSigSetupPipeline ( cdkContext, tail, &hashes, buf, len, 
				   ((extra && extra[0]) ? charmap : NULL));
	pgpContextMemFree( cdkContext, buf);
	if ( IsPGPError( err ) ) {
		(*tail)->teardown (*tail);
		*tail = NULL;
	}

	if ( pgpHashListGetSize( hashes ) == 0) {
		(*tail)->teardown (*tail);
		*tail = NULL;
		ui->message (ui_arg, kPGPError_VERBOSE_0, PGPMSG_SIG_NO_CHECK, 0);
		pgpHashListDestroy( hashes );
		return kPGPError_CantHash;
	}

	*hashlist = hashes;
	return 0;
}
Esempio n. 19
0
PGPError dokeycheck(struct pgpmainBones *mainbPtr, char *useridStr,
        PGPFileSpecRef ringFileSpec)
{
    PGPKeySetRef ringSet = NULL;
    char *ringfile = NULL;
    PGPError err, er2;
    struct pgpenvBones *envbPtr = mainbPtr->envbPtr;
    struct pgpfileBones *filebPtr = mainbPtr->filebPtr;
    PGPEnv *env = envbPtr->m_env;
    PGPInt32 pri;
    PGPBoolean quietmode = pgpenvGetInt( env, PGPENV_NOOUT, &pri, &err);
    PGPBoolean compatible = envbPtr->compatible;

    err = PGPGetFullPathFromFileSpec( ringFileSpec, &ringfile );
    pgpAssertNoErr(err);


    err = PGPOpenKeyRing(mainbPtr->pgpContext, 0, ringFileSpec, &ringSet);
#if 0
    err = pgpOpenKeyringsFromPubringSpec( mainbPtr, ringFileSpec, &ringSet, 0);
#endif 0

    if( IsPGPError(err) ) goto done;

    if (!quietmode) fprintf(filebPtr->pgpout,
         LANG("\nKey ring: '%s'"), ringfile);

    mainbPtr->workingRingSet=ringSet;
    err = pgpDoCheckKeyRing(mainbPtr, useridStr);
    pgpAssertNoErr(err);

done:
    if (ringfile)
        er2 = PGPFreeData( ringfile );
    if (ringSet)
        er2 = PGPFreeKeySet( ringSet );
    mainbPtr->workingRingSet = NULL;

    if( !compatible && IsPGPError(err) &&
        pgpenvGetInt( env, PGPENV_VERBOSE, &pri, &er2) )
        pgpShowError(filebPtr, err, __FILE__,__LINE__);

    return err;
}
Esempio n. 20
0
	PGPError 
PGPNewCBCContext(
	PGPSymmetricCipherContextRef	symmetricRef,
	PGPCBCContextRef *				outRef )
{
	PGPCBCContextRef				newRef	= NULL;
	PGPError						err	= kPGPError_NoErr;
	PGPMemoryMgrRef					memoryMgr	= NULL;
	
	PGPValidatePtr( outRef );
	*outRef	= NULL;
	PGPValidatePtr( symmetricRef );
	
	memoryMgr	= pgpGetSymmetricCipherMemoryMgr( symmetricRef );
	newRef	= (PGPCBCContextRef)
			PGPNewData( memoryMgr,
				sizeof( *newRef ), 0 | kPGPMemoryMgrFlags_Clear);
			
	if ( IsntNull( newRef ) )
	{
#if PGP_DEBUG
		/* make original invalid to enforce semantics */
		PGPSymmetricCipherContextRef	tempRef;
		err	= PGPCopySymmetricCipherContext( symmetricRef, &tempRef );
		if ( IsntPGPError( err ) )
		{
			PGPFreeSymmetricCipherContext( symmetricRef );
			symmetricRef	= tempRef;
		}
		err	= kPGPError_NoErr;
#endif

		newRef->magic			= kCBCMagic;
		newRef->CBCInited		= FALSE;
		newRef->symmetricRef	= symmetricRef;
		newRef->iv				= newRef->iv1;
		newRef->memoryMgr		= memoryMgr;
		
		/* make sure we clean up */
		if ( IsPGPError( err ) )
		{
			PGPFreeCBCContext( newRef );
			newRef	= NULL;
		}
	}
	else
	{
		/* we own it, so dispose it */
		PGPFreeSymmetricCipherContext( symmetricRef );
		err	= kPGPError_OutOfMemory;
	}
	
	*outRef	= newRef;
	return( err );
}
Esempio n. 21
0
	PGPError
pgpPumpMem(
	PGPPipeline			*head,
	PGPByte				*inBufPtr,
	PGPSize				 inBufLength,
	PGPProgressCallBack	 callBack,
	void				 *callBackArg
	)
{
	PGPSize				totalSize;
	PGPError			err = kPGPError_NoErr;
	PGPSize				written;

	totalSize = inBufLength;

	err = head->sizeAdvise( head, inBufLength );
	if( IsPGPError( err ) )
		return err;
	err = head->annotate (head, NULL, PGPANN_FILE_BEGIN, NULL, 0);
	if( IsPGPError( err ) )
		return err;
	err = head->sizeAdvise( head, inBufLength );

	while( inBufLength>0 && IsntPGPError( err ) ) {
		written = head->write( head, inBufPtr,
							   pgpMin(inBufLength, 4096), &err );
		inBufPtr += written;
		inBufLength -= written;
		if( IsPGPError( err ) )
			break;
		if( NULL!=(int)( callBack ) )
			err = callBack( callBackArg, totalSize - inBufLength, totalSize );
	}
	if( IsntPGPError( err ) )
		err = head->sizeAdvise( head, 0 );
	if( IsntPGPError( err ) )
		err = head->annotate (head, NULL, PGPANN_FILE_END, NULL, 0);
	if( IsntPGPError( err ) )
		err = head->sizeAdvise( head, 0 );
	return err;
}
Esempio n. 22
0
bool CheckPGPError(PGPError err)
{
	if (IsPGPError(err)) {
		PGPSize ErrMsgLen = pgpErrMsgLen;
		PGPGetErrorString(err, ErrMsgLen, pgpErrMsg);
		return 1;
	}
	else {
		*pgpErrMsg = '\0';
		return 0;
	}
}
Esempio n. 23
0
BOOL 
KMAddCertificate (PKEYMAN pKM) 
{
	PGPKeySetRef	keysetKey		= kInvalidPGPKeySetRef;
	PGPKeyRef		key				= kInvalidPGPKeyRef;
	PGPUserIDRef	userid			= kInvalidPGPUserIDRef;
	PGPError		err;

	if (KMSelectedFlags (pKM) == OBJECT_USERID)
	{
		userid = (PGPUserIDRef)KMFocusedObject (pKM);
		key = KMGetKeyFromUserID (pKM, userid);
	}
	else
	{
		key = (PGPKeyRef)KMFocusedObject (pKM);
		PGPGetPrimaryUserID (key, &userid);
	}

	PGPNewSingletonKeySet (key, &keysetKey);
	if (PGPRefIsValid (keysetKey)) 
	{
		err = PGPclSendCertificateRequestToServer (
									pKM->Context, 
									pKM->tlsContext,
									pKM->hWndParent, 
									pKM->KeySetMain,
									userid,
									keysetKey);
		PGPFreeKeySet (keysetKey);
	}

	if (err == kPGPError_InvalidProperty)
	{
		if (KMIsThisTheOnlyUserID (pKM, userid))
			KMMessageBox (pKM->hWndParent, IDS_CAPTION, 
					IDS_CANTDERIVEATTRIBUTESONLY, MB_OK|MB_ICONEXCLAMATION);
		else
			KMMessageBox (pKM->hWndParent, IDS_CAPTION, 
					IDS_CANTDERIVEATTRIBUTES, MB_OK|MB_ICONEXCLAMATION);
	}
	else if (IsPGPError (err))
	{
		PGPclErrorBox (pKM->hWndParent, err);
	}
	else
	{
		KMMessageBox (pKM->hWndParent, IDS_PGP, 
				IDS_CERTIFICATEREQUESTED, MB_OK|MB_ICONINFORMATION);
	}

	return TRUE;
}
Esempio n. 24
0
	PGPError
pgpGetMinValidity(
	PGPOptionListRef	 optionList,
	PGPValidity			*failValidity,	/* Output parameters */
	PGPValidity			*warnValidity
	)
{
	PGPError			 err;
	PGPOption			 op;
	PGPUInt32			temp;

	/* Init return pointers */
	pgpa( pgpaAddrValid( failValidity, PGPValidity ) );
	pgpa( pgpaAddrValid( warnValidity, PGPValidity ) );
	/* XXX Need to fix these based on trust model and other aspects */
	*failValidity = kPGPValidity_Unknown;
	*warnValidity = kPGPValidity_Marginal;

	if( IsPGPError( err = pgpSearchOptionSingle( optionList,
						  kPGPOptionType_FailBelowValidity, &op ) ) )
		goto error;
	if( IsOp( op ) ) {
		
		if( IsPGPError( err = pgpOptionUInt( &op, &temp ) ) )
			goto error;
		*failValidity	= (PGPValidity)temp;
	}
	if( IsPGPError( err = pgpSearchOptionSingle( optionList,
						  kPGPOptionType_WarnBelowValidity, &op ) ) )
		goto error;
	if( IsOp( op ) ) {
		if( IsPGPError( err = pgpOptionUInt( &op, &temp ) ) )
			goto error;
		*warnValidity	= (PGPValidity)temp;
	}
	return kPGPError_NoErr;

error:
	return err;
}
Esempio n. 25
0
static PGPError
PGPsdkUIErrorBox(PGPError error) 
{
	PGPError	err				= kPGPError_NoErr;
	char		szMessage[512];
	
	if (IsPGPError (error) && (error!=kPGPError_UserAbort)) {
		PGPGetErrorString (error, sizeof(szMessage), szMessage);
		printf("%s: PGP Error", szMessage);
	}

	return err;
}
Esempio n. 26
0
PGPError
pgpVirtMaskOR (RingPool const *pool, PGPVirtMask const *imask,
	PGPVirtMask *omask)
{
	PGPError err;
	PGPUInt32 i;

	err = pgpVirtMaskSizeUp (pool, omask, imask->nwords);
	if (IsPGPError (err))
		return err;
	for (i=0; i<pgpMin(imask->nwords, omask->nwords); ++i)
		omask->words[i] |= imask->words[i];
	return kPGPError_NoErr;
}
Esempio n. 27
0
/* processes a PKCS #8 EncryptedPrivateKeyInfo ASN.1 blob */
static PGPError
pkcs8Decrypt (
    PGPContextRef		context,	/* [IN] */
    const PGPByte		*pass,		/* [IN] */
    PGPSize			passsize,	/* [IN] */
    const PGPByte		*encdata,	/* [IN] data to decrypt */
    PGPSize			encdatasize,	/* [IN] size of data to decrypt
						   (bytes) */
    PKICONTEXT			*pki,		/* [IN] asn.1 compiler
						   context */
    PGPByte			**privkey,	/* [OUT] PrivateKeyInfo ASN.1 */
    PGPSize			*privkeysize)	/* [OUT] asn.1 binary size */
{
    int				asnerr = 0;
    PKIEncryptedPrivateKeyInfo	*pkcs8;
#if 0
    PKIPrivateKeyInfo		*privkeyinfo;
#endif
    PGPError			err;

    PKIUnpackEncryptedPrivateKeyInfo (pki, &pkcs8, encdata, encdatasize,&asnerr);
    if (asnerr)
	return kPGPError_NoErr; /* can't process this */

    err = pkcs12Decrypt(context, pass, passsize,
			pkcs8->encryptedData.val, pkcs8->encryptedData.len,
			&pkcs8->encryptionAlgorithm, pki,
			privkey, privkeysize);

    if (IsPGPError (err))
	goto error;

#if 0
    /* test the result of the decryption */
    PKIUnpackPrivateKeyInfo (pki, &privkeyinfo, *privkey, *privkeysize, &asnerr);
    if (asnerr)
    {
	err = kPGPError_LazyProgrammer;
	goto error;
    }
    PKIFreePrivateKeyInfo (pki, privkeyinfo);
#endif

    err = kPGPError_NoErr;

error:
    if (pkcs8)
	PKIFreeEncryptedPrivateKeyInfo(pki,pkcs8);
    return err;
}
Esempio n. 28
0
int
pgpSigSetupPipeline (
	PGPContextRef cdkContext,
	PGPPipeline **head,
	PGPHashListRef *hashes,
	PGPByte const *hashlist,
	PGPUInt16 hashlen,
	PGPByte const *charmap)
{
	int num;
	PGPPipeline *mod = NULL, **tail = &mod;
	PGPError error;
	PGPMemoryMgrRef	memoryMgr	= PGPGetContextMemoryMgr( cdkContext );

	pgpAssertAddrValid( head, PGPPipeline );
	pgpAssertAddrValid( hashes, PGPHashListRef );
	pgpAssertAddrValid( hashlist, PGPByte );
	
	if (!head || !hashes || !hashlist || hashlen == 0 )
		return 0;

	error = pgpHashListCreate ( memoryMgr, hashlist, hashes, hashlen);
	if( IsPGPError( error ) )
		return error;

	num = pgpHashListGetSize( *hashes );
	if (num <= 0)
		return 0;

	if (charmap) {
		tail = pgpTextFiltCreate ( cdkContext,
			tail, charmap, 0, kPGPLineEnd_CRLF);
		if (!tail) {
			pgpHashListDestroy (*hashes);
			return kPGPError_OutOfMemory;
		}
	}

	tail = pgpHashModListCreate ( cdkContext, tail, *hashes, num);
	if (!tail) {
		pgpHashListDestroy (*hashes);
		mod->teardown (mod);
		return kPGPError_OutOfMemory;
	}

	/* splice in the modules */
	*tail = *head;
	*head = mod;
	return 0;
}
Esempio n. 29
0
	static PGPError
sAddAllKeysToGroup(
	PGPGroupSetRef	set,
	PGPGroupID		id,
	PGPKeySetRef	keySet )
{
	PGPError		err	= kPGPError_NoErr;
	PGPKeyListRef	keyList;
	
	err = PGPOrderKeySet( keySet, kPGPAnyOrdering, &keyList );
	if( IsntPGPError( err ) )
	{
		PGPKeyIterRef	iter;
		
		err = PGPNewKeyIter( keyList, &iter );
		if( IsntPGPError( err ) )
		{
			PGPKeyRef		key;
			
			while( IsntPGPError( err = PGPKeyIterNext( iter, &key ) ) )
			{
				PGPKeyID	keyID;
				
				err	= PGPGetKeyIDFromKey( key, &keyID );
				if ( IsntPGPError( err ) )
				{
					PGPGroupItem	item;
					PGPInt32		algorithm;
					
					item.type				= kPGPGroupItem_KeyID;
					item.u.key.keyID		= keyID;
					PGPGetKeyNumber( key, kPGPKeyPropAlgID, &algorithm);
					item.u.key.algorithm	= (PGPPublicKeyAlgorithm) algorithm;
						
					err	= PGPAddItemToGroup( set, &item, id);
					
					if ( IsPGPError( err ) )
						break;
				}
			}
			
			if( err == kPGPError_EndOfIteration )
				err = kPGPError_NoErr;
				
			(void) PGPFreeKeyIter( iter );
		}
		(void) PGPFreeKeyList( keyList );
	}
	return( err );
}
Esempio n. 30
0
PGPError
pgpVirtMaskSetBit (RingPool const *pool, PGPVirtMask *mask,
	PGPUInt32 bitnumber)
{
	PGPUInt32 bitword;
	PGPError err;

	bitword = bitnumber / 32;
	err = pgpVirtMaskSizeUp (pool, mask, bitword + 1);
	if (IsPGPError(err))
		return err;
	mask->words[bitword] |= 1 << (bitnumber % 32);
	return kPGPError_NoErr;
}