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

📄 pgprpcserver.c

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 C
📖 第 1 页 / 共 4 页
字号:
}

static void
sRecv_FetchKeyInfo(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPInt32 id;
	PGPByte *bufPtr;
	PGPSize bufSize;

	id = unpack_int32(pkt);

	err = pgpFetchKeyInfo_back(
		gCtx,
		id,
		&bufPtr,
		&bufSize);
	rpkt->status = err;
	if (IsPGPError(err)) return;
	pack_opaque(rpkt, bufPtr, bufSize);
	if( IsntNull( bufPtr ) )
		PGPFreeData( bufPtr );
}

static void
sRecv_OpenKeyDBFile(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPInt32 flags;
	PGPUInt32 kdbid, numKeys, *keyBuffer;
	PGPError err;
	PFLFileSpecRef pub, priv;
	PGPSize		bufSize;
	
	flags = unpack_int32(pkt);
	pub = unpack_filespec(pkt, PGPPeekContextMemoryMgr(gCtx) );
	priv = unpack_filespec(pkt, PGPPeekContextMemoryMgr(gCtx) );

	err = pgpOpenKeyDBFile_back(
		gCtx,
		(PGPOpenKeyDBFileOptions) flags,
		pub,
		priv,
		&kdbid,
		&numKeys,
		&keyBuffer,
		&bufSize );
	rpkt->status = err;
	if (IsPGPError(err))
		return;
	pack_int32(rpkt, kdbid);
	pack_int32(rpkt, numKeys);
	pack_opaque(rpkt, (PGPByte *)keyBuffer, bufSize);

	if(IsntNull( keyBuffer ) )
		PGPFreeData( keyBuffer );
	if(PFLFileSpecRefIsValid(pub))
		PFLFreeFileSpec(pub);
	if(PFLFileSpecRefIsValid(pub))
		PFLFreeFileSpec(priv);
}

static void
sRecv_KeyDBFlush(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 id;
	PGPUInt32 *changedkeylist;
	PGPSize changedkeylistsize;

	id = unpack_uint32(pkt);

	err = pgpKeyDBFlush_back(gCtx,
		id, &changedkeylist,
		&changedkeylistsize );
	rpkt->status = err;
	if (IsPGPError(err)) return;
	pack_opaque(rpkt, changedkeylist, changedkeylistsize);
	if( IsntNull( changedkeylist ) )
		PGPFreeData( changedkeylist );
}

static void
sRecv_FreeKeyDB(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPUInt32 id = unpack_uint32(pkt);

	pgpFreeKeyDB_back(gCtx, id);

	rpkt->status = kPGPError_NoErr;
}

static void
sRecv_CacheKeyDB(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 id = unpack_uint32(pkt);
	PGPUInt32 timeoutSeconds = unpack_uint32(pkt);

	err = pgpCacheKeyDB_back(gCtx, id, timeoutSeconds);

	rpkt->status = err;
}

static void
sRecv_PurgeKeyDBCache(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err = pgpPurgeKeyDBCache_back(gCtx);
	rpkt->status = err;
}

static void
sRecv_SetKeyEnabled(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 id;
	PGPBoolean enable;

	id = unpack_uint32(pkt);
	enable = unpack_bool(pkt);

	err = pgpSetKeyEnabled_back(gCtx, id, enable);
	rpkt->status = err;
	if (IsPGPError(err)) return;
}

static void
sRecv_SetKeyAxiomatic(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 id;
	PGPBoolean setAxiomatic;
	PGPBoolean checkPassphrase;
	PGPByte *passphrase;
	PGPSize passphraseLength;
	PGPBoolean hashedPhrase;
	PGPUInt32 cacheTimeOut;
	PGPBoolean cacheGlobal;

	id = unpack_uint32(pkt);
	setAxiomatic = unpack_bool(pkt);
	checkPassphrase = unpack_bool(pkt);
	unpack_opaque(pkt, (void **) &passphrase, &passphraseLength);
	hashedPhrase = unpack_bool(pkt);
	cacheTimeOut = unpack_uint32(pkt);
	cacheGlobal = unpack_bool(pkt);

	err = pgpSetKeyAxiomatic_back(gCtx, id, setAxiomatic, checkPassphrase,
		(char *) passphrase, passphraseLength, hashedPhrase, cacheTimeOut, cacheGlobal);
	rpkt->status = err;
	if (IsPGPError(err)) return;
}

