📄 pgprpckeyback.c
字号:
/*____________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
$Id: pgpRPCKeyBack.c,v 1.64 2002/08/06 20:11:13 dallen Exp $
____________________________________________________________________________*/
#include "pgpPubTypes.h"
#include "pgpErrors.h"
#include "pgpFileSpec.h"
#include "pgpUtilities.h"
#include "pgpKeys.h"
#include "pgpPublicKey.h"
#include "pgpRPCMsg.h"
#include "pgpKeyPriv.h"
#if PGP_WIN32
#include <windows.h>
#endif
static PGPInt32 connect_ref = 0;
#if PGP_MACINTOSH
#pragma warn_unusedarg off
#endif
PGPError
pgpConnect_backRPC()
{
PGPInt32 status;
PGPPackMsg pkt, rplypkt;
pack_init(&pkt, kPGP_Connect_MSG, 0);
pack_int32(&pkt, PGPMSG_PROTOCOL_REV);
#if PGP_WIN32
pack_uint32(&pkt, GetCurrentProcessId());
pack_uint32(&pkt,
pgpSDKGetFrontEndEventHandle( kPGPNotification_KeyDBChanged ));
pack_uint32(&pkt,
pgpSDKGetFrontEndEventHandle( kPGPNotification_PassphraseCacheChanged));
#else
pack_uint32(&pkt, 0);
pack_uint32(&pkt, 0);
#endif
status = pgpRPCSendPacket(&pkt, &rplypkt, TRUE);
/* pgpAssert( IsntPGPError(status) ); */
if (IsntPGPError(status)) {
connect_ref = unpack_int32(&rplypkt);
PGPFreeData(rplypkt.base);
}
return status;
}
PGPError
pgpReconnect_backRPC()
{
PGPInt32 status;
PGPPackMsg pkt, rplypkt;
pack_init(&pkt, kPGP_Reconnect_MSG, connect_ref);
status = pgpRPCSendPacket(&pkt, &rplypkt, TRUE);
if (IsntPGPError(status)) {
PGPFreeData(rplypkt.base);
}
return status;
}
PGPError
pgpDisconnect_backRPC()
{
PGPInt32 status;
PGPPackMsg pkt, rplypkt;
if (connect_ref == 0)
return kPGPError_NoErr;
pack_init(&pkt, kPGP_Disconnect_MSG, connect_ref);
status = pgpRPCSendPacket(&pkt, &rplypkt, TRUE);
if (IsntPGPError(status)) {
PGPFreeData(rplypkt.base);
}
connect_ref = 0;
return status;
}
PGPError
pgpFetchObjectData_backRPC(
PGPContextRef ctx,
PGPUInt32 id,
PGPByte **bufPtr, /* return parameters */
PGPSize *bufSize)
{
PGPInt32 status;
PGPPackMsg pkt, rplypkt;
(void)ctx;
pack_init(&pkt, kPGP_FetchObjectData_MSG, connect_ref);
pack_int32(&pkt, id);
status = pgpRPCSendPacket(&pkt, &rplypkt, TRUE);
if (IsntPGPError(status)) {
unpack_opaque_alloc(&rplypkt, (void **)bufPtr, bufSize);
PGPFreeData(rplypkt.base);
}
return status;
}
PGPError
pgpGetKeyByKeyID_backRPC(
PGPContextRef ctx,
PGPUInt32 dbid,
PGPKeyID const *keyIDIn,
PGPBoolean dummyOK,
PGPBoolean deletedOK,
PGPUInt32 *outID)
{
PGPInt32 status;
PGPPackMsg pkt, rplypkt;
(void)ctx;
pack_init(&pkt, kPGP_GetKeyByKeyID_MSG, connect_ref);
pack_uint32(&pkt, dbid);
pack_opaque(&pkt, (PGPByte *)keyIDIn, sizeof(*keyIDIn));
pack_bool(&pkt, dummyOK);
pack_bool(&pkt, deletedOK);
status = pgpRPCSendPacket(&pkt, &rplypkt, TRUE);
if (IsntPGPError(status)) {
*outID = unpack_uint32(&rplypkt);
PGPFreeData(rplypkt.base);
}
return status;
}
PGPError
pgpKeyEncrypt_backRPC(
PGPContextRef ctx,
PGPUInt32 id,
PGPByte const *inbuf,
PGPSize inbuflen,
PGPPublicKeyMessageFormat format,
PGPByte **outbuf,
PGPSize *outbuflen)
{
PGPInt32 status;
PGPPackMsg pkt, rplypkt;
(void)ctx;
pack_init(&pkt, kPGP_KeyEncrypt_MSG, connect_ref);
pack_uint32(&pkt, id);
pack_opaque(&pkt, (PGPByte *)inbuf, inbuflen);
pack_uint32(&pkt, (PGPUInt32)format);
status = pgpRPCSendPacket(&pkt, &rplypkt, TRUE);
if (IsntPGPError(status)) {
unpack_opaque_alloc(&rplypkt, (void **)outbuf, outbuflen);
PGPFreeData(rplypkt.base);
}
return status;
}
PGPError
pgpKeyDecrypt_backRPC(
PGPContextRef ctx,
PGPUInt32 id,
const PGPByte *passphrase,
PGPSize pplen,
PGPBoolean hashedPhrase,
PGPUInt32 cacheTimeOut, PGPBoolean cacheGlobal,
const PGPByte *inbuf,
PGPSize inbuflen,
PGPPublicKeyMessageFormat format,
PGPByte **outbuf,
PGPSize *outbuflen)
{
PGPInt32 status;
PGPPackMsg pkt, rplypkt;
(void)ctx;
pack_init_secure(&pkt, kPGP_KeyDecrypt_MSG, connect_ref);
pack_int32(&pkt, id);
pack_opaque(&pkt, passphrase, pplen);
pack_bool(&pkt, hashedPhrase);
pack_uint32(&pkt, cacheTimeOut);
pack_bool(&pkt, cacheGlobal);
pack_opaque(&pkt, (PGPByte *)inbuf, inbuflen);
pack_uint32(&pkt, (PGPUInt32)format);
status = pgpRPCSendPacket(&pkt, &rplypkt, TRUE);
if (IsntPGPError(status)) {
unpack_opaque_alloc(&rplypkt, (void **)outbuf, outbuflen);
PGPFreeData(rplypkt.base);
}
return status;
}
PGPInt32
pgpKeyVerify_backRPC(
PGPContextRef ctx,
PGPUInt32 id,
PGPByte const *inbuf,
PGPSize inbuflen,
PGPHashAlgorithm hashalg,
PGPByte const *hash,
PGPSize hashlen,
PGPPublicKeyMessageFormat format)
{
PGPInt32 status, n = 0;
PGPPackMsg pkt, rplypkt;
(void)ctx;
pack_init(&pkt, kPGP_KeyVerify_MSG, connect_ref);
pack_uint32(&pkt, id);
pack_opaque(&pkt, (PGPByte *)inbuf, inbuflen);
pack_uint32(&pkt, (PGPUInt32)hashalg);
pack_opaque(&pkt, (PGPByte *)hash, hashlen);
pack_uint32(&pkt, (PGPUInt32)format);
status = pgpRPCSendPacket(&pkt, &rplypkt, TRUE);
if (IsntPGPError(status)) {
n = unpack_int32(&rplypkt);
PGPFreeData(rplypkt.base);
}
return n;
}
PGPError
pgpKeySign_backRPC(
PGPContextRef ctx,
PGPUInt32 id,
PGPByte const *passphrase,
PGPSize pplen,
PGPBoolean hashedPhrase,
PGPUInt32 cacheTimeOut,
PGPBoolean cacheGlobal,
PGPHashAlgorithm hashalg,
PGPByte const *hash,
PGPSize hashlen,
PGPPublicKeyMessageFormat format,
PGPByte **outbuf,
PGPSize *outbuflen)
{
PGPInt32 status;
PGPPackMsg pkt, rplypkt;
(void)ctx;
pack_init_secure(&pkt, kPGP_KeySign_MSG, connect_ref);
pack_int32(&pkt, id);
pack_opaque(&pkt, (PGPByte *)passphrase, pplen);
pack_bool(&pkt, hashedPhrase);
pack_uint32(&pkt, cacheTimeOut);
pack_bool(&pkt, cacheGlobal);
pack_uint32(&pkt, (PGPUInt32)hashalg);
pack_opaque(&pkt, (PGPByte *)hash, hashlen);
pack_uint32(&pkt, (PGPUInt32)format);
status = pgpRPCSendPacket(&pkt, &rplypkt, TRUE);
if (IsntPGPError(status)) {
unpack_opaque_alloc(&rplypkt, (void **)outbuf, outbuflen);
PGPFreeData(rplypkt.base);
}
return status;
}
PGPBoolean
pgpSecPassphraseOK_backRPC(
PGPContextRef ctx,
PGPUInt32 id,
PGPByte const *passphrase,
PGPSize pplen,
PGPBoolean hashedPhrase,
PGPUInt32 cacheTimeOut,
PGPBoolean cacheGlobal )
{
PGPInt32 status;
PGPPackMsg pkt, rplypkt;
PGPBoolean b;
(void)ctx;
pack_init_secure(&pkt, kPGP_SecPassphraseOK_MSG, connect_ref);
pack_uint32(&pkt, id);
pack_opaque(&pkt, (PGPByte *)passphrase, pplen);
pack_bool(&pkt, hashedPhrase);
pack_uint32(&pkt, cacheTimeOut);
pack_bool(&pkt, cacheGlobal);
status = pgpRPCSendPacket(&pkt, &rplypkt, TRUE);
if (IsPGPError(status))
b = FALSE;
else {
b = unpack_bool(&rplypkt);
PGPFreeData(rplypkt.base);
}
return b;
}
PGPError
pgpPurgePassphraseCache_backRPC(
PGPContextRef ctx)
{
PGPInt32 status;
PGPPackMsg pkt, rplypkt;
(void)ctx;
pack_init(&pkt, kPGP_PurgePassphraseCache_MSG, connect_ref);
status = pgpRPCSendPacket(&pkt, &rplypkt, TRUE);
if (IsntPGPError(status))
PGPFreeData(rplypkt.base);
return status;
}
PGPError
pgpCountCachedPassphrases_backRPC( PGPContextRef context, PGPUInt32 *nLocals,
PGPUInt32 *nGlobals, PGPUInt32 *nOtherLocals )
{
PGPInt32 status;
PGPPackMsg pkt, rplypkt;
(void)context;
pack_init(&pkt, kPGP_CountCachedPassphrases_MSG, connect_ref);
status = pgpRPCSendPacket(&pkt, &rplypkt, TRUE);
if (IsntPGPError(status)) {
*nLocals = unpack_uint32(&rplypkt);
*nGlobals = unpack_uint32(&rplypkt);
*nOtherLocals = unpack_uint32(&rplypkt);
PGPFreeData(rplypkt.base);
}
return status;
}
PGPError
pgpKeyMaxSizes_backRPC(
PGPContextRef ctx,
PGPUInt32 id,
PGPUInt32 *maxEncryption,
PGPUInt32 *maxDecryption,
PGPUInt32 *maxSignature,
PGPPublicKeyMessageFormat format)
{
PGPInt32 status;
PGPPackMsg pkt, rplypkt;
(void)ctx;
pack_init(&pkt, kPGP_KeyMaxSizes_MSG, connect_ref);
pack_uint32(&pkt, id);
pack_bool(&pkt, (PGPBoolean)(IsntNull(maxEncryption)));
pack_bool(&pkt, (PGPBoolean)(IsntNull(maxDecryption)));
pack_bool(&pkt, (PGPBoolean)(IsntNull(maxSignature)));
pack_uint32(&pkt, (PGPUInt32)format);
status = pgpRPCSendPacket(&pkt, &rplypkt, TRUE);
if (IsntPGPError(status)) {
PGPUInt32 mymax;
mymax = unpack_uint32(&rplypkt);
if( IsntNull( maxEncryption ) )
*maxEncryption = mymax;
mymax = unpack_uint32(&rplypkt);
if( IsntNull( maxDecryption ) )
*maxDecryption = mymax;
mymax = unpack_uint32(&rplypkt);
if( IsntNull( maxSignature ) )
*maxSignature = mymax;
PGPFreeData(rplypkt.base);
}
return status;
}
PGPError
pgpSecProperties_backRPC( PGPContextRef context, PGPUInt32 id,
PGPBoolean *needsPassphrase, PGPBoolean *isSecretShared,
PGPCipherAlgorithm *lockAlg, PGPUInt32 *lockBits )
{
PGPInt32 status;
PGPPackMsg pkt, rplypkt;
(void)context;
pack_init(&pkt, kPGP_SecProperties_MSG, connect_ref);
pack_uint32(&pkt, id);
status = pgpRPCSendPacket(&pkt, &rplypkt, TRUE);
if (IsntPGPError(status)) {
*needsPassphrase = unpack_uint32(&rplypkt);
*isSecretShared = unpack_uint32(&rplypkt);
*lockAlg = (PGPCipherAlgorithm) unpack_uint32(&rplypkt);
*lockBits = unpack_uint32(&rplypkt);
PGPFreeData(rplypkt.base);
}
return status;
}
PGPError
pgpFetchKeyInfo_backRPC(
PGPContextRef ctx,
PGPUInt32 id,
PGPByte **bufPtr, /* return parameters */
PGPSize *bufSize)
{
PGPInt32 status;
PGPPackMsg pkt, rplypkt;
(void)ctx;
pack_init(&pkt, kPGP_FetchKeyInfo_MSG, connect_ref);
pack_int32(&pkt, id);
status = pgpRPCSendPacket(&pkt, &rplypkt, TRUE);
if (IsntPGPError(status)) {
unpack_opaque_alloc(&rplypkt, (void **)bufPtr, bufSize);
PGPFreeData(rplypkt.base);
}
return status;
}
PGPError
pgpOpenKeyDBFile_backRPC(
PGPContextRef ctx,
PGPOpenKeyDBFileOptions openFlags,
PFLFileSpecRef pub,
PFLFileSpecRef priv,
PGPUInt32 *kdbid, /* return parameters */
PGPUInt32 *numKeys,
PGPUInt32 **keyBuffer,
PGPSize *bufSize )
{
PGPInt32 status;
PGPPackMsg pkt, rplypkt;
(void)ctx;
pack_init(&pkt, kPGP_OpenKeyDBFile_MSG, connect_ref);
pack_int32(&pkt, openFlags);
pack_filespec(&pkt, pub);
pack_filespec(&pkt, priv);
status = pgpRPCSendPacket(&pkt, &rplypkt, TRUE);
if (IsntPGPError(status)) {
*kdbid = unpack_int32(&rplypkt);
*numKeys = unpack_int32(&rplypkt);
unpack_opaque_alloc(&rplypkt, (void **)keyBuffer, bufSize);
PGPFreeData(rplypkt.base);
}
return status;
}
PGPError
pgpImportKeyBinary_backRPC(
PGPContextRef context,
PGPByte const * buffer,
PGPSize length,
PGPUInt32 * kdbid,
PGPUInt32 * numKeys,
PGPUInt32 ** keyArray,
PGPSize * keyArraySize )
{
PGPInt32 status;
PGPPackMsg pkt, rplypkt;
(void)context;
pack_init(&pkt, kPGP_ImportKeyBinary_MSG, connect_ref);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -