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

📄 pgprpcserver.c

📁 可以实现对邮件的加密解密以及签名
💻 C
📖 第 1 页 / 共 4 页
字号:
	unpack_opaque(pkt, (void **) &passphrase, &passphraseLength);
	err = pgpTokenPassphraseIsValid_back(gCtx, tokNumber,
										 passphrase, passphraseLength );
	rpkt->status = err;
}

static void
sRecv_CopyKeyToToken(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 id;
	PGPUInt32 tokNumber;
	PGPByte *passphrase;
	PGPSize passphraseLength;
	PGPBoolean hashedPhrase;
	PGPByte *PIN;
	PGPSize PINlength;
	PGPUInt32 cacheTimeOut;
	PGPBoolean cacheGlobal;
	PGPBoolean isMaster;

	id = unpack_int32(pkt);
	tokNumber = unpack_uint32(pkt);
	isMaster = unpack_bool(pkt);
	unpack_opaque(pkt, (void **) &passphrase, &passphraseLength);
	hashedPhrase = unpack_bool(pkt);
	unpack_opaque(pkt, (void **) &PIN, &PINlength);
	cacheTimeOut = unpack_uint32(pkt);
	cacheGlobal = unpack_bool(pkt);

	err = pgpCopyKeyToToken_back(gCtx,
				id, tokNumber, isMaster,
				(char *) passphrase, passphraseLength, hashedPhrase,
				(char *)PIN, PINlength, cacheTimeOut, cacheGlobal);
	rpkt->status = err;
}

static void
sRecv_TokenImportX509(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
    PGPKeyID    keyID = { 0 };
	PGPByte     *x509;
	PGPSize     x509_len;
    PGPByte     *password;
    PGPSize     passwordLength;
    PGPByte     *userID;
    PGPSize     userID_len;

    *(PGPUInt32*)&keyID = unpack_uint32(pkt);
    ((PGPUInt32*)&keyID)[1] = unpack_uint32(pkt);

    unpack_opaque(pkt, (void **) &userID, &userID_len);
	unpack_opaque(pkt, (void **) &password, &passwordLength);
	unpack_opaque(pkt, (void **) &x509, &x509_len);

	rpkt->status = pgpTokenImportX509_back(gCtx, (PGPByte*)&keyID, 
        userID,     userID_len, 
        x509,       x509_len, 
        password,   passwordLength );
}


static void
sRecv_TokenPutKeyContainer(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
    PGPKeyID    keyID = { 0 };
    PGPByte     *cont;
    PGPSize     contSize;
    const PGPByte     *password;
    PGPSize     passwordSize;

    *(PGPUInt32*)&keyID = unpack_uint32(pkt);
    ((PGPUInt32*)&keyID)[1] = unpack_uint32(pkt);

    unpack_opaque(pkt, (void **) &cont, &contSize);
    unpack_opaque(pkt, (void **) &password, &passwordSize);

    /* call to pgpTokenPutKeyContainer_internal */
	rpkt->status = pgpTokenPutKeyContainer_back( 
        gCtx, (const PGPByte*)&keyID, 
        password, passwordSize, 
        cont, contSize );
}

static void
sRecv_TokenGetKeyContainer(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
    PGPKeyID		keyID = { 0 };
    PGPByte			*cont;
    PGPSize			contSize;
    const PGPByte   *password;
    PGPSize			passwordSize;
    PGPByte			*contOut;
    PGPSize			contOutSize;

    *(PGPUInt32*)&keyID = unpack_uint32(pkt);
    ((PGPUInt32*)&keyID)[1] = unpack_uint32(pkt);

    unpack_opaque(pkt, (void **) &cont, &contSize);
    unpack_opaque(pkt, (void **) &password, &passwordSize);

    /* call to pgpTokenGetKeyContainer_internal */
	rpkt->status = pgpTokenGetKeyContainer_back( 
        gCtx, (const PGPByte*)&keyID, 
        password, passwordSize, 
        &contOut, &contOutSize );

    /* Reply */
    if( ! IsPGPError(rpkt->status) )  {
        pack_opaque(rpkt, contOut, contOutSize);
    }

    if( !IsNull( contOut ) )
        PGPFreeData( contOut );     /* Allocated in the gCtx */
}

static void
sRecv_SetPKCS11DrvFile(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPByte *module;
	PGPSize moduleLength=0;

	unpack_opaque(pkt, (void **) &module, &moduleLength);

    if( moduleLength == 0 )  
		module = NULL;

    err = pgpSetPKCS11DrvFile_back( module );

	rpkt->status = err;
}


static void
sRecv_AddUserID(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 id;
	PGPBoolean isAttribute;
	PGPAttributeType attributeType;
	PGPByte *userIDData, *passphrase;
	PGPSize userIDLength, passphraseLength;
	PGPBoolean hashedPhrase;
	PGPUInt32 cacheTimeOut;
	PGPBoolean cacheGlobal;
	PGPUInt32 *newobjs;
	PGPSize newobjsLength;

	id = unpack_int32(pkt);
	isAttribute = unpack_bool(pkt);
	attributeType = (PGPAttributeType) unpack_int32(pkt);
	unpack_opaque(pkt, (void **) &userIDData, &userIDLength);
	unpack_opaque(pkt, (void **) &passphrase, &passphraseLength);
	hashedPhrase = unpack_bool(pkt);
	cacheTimeOut = unpack_uint32(pkt);
	cacheGlobal = unpack_bool(pkt);

	err = pgpAddUserID_back(gCtx,
				id, isAttribute, attributeType,
				(char *) userIDData, userIDLength,
				(char *) passphrase, passphraseLength,
				hashedPhrase, cacheTimeOut, cacheGlobal, 
				&newobjs, &newobjsLength);
	rpkt->status = err;
	if (IsPGPError(err)) return;

	pack_opaque(rpkt, (PGPByte *)newobjs, newobjsLength);
	if( IsntNull( newobjs ) )
		PGPFreeData( newobjs );
}

static void
sRecv_CertifyUserID(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 userid, certifying_keyid;
	PGPByte *passphrase;
	PGPSize passphraseLength;
	PGPBoolean hashedPhrase;
	PGPUInt32 cacheTimeOut;
	PGPBoolean cacheGlobal;
	PGPBoolean exportable;
	PGPTime creationDate;
	PGPUInt32 expiration;
	PGPByte trustDepth;
	PGPByte trustValue;
	PGPByte *sRegExp;
	PGPSize sRegExpLength;
	PGPUInt32 *newobjs;
	PGPSize newobjsLength;

	userid = unpack_uint32(pkt);
	certifying_keyid = unpack_uint32(pkt);
	unpack_opaque(pkt, (void **) &passphrase, &passphraseLength);
	hashedPhrase = unpack_bool(pkt);
	cacheTimeOut = unpack_uint32(pkt);
	cacheGlobal = unpack_bool(pkt);
	exportable = unpack_bool(pkt);
	creationDate = unpack_uint32(pkt);
	expiration = unpack_uint32(pkt);
	trustDepth = unpack_byte(pkt);
	trustValue = unpack_byte(pkt);
	unpack_opaque(pkt, (void **) &sRegExp, &sRegExpLength);

	err = pgpCertifyUserID_back(gCtx,
			userid, certifying_keyid, (char *) passphrase, passphraseLength,
			hashedPhrase, cacheTimeOut, cacheGlobal, exportable,
			creationDate, expiration, trustDepth, trustValue,
			(char *) sRegExp, sRegExpLength,
			&newobjs, &newobjsLength);
	rpkt->status = err;
	if (IsPGPError(err)) return;

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

static void
sRecv_CertifyPrimaryUserID(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 userid;
	PGPByte *passphrase;
	PGPSize passphraseLength;
	PGPBoolean hashedPhrase;
	PGPUInt32 cacheTimeOut;
	PGPBoolean cacheGlobal;
	PGPUInt32 *newobjs;
	PGPSize newobjsLength;

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

	err = pgpCertifyPrimaryUserID_back(gCtx,
				userid, (char *) passphrase, passphraseLength,
				hashedPhrase, cacheTimeOut, cacheGlobal, &newobjs, &newobjsLength);
	rpkt->status = err;
	if (IsPGPError(err)) return;
	pack_opaque(rpkt, newobjs, newobjsLength);
	if( IsntNull( newobjs ) )
		PGPFreeData( newobjs );
}

static void
sRecv_RevokeSig(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 sigid;
	PGPByte *passphrase;
	PGPSize passphraseLength;
	PGPBoolean hashedPhrase;
	PGPUInt32 cacheTimeOut;
	PGPBoolean cacheGlobal;
	PGPUInt32 *newobjs;
	PGPSize newobjsLength;

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

	err = pgpRevokeSig_back(gCtx,
				sigid, (char *) passphrase, passphraseLength,
				hashedPhrase, cacheTimeOut, cacheGlobal, &newobjs, &newobjsLength);
	rpkt->status = err;
	if (IsPGPError(err)) return;
	pack_opaque(rpkt, newobjs, newobjsLength);
	if( IsntNull( newobjs ) )
		PGPFreeData( newobjs );
}

static void
sRecv_RevokeKey(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 key_id;
	PGPByte *passphrase;
	PGPSize passphraseLength;
	PGPBoolean hashedPhrase;
	PGPUInt32 cacheTimeOut;
	PGPBoolean cacheGlobal;
	PGPUInt32 *newobjs;
	PGPSize newobjsLength;

	key_id = unpack_int32(pkt);
	unpack_opaque(pkt, (void **) &passphrase, &passphraseLength);
	hashedPhrase = unpack_bool(pkt);
	cacheTimeOut = unpack_uint32(pkt);
	cacheGlobal = unpack_bool(pkt);

	err = pgpRevokeKey_back(gCtx,
		key_id, (char *) passphrase, passphraseLength, hashedPhrase, cacheTimeOut, cacheGlobal,
		&newobjs, &newobjsLength);
	rpkt->status = err;
	if (IsPGPError(err)) return;
	pack_opaque(rpkt, (PGPByte *)newobjs, newobjsLength);
	if( IsntNull( newobjs ) )
		PGPFreeData( newobjs );
}

static void
sRecv_DoChangePassphrase(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 keydbid, key_id, masterkey_id;
	PGPByte *oldphrase, *newphrase;
	PGPSize oldphraseLength, newphraseLength;
	PGPBoolean newpassphraseisKey;
	PGPUInt32 cacheTimeOut;
	PGPBoolean cacheGlobal;

	keydbid = unpack_uint32(pkt);
	key_id = unpack_uint32(pkt);
	masterkey_id = unpack_uint32(pkt);
	unpack_opaque(pkt, (void **) &oldphrase, &oldphraseLength);
	unpack_opaque(pkt, (void **) &newphrase, &newphraseLength);
	newpassphraseisKey = unpack_bool(pkt);
	cacheTimeOut = unpack_uint32(pkt);
	cacheGlobal = unpack_bool(pkt);

	err = pgpDoChangePassphrase_back(gCtx,
				keydbid, key_id, masterkey_id,
				(char *) oldphrase, oldphraseLength,
				(char *) newphrase, newphraseLength,
				newpassphraseisKey, cacheTimeOut, cacheGlobal);

	rpkt->status = err;
}

static void
sRecv_PassphraseIsValid(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 key_id;
	PGPByte *passphrase;
	PGPSize passphraseLength;
	PGPBoolean hashedPhrase;
	PGPBoolean isValid;
	PGPUInt32 cacheTimeOut;
	PGPBoolean cacheGlobal;

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

	err = pgpPassphraseIsValid_back(gCtx,
				key_id, (char *) passphrase, passphraseLength,
				hashedPhrase, cacheTimeOut, cacheGlobal, &isValid);
	rpkt->status = err;
	if (IsPGPError(err)) return;
	pack_bool(rpkt, isValid);
}

static void
sRecv_SetKeyTrust(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 key_id, trust;

	key_id = unpack_uint32(pkt);
	trust = unpack_uint32(pkt);

	err = pgpSetKeyTrust_back(gCtx, key_id, trust);
	rpkt->status = err;
	if (IsPGPError(err)) return;
}

static void
sRecv_GetPasskeyBuffer(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 key_id;
	PGPByte *passphrase;
	PGPSize passphraseLength;
	PGPByte *passkeyBuffer;
	PGPSize passkeyBufferLength;

	key_id = unpack_uint32(pkt);
	unpack_opaque(pkt, (void **) &passphrase, &passphraseLength);

	err = pgpGetPasskeyBuffer_back(gCtx,
				key_id, (char *) passphrase, passphraseLength,
				&passkeyBuffer, &passkeyBufferLength);
	rpkt->status = err;
	if (IsPGPError(err)) return;
	pack_opaque(rpkt, passkeyBuffer, passkeyBufferLength);
	if( IsntNull( passkeyBuffer ) )
		PGPFreeData( passkeyBuffer );
}

static void
sRecv_AddKeyOptions(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 key_id;
	PGPByte *passphrase;
	PGPSize passphraseLength;
	PGPBoolean hashedPhrase;
	PGPUInt32 cacheTimeOut;
	PGPBoolean cacheGlobal;
	PGPUInt32 *raklist;
	PGPSize raklistsize;
	PGPUInt32 rakclass;
	PGPUInt32 *newobjs;
	PGPSize newobjsLength;

	key_id = unpack_uint32(pkt);
	unpack_opaque(pkt, (void **) &passphrase, &passphraseLength);
	hashedPhrase = unpack_bool(pkt);
	cacheTimeOut = unpack_uint32(pkt);
	cacheGlobal = unpack_bool(pkt);
	unpack_opaque_alloc(pkt, (void **) &raklist, &raklistsize);
	rakclass = unpack_uint32(pkt);

	err = pgpAddKeyOptions_back(gCtx,
				key_id, (char *) passphrase, passphraseLength, hashedPhrase,
				cacheTimeOut, cacheGlobal, raklist, raklistsize, rakclass, 
				&newobjs, &newobjsLength);
	rpkt->status = err;
	if (IsPGPError(err)) return;
	pack_opaque(rpkt, newobjs, newobjsLength);
	if( IsntNull( newobjs ) )
		PGPFreeData( newobjs );
}

static void
sRecv_UpdateKeyOptions(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 key_id;
	PGPByte *passphrase;
	PGPSize passphraseLength;
	PGPBoolean hashedPhrase;
	PGPUInt32 cacheTimeOut;
	PGPBoolean cacheGlobal;
	PGPCipherAlgorithm *prefalg;
	PGPSize prefalgLength;
	PGPByte *prefkeyserv;
	PGPSize prefkeyservLength;
	PGPUInt32 keyflags;
	PGPBoolean fkeyflags;
	PGPUInt32 keyservprefs;
	PGPBoolean fkeyservprefs;
	PGPUInt32 *newobjs;
	PGPSize newobjsLength;

	key_id = unpack_uint32(pkt);
	unpack_opaque(pkt, (void **) &passphrase, &passphraseLength);
	hashedPhrase = unpack_bool(pkt);
	cacheTimeOut = unpack_uint32(pkt);
	cacheGlobal = unpack_bool(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 = pgpUpdateKeyOptions_back(gCtx,
				key_id, (char *) passphrase, passphraseLength,
				hashedPhrase, cacheTimeOut, cacheGlobal, prefalg, prefalgLength,
				prefkeyserv, prefkeyservLength, keyflags, fkeyflags,
				keyservprefs, fkeyservprefs, &newobjs, &newobjsLength);
	rpkt->status = err;
	if (IsPGPError(err)) return;
	pack_opaque(rpkt, newobjs, newobjsLength);
	if( IsntNull( newobjs ) )
		PGPFreeData( newobjs );
}

static void
sRecv_KeyDBAddObject(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 kdb_id;
	PGPUInt32 obj_id;
	PGPUInt32 *newobjs;
	PGPSize newobjsLength;
	PGPUInt32 pnewobj;

	kdb_id = unpack_uint32(pkt);
	obj_id = unpack_uint32(pkt);

	err = pgpKeyDBAddObject_back(gCtx,
			kdb_id, obj_id, &newobjs, &newobjsLength, &pnewobj);
	rpkt->status = err;
	if (IsPGPError(err)) return;
	pack_opaque(rpkt, newobjs, newobjsLength);
	if( IsntNull( newobjs ) )
		PGPFreeData( newobjs );
	pack_uint32(rpkt, pnewobj);
}

static void
sRecv_KeyDBRemoveObject(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 kdb_id, obj_id;

	kdb_id = unpack_uint32(pkt);
	obj_id = unpack_uint32(pkt);

	err = pgpKeyDBRemoveObject_back(gCtx, kdb_id, obj_id);
	rpkt->status = err;
	if (IsPGPError(err)) return;
}

static void
sRecv_CopyKeys(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPUInt32 srcid, dstid, *keylist;
	PGPSize keylistsize;
	PGPBoolean neednewkeylist;
	PGPUInt32 *newkeylist = NULL;
	PGPSize newkeylistsize;

	srcid = unpack_uint32(pkt);
	dstid = unpack_uint32(pkt);
	unpack_opaque_alloc(pkt, (void **) &keylist, &keylistsize);
	neednewkeylist = unpack_bool(pkt);

	err = pgpCopyKeys_back(gCtx,
			srcid, dstid, keylist, keylistsize, neednewkeylist,
			(neednewkeylist ? &newkeylist : NULL),
			(neednewkeylist ? &newkeylistsize : NULL) );
	rpkt->status = err;
	if (IsPGPError(err)) return;
	if( neednewkeylist )
		pack_opaque(rpkt, (PGPByte *)newkeylist, newkeylistsize);
	if( IsntNull( newkeylist ) )
		PGPFreeData( newkeylist );
}

static void
sRecv_ImportKeyBinary(PGPPackMsg *pkt, PGPPackMsg *rpkt)
{
	PGPError err;
	PGPByte *buffer;
	PGPSize length;
	PGPUInt32 kdbid, numKeys, *keyArray;
	PGPSize	keyArraySize;
	
	unpack_opaque(pkt, (void **) &buffer, &length);

	err = pgpImportKeyBinary_back(gCtx,
			buffer, length,  &kdbid, &numKeys, &keyArray, &keyArraySize);

⌨️ 快捷键说明

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