static void
sRecv_PropagateTrust(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 setid, *keylist;
	PGPSize keylistsize;
	PGPUInt32 altid;
	PGPUInt32 timenow;
	PGPUInt32 *changedkeylist;
	PGPSize changedkeylistsize;

	setid = unpack_uint32(pkt);
	unpack_opaque_alloc(pkt, (void **) &keylist, &keylistsize);
	altid = unpack_uint32(pkt);
	timenow = unpack_uint32(pkt);

	err = pgpPropagateTrust_back(gCtx,
		setid, keylist, keylistsize, altid,
		timenow, &changedkeylist, &changedkeylistsize );
	rpkt->status = err;
	if (IsPGPError(err)) return;
	pack_opaque(rpkt, (PGPByte *)changedkeylist, changedkeylistsize);
	if( IsntNull( changedkeylist ) )
		PGPFreeData( changedkeylist );
}

static void
sRecv_CheckKeyRingSigs(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 setid, *keylist;
	PGPSize keylistsize;
	PGPUInt32 altid;
	PGPBoolean checkAll;
	PGPUInt32 *changedkeylist;
	PGPSize changedkeylistsize;

	setid = unpack_uint32(pkt);
	unpack_opaque_alloc(pkt, (void **) &keylist, &keylistsize);
	altid = unpack_uint32(pkt);
	checkAll = unpack_bool(pkt);

	err = pgpCheckKeyRingSigs_back(gCtx,
			setid, keylist, keylistsize, altid, checkAll,
			&changedkeylist, &changedkeylistsize);
	rpkt->status = err;
	if (IsPGPError(err)) return;
	pack_opaque(rpkt, (PGPByte *)changedkeylist, changedkeylistsize);
	if( IsntNull( changedkeylist ) )
		PGPFreeData( changedkeylist );
}

static void
sRecv_PrepareToCheckKeyRingSigs(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 setid, *keylist;
	PGPSize keylistsize;
	PGPUInt32 altid;
	PGPBoolean checkAll;
	PGPUInt32 *changedkeylist;
	PGPSize changedkeylistsize;
	PGPUInt32 nsigs;

	setid = unpack_uint32(pkt);
	unpack_opaque_alloc(pkt, (void **) &keylist, &keylistsize);
	altid = unpack_uint32(pkt);
	checkAll = unpack_bool(pkt);

	err = pgpPrepareToCheckKeyRingSigs_back(gCtx,
		setid, keylist, keylistsize, altid, checkAll,
		&nsigs, &changedkeylist, &changedkeylistsize);
	rpkt->status = err;
	if (IsPGPError(err)) return;
	pack_uint32(rpkt, nsigs);
	pack_opaque(rpkt, (PGPByte *)changedkeylist, changedkeylistsize);
	if( IsntNull( changedkeylist ) )
		PGPFreeData( changedkeylist );
}

static void
sRecv_CheckSig(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 setid, altid, objid;
	PGPBoolean checkAll, revocationonly;
	PGPBoolean handled, changed, verified;

	setid = unpack_uint32(pkt);
	objid = unpack_uint32(pkt);
	altid = unpack_uint32(pkt);
	checkAll = unpack_bool(pkt);
	revocationonly = unpack_bool(pkt);

	err = pgpCheckSig_back(gCtx,
				setid, objid, altid, checkAll, revocationonly,
				&handled, &changed, &verified);
	rpkt->status = err;
	if (IsPGPError(err)) return;
	pack_bool(rpkt, handled);
	pack_bool(rpkt, changed);
	pack_bool(rpkt, verified);
}

static void
sRecv_DoGenerateKey(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 keydbID;
	PGPUInt32 masterkeyID;
	PGPByte pkalg;
	PGPUInt32 bits;
	PGPTime creationDate;
	PGPUInt16 expirationDays;
	PGPByte *name, *passphrase, *masterpass;
	PGPSize namelen, passphraseLength, masterpassLength;
	PGPUInt32 cacheTimeOut;
	PGPBoolean cacheGlobal;
	PGPBoolean passphraseIsKey;
	PGPUInt32 *adkkeylist;
	PGPSize adkkeylistsize;
	PGPByte adkclass;
	PGPEventHandlerProcPtr progress;
	PGPUserValue userValue;
	PGPBoolean fastgen, checkentropy;
	PGPBoolean usetoken;
	PGPUInt32 tokenid;
	PGPUInt32 *rakkeylist;
	PGPSize rakkeylistsize;
	PGPByte rakclass;
	PGPCipherAlgorithm *prefalg;
	PGPSize prefalgLength;
	PGPByte * prefkeyserv;
	PGPSize prefkeyservLength;
	PGPUInt32 keyflags;
	PGPBoolean fkeyflags;
	PGPUInt32 keyservprefs;
	PGPBoolean fkeyservprefs;
	PGPUInt32 *newobjs;
	PGPSize newobjsLength;
	PGPUInt32 newKey;
	
	keydbID = unpack_uint32(pkt);
	masterkeyID = unpack_uint32(pkt);
	pkalg = unpack_int32(pkt);
	bits = unpack_uint32(pkt);
	creationDate = unpack_uint32(pkt);
	expirationDays = (PGPUInt16)unpack_uint32(pkt);
	unpack_opaque(pkt, (void **) &name, &namelen);
	unpack_opaque(pkt, (void **) &passphrase, &passphraseLength);
	passphraseIsKey = unpack_bool(pkt);
	unpack_opaque(pkt, (void **) &masterpass, &masterpassLength);
	cacheTimeOut = unpack_uint32(pkt);
	cacheGlobal = unpack_bool(pkt);
	progress = (PGPEventHandlerProcPtr)unpack_uint32(pkt);
	userValue = (PGPUserValue)unpack_uint32(pkt);
	fastgen = unpack_bool(pkt);
	checkentropy = unpack_bool(pkt);
	usetoken = unpack_bool(pkt);
	tokenid = unpack_uint32(pkt);
	unpack_opaque_alloc(pkt, (void **) &adkkeylist, &adkkeylistsize);
	adkclass = unpack_byte(pkt);
	unpack_opaque_alloc(pkt, (void **) &rakkeylist, &rakkeylistsize);
	rakclass = unpack_byte(pkt);
	unpack_opaque(pkt, (void **) &prefalg, &prefalgLength);
	unpack_opaque(pkt, (void **) &prefkeyserv, &prefkeyservLength);
	keyflags = unpack_uint32(pkt);
	fkeyflags = unpack_bool(pkt);
	keyservprefs = unpack_uint32(pkt);
	fkeyservprefs = unpack_bool(pkt);

	err = pgpDoGenerateKey_back(gCtx,
			keydbID, masterkeyID,
			pkalg, bits, creationDate, expirationDays, (char *) name, namelen,
			(char *) passphrase, passphraseLength,
			passphraseIsKey,
			(char *) masterpass, masterpassLength,
			cacheTimeOut, cacheGlobal, NULL /* progress */, userValue,
			fastgen, checkentropy, usetoken, tokenid,
			adkkeylist, adkkeylistsize,
			adkclass, rakkeylist, rakkeylistsize, rakclass,
			prefalg, prefalgLength, prefkeyserv, prefkeyservLength, keyflags, fkeyflags,
			keyservprefs, fkeyservprefs, &newobjs, &newobjsLength, &newKey);

	rpkt->status = err;
	if (IsPGPError(err)) return;

	pack_opaque(rpkt, newobjs, newobjsLength);
	if( IsntNull( newobjs ) )
		PGPFreeData( newobjs );
	pack_int32(rpkt, newKey);
}

