Exemplo n.º 1
0
int __cdecl _pgp_open_keyrings(LPSTR PubRingPath, LPSTR SecRingPath)
{
	#if defined(_WIN64)
		return 0;
	#else
		_pgp_close_keyrings();

		if ((!PubRingPath || !*PubRingPath) && !ShowSelectKeyringsDlg(0,PubRingPath,SecRingPath))
			return 0;

		PGPFileSpecRef PubKeyRing, SecKeyRing;
		PGPNewFileSpecFromFullPath(pgpContext, PubRingPath, &PubKeyRing);
		PGPNewFileSpecFromFullPath(pgpContext, SecRingPath, &SecKeyRing);

		PGPError err = PGPOpenKeyDBFile(pgpContext, kPGPOpenKeyDBFileOptions_None, PubKeyRing, SecKeyRing, &pgpKeyDB);
		PGPFreeFileSpec(SecKeyRing);
		PGPFreeFileSpec(PubKeyRing);

		if (CheckPGPError(err))
			return 0;

		return 1;
	#endif
}
Exemplo n.º 2
0
int __cdecl _pgp_open_keyrings(LPSTR PubRingPath, LPSTR SecRingPath)
{
	_pgp_close_keyrings();

#if (PGP_WIN32 < 0x700)
    PGPError err = PGPOpenDefaultKeyRings(pgpContext, kPGPKeyRingOpenFlags_None, &pgpKeyDB);
#else
    if ((!PubRingPath || !*PubRingPath) && !ShowSelectKeyringsDlg(0,PubRingPath,SecRingPath)) {
		return 0;
    }

    PGPFileSpecRef PubKeyRing, SecKeyRing;
    PGPNewFileSpecFromFullPath(pgpContext, PubRingPath, &PubKeyRing);
    PGPNewFileSpecFromFullPath(pgpContext, SecRingPath, &SecKeyRing);

    PGPError err = PGPOpenKeyDBFile(pgpContext, kPGPOpenKeyDBFileOptions_None, PubKeyRing, SecKeyRing, &pgpKeyDB);
    PGPFreeFileSpec(SecKeyRing);
    PGPFreeFileSpec(PubKeyRing);
#endif
	if (CheckPGPError(err)) {
		return 0;
	}
	return 1;
}
Exemplo n.º 3
0
PGPError AddKeyFileListStub (MYSTATE *ms) 
{
	PGPContextRef context;
	PGPFileSpecRef inref;
	PGPOptionListRef opts;
	FILELIST *FileCurrent;
	PGPError err;

	err=kPGPError_NoErr;

	context=ms->context;

	FileCurrent=ms->ListHead;

	while(!(SCGetProgressCancel(ms->hPrgDlg))&&(FileCurrent!=0)&&(IsntPGPError(err)))
	{    
		if(FileCurrent->IsDirectory)
		{
			FileCurrent=FileCurrent->next;
			continue;
		}

		PGPNewFileSpecFromFullPath (context, 
			FileCurrent->name, &inref);

		PGPBuildOptionList(context,&opts,
			PGPOInputFile(context,inref),
			PGPOLastOption(context));

		err=GenericAddKey(ms,opts,FileCurrent->name);

		PGPFreeOptionList(opts);

		PGPFreeFileSpec( inref );
	
		FileCurrent=FileCurrent->next;				
	}

	return err;
}
Exemplo n.º 4
0
PGPError doMaintenance(struct pgpmainBones *mainbPtr, PGPFileSpecRef
        pubRingFileSpec, char * ringfilename)
{
    struct pgpfileBones *filebPtr = mainbPtr->filebPtr;
    PGPContextRef context = mainbPtr->pgpContext;
    PGPEnv *env = mainbPtr->envbPtr->m_env;
    PGPBoolean compatible = mainbPtr->envbPtr->compatible;
    PGPUInt32 pri;
    PGPFilterRef depthFilter = NULL;
    PGPKeySetRef bothRingsSet = NULL;
    PGPKeySetRef secRingSet = NULL;
    PGPError err, er2;
    char secringfilename[MAX_PATH];
    PGPFileSpecRef secRingFileSpec = NULL;
    PGPBoolean cantopen = FALSE;

    /* Assume: ringfilename always public */
    err = pgpGetCorrespondingSecretRingName( filebPtr,
                ringfilename, secringfilename);
    if( IsPGPError(err) ) cantopen = TRUE;

    err = PGPNewFileSpecFromFullPath( context, secringfilename,
                &secRingFileSpec);
    pgpAssertNoErr(err);

    err = PGPOpenKeyRing( context, kPGPKeyRingOpenFlags_Private,
            secRingFileSpec, &secRingSet);
    if( IsPGPError(err) ) cantopen = TRUE;

    err = pgpOpenKeyringsFromPubringSpec( mainbPtr, pubRingFileSpec,
	    &bothRingsSet, 0);

    if( IsPGPError(err) ) goto done;
    /* It generates its own error message. */

    if (cantopen) {
        fprintf(filebPtr->pgpout,
                LANG("\nCan't open key ring file '%s'\n"),
                ringfilename);
        goto done;
    }

    /* Give trust a meaningful value. */
    err = PGPCheckKeyRingSigs(secRingSet, bothRingsSet,
                                       TRUE, NULL, NULL);
    pgpAssertNoErr(err);

    /* Pass 1: */
    err = findUltimatelyTrustedKeys(mainbPtr,
            secRingSet, bothRingsSet, &depthFilter );

    pgpAssertNoErr(err);

    /* Pass 2: trace signature chains */
    if ( IsntPGPError(err) ) {

        err = traceSignatureChains(mainbPtr, bothRingsSet, depthFilter);

    }

    /* Pass 3: */

    err = pgpShowKeySetTrustAndValidity( filebPtr, bothRingsSet,
            bothRingsSet);

    pgpAssertNoErr(err);

 done:

    if (bothRingsSet)
        PGPFreeKeySet( bothRingsSet );
    if (secRingSet)
        PGPFreeKeySet( secRingSet );

    if (secRingFileSpec)
        PGPFreeFileSpec(secRingFileSpec);

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

    return err;
}
Exemplo n.º 5
0
int addToKeyring(struct pgpmainBones *mainbPtr, char* keyfile,
                 PGPFileSpecRef ringFileSpec, char *origRingFileName )

{
    PGPContextRef context = mainbPtr->pgpContext;
    struct pgpfileBones *filebPtr = mainbPtr->filebPtr;

    PGPFileSpecRef  keyFileSpec = kPGPInvalidRef;
    PGPKeySetRef    ringSet = kPGPInvalidRef;
#ifdef NOTPREFERREDMETHOD
    PGPKeySetRef    keySet = kPGPInvalidRef;
#endif /* NOTPREFERREDMETHOD */
    PGPKeySetRef    emptyKeySet = kPGPInvalidRef;
    PGPError err,er2;
    char *ringfile = NULL;
    PGPEnv *env = mainbPtr->envbPtr->m_env;
    PGPInt32 pri;
    PGPBoolean compatible = mainbPtr->envbPtr->compatible;


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

    /* Manually open the input file, gives us an early out if it is
       missing */

    err = PGPNewFileSpecFromFullPath(context, keyfile, &keyFileSpec);
    if(err) {
        pgpShowError( filebPtr, err, __FILE__,__LINE__);
        goto done;
    }

    /* add the keys to a in memory key set, then
       do one add operation at end to the target key set */
    err = PGPNewKeySet(context, &emptyKeySet);
    if(IsPGPError(err))
        goto done;
    mainbPtr->workingRingSet = emptyKeySet;

    /* Get or create target keySet. Must be both public and secret
       keyrings, in case the input contains new secret keys. */

    err = pgpOpenKeyringsFromPubringSpec( mainbPtr, ringFileSpec, &ringSet,
                                          kPGPKeyRingOpenFlags_Mutable);
    if(err) {
        /* XXX The error msg context here may differ from 262 */
        fprintf(filebPtr->pgpout, ringFileSpec ? LANG(
                    "\nKey ring file '%s' cannot be created.\n")
                : LANG("Default ring file cannot be created"),
                origRingFileName);
        goto done;
    }

    /*
     *	mark key set so that we know what was added
     */
    err = pgpMarkKeySet(ringSet);
    pgpAssertNoErr(err);

    /* Allow eventhandler in dodecode.c to do the remaining work */

    fprintf(filebPtr->pgpout,LANG("\nLooking for new keys...\n"));

    err = PGPDecode(
              context,
              PGPOInputFile( context, keyFileSpec ),
              PGPOKeySetRef( context, ringSet ),
              PGPOSendEventIfKeyFound( context, TRUE ),
              PGPOEventHandler( context, addHandler, (PGPUserValue) mainbPtr ),
              PGPOLastOption( context )
          );

    if(err) {
        pgpShowError( filebPtr, err,__FILE__,__LINE__ );
        goto done;
    }
    else
    {
        /* count number of keys before add */
        PGPUInt32	countBefore = 0;

        err = PGPCountKeys(ringSet, &countBefore);
        pgpAssertNoErr(err);

        err = PGPAddKeys(mainbPtr->workingRingSet, ringSet);
        if(IsntPGPError(err) && PGPKeySetNeedsCommit(ringSet))
        {
            /*
             *	show what was added
             */

            PGPUInt32	keys = 0;
            PGPSize dummy,uids,sigs,rvks;

            err = PGPCountKeys(ringSet, &keys);
            pgpAssertNoErr(err);

            keys -= countBefore;

            fprintf(filebPtr->pgpout,
                    LANG("\n\nSummary of changes : \n"));

            err = pgpShowKeySetUnmarked( filebPtr, ringSet, &dummy, &uids,
                                         &sigs, &rvks );
            pgpAssertNoErr(err);

            if(keys || uids || sigs || rvks)
            {
                fprintf(filebPtr->pgpout, LANG("\nAdded :\n"));
                if (keys)
                    fprintf(filebPtr->pgpout,
                            LANG("%4d new key(s)\n"), keys);
                if (sigs)
                    fprintf(filebPtr->pgpout,
                            LANG("%4d new signatures(s)\n"), sigs);
                if (uids)
                    fprintf(filebPtr->pgpout,
                            LANG("%4d new user ID(s)\n"), uids);
                if (rvks)
                    fprintf(filebPtr->pgpout,
                            LANG("%4d new revocation(s)\n"), rvks);
            }
            else
            {
                fprintf(filebPtr->pgpout,
                        LANG("No new keys found."));
            }

            PGPCommitKeyRingChanges(ringSet);
        }
    }

#ifdef NOTPREFERREDMETHOD
    /* Rather than calling this here, we call it from the callback
       Copy all keys from keySet which aren't in ringSet already */
    err = addToWorkingRingSet( mainbPtr, keySet );
#endif /* NOTPREFERREDMETHOD */

done:
    if(emptyKeySet != kPGPInvalidRef)
    {
        er2 = PGPFreeKeySet(emptyKeySet);
        pgpAssertNoErr(er2);
    }

#ifdef NOTPREFERREDMETHOD
    if( keySet != kPGPInvalidRef ) {
        er2 = PGPFreeKeySet( keySet );
        pgpAssertNoErr(er2);
    }
#endif /* NOTPREFERREDMETHOD */

    if( ringSet != kPGPInvalidRef ) {
        er2 = PGPFreeKeySet( ringSet );
        pgpAssertNoErr(er2);
        mainbPtr->workingRingSet = NULL;
    }

    if( keyFileSpec != kPGPInvalidRef ) {
        er2 = PGPFreeFileSpec(keyFileSpec);
        pgpAssertNoErr(er2);
    }

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

    return err ? -1 : 0;
}