static void
sRecv_CreateKeypair(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 keydbID;
	PGPByte *name, *passphrase;
	PGPSize namelen, passphraseLength;
	PGPByte *seckeyBuf, *keyspecBuf;
	PGPSize seckeySize, keyspecSize;
	PGPUInt32 cacheTimeOut;
	PGPBoolean cacheGlobal;
	PGPBoolean passphraseIsKey;
	PGPUInt32 *adkkeylist;
	PGPSize adkkeylistsize;
	PGPByte adkclass;
	PGPUInt32 *rakkeylist;
	PGPSize rakkeylistsize;
	PGPByte rakclass;
	PGPUInt32 *newobjs;
	PGPSize newobjsLength;
	PGPUInt32 newkeyid;
	
	keydbID = unpack_uint32(pkt);
	unpack_opaque_alloc(pkt, (void **) &seckeyBuf, &seckeySize);
	unpack_opaque_alloc(pkt, (void **) &keyspecBuf, &keyspecSize);
	unpack_opaque(pkt, (void **) &name, &namelen);
	unpack_opaque_alloc(pkt, (void **) &adkkeylist, &adkkeylistsize);
	adkclass = unpack_byte(pkt);
	unpack_opaque_alloc(pkt, (void **) &rakkeylist, &rakkeylistsize);
	rakclass = unpack_byte(pkt);
	unpack_opaque(pkt, (void **) &passphrase, &passphraseLength);
	passphraseIsKey = unpack_bool(pkt);
	cacheTimeOut = unpack_uint32(pkt);
	cacheGlobal = unpack_bool(pkt);

	err = pgpCreateKeypair_back( gCtx, keydbID,
					seckeyBuf, seckeySize, keyspecBuf, keyspecSize,
					(char *)name, namelen,
					adkkeylist, adkkeylistsize, adkclass,
					rakkeylist, rakkeylistsize, rakclass,
					(char *)passphrase, passphraseLength,
					passphraseIsKey, cacheTimeOut, cacheGlobal,
					&newobjs, &newobjsLength, &newkeyid);

	rpkt->status = err;
	if (IsPGPError(err)) return;

	pack_opaque(rpkt, newobjs, newobjsLength);
	if( IsntNull( newobjs ) )
		PGPFreeData( newobjs );
	pack_int32(rpkt, newkeyid);
}

static void
sRecv_CreateSubkeypair(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 masterkeyID;
	PGPByte *passphrase;
	PGPSize passphraseLength;
	PGPByte *seckeyBuf, *keyspecBuf;
	PGPSize seckeySize, keyspecSize;
	PGPUInt32 cacheTimeOut;
	PGPBoolean cacheGlobal;
	PGPBoolean passphraseIsKey;
	PGPUInt32 *newobjs;
	PGPSize newobjsLength;
	PGPUInt32 newkeyid;
	
	masterkeyID = unpack_uint32(pkt);
	unpack_opaque_alloc(pkt, (void **) &seckeyBuf, &seckeySize);
	unpack_opaque_alloc(pkt, (void **) &keyspecBuf, &keyspecSize);
	unpack_opaque(pkt, (void **) &passphrase, &passphraseLength);
	passphraseIsKey = unpack_bool(pkt);
	cacheTimeOut = unpack_uint32(pkt);
	cacheGlobal = unpack_bool(pkt);

	err = pgpCreateSubkeypair_back( gCtx, masterkeyID,
							seckeyBuf, seckeySize,
							keyspecBuf, keyspecSize,
							(char *)passphrase, passphraseLength,
							passphraseIsKey, cacheTimeOut, cacheGlobal,
							&newobjs, &newobjsLength, &newkeyid);

	rpkt->status = err;
	if (IsPGPError(err)) return;

	pack_opaque(rpkt, newobjs, newobjsLength);
	if( IsntNull( newobjs ) )
		PGPFreeData( newobjs );
	pack_int32(rpkt, newkeyid);
}

static void
sRecv_CountTokens(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 ntokens;

	err = pgpCountTokens_back(gCtx, &ntokens );
	rpkt->status = err;
	if (IsPGPError(err)) return;
	pack_uint32(rpkt, ntokens);
}

static void
sRecv_GetTokenInfo(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 tokNumber;
    PGPUInt32 client_size;
    PGPTokenInfo i;

	tokNumber = unpack_uint32(pkt);
    i.size = client_size = unpack_uint32(pkt);

	err = pgpGetTokenInfo_back(gCtx, tokNumber, &i );

    if( ! IsPGPError(err) )  {
        /* Serialize */
        pack_uint32(rpkt, i.size);

        /* Begin of base structure PGPTokenInfo */
        pack_bool(rpkt, i.bRsa);

        pack_uint32(rpkt, i.minRsaKeySize);
        pack_uint32(rpkt, i.maxRsaKeySize);
        pack_uint32(rpkt, i.minPinLen);
        pack_uint32(rpkt, i.maxPinLen);

        pack_opaque(rpkt, i.manufacturerID, strlen(i.manufacturerID)+1);
	    pack_opaque(rpkt, i.model, strlen(i.model)+1);
	    pack_opaque(rpkt, i.serialNumber, strlen(i.serialNumber)+1);

		pack_uint32(rpkt, i.numPubKeys);
		pack_uint32(rpkt, i.numPrivKeys);

        /* End of base structure PGPTokenInfo, therefore: */
        pgpAssert( i.size == 0 || client_size == i.size/*SDK size*/ );
    }

	rpkt->status = err;
}

static void
sRecv_DeleteKeyOnToken(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPUInt32	keydbID;
    PGPKeyID    *keyID;
	PGPSize		l;
	PGPUInt32	tokenNumber;
	PGPByte		*pin;
	PGPSize		pinLen;

	keydbID = unpack_uint32(pkt);
	unpack_opaque(pkt, (void **) &keyID, &l);
	tokenNumber = unpack_uint32(pkt);
	unpack_opaque(pkt, (void **) &pin, &pinLen);

	if( l >= sizeof(PGPKeyID) )
		rpkt->status = pgpDeleteKeyOnToken_back( gCtx, keydbID, keyID, tokenNumber, pin, pinLen );
	else
		rpkt->status = kPGPError_RPCGarbledMsg;
}


static void
sRecv_WipeToken(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 tokNumber;
	PGPByte *passphrase;
	PGPSize passphraseLength;

	tokNumber = unpack_uint32(pkt);
	unpack_opaque(pkt, (void **) &passphrase, &passphraseLength);
	err = pgpWipeToken_back(gCtx, tokNumber, passphrase, passphraseLength );
	rpkt->status = err;
}

static void
sRecv_FormatToken(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 tokNumber;

	PGPByte *adminPin;
	PGPSize	adminPinLen;
	PGPByte *newUserPin;
	PGPSize	newUserPinLen;

	tokNumber = unpack_uint32(pkt);
	unpack_opaque(pkt, (void **) &adminPin, &adminPinLen);
	unpack_opaque(pkt, (void **) &newUserPin, &newUserPinLen);
	err = pgpFormatToken_back(gCtx, tokNumber, 
		adminPin, adminPinLen, newUserPin, newUserPinLen );

	rpkt->status = err;
}


static void
sRecv_TokenPassphraseIsValid(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 tokNumber;
	PGPByte *passphrase;
	PGPSize passphraseLength;

	tokNumber = unpack_uint32(pkt);

⌨️ 快捷键说明

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