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

📄 pgpkeypriv.h

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 H
📖 第 1 页 / 共 5 页
字号:
/*____________________________________________________________________________
        Copyright (C) 2002 PGP Corporation
        All rights reserved.

        $Id: pgpKeyPriv.h,v 1.132 2002/10/29 04:50:59 ajivsov Exp $
____________________________________________________________________________*/

#ifndef Included_pgpKeyPriv_h
#define Included_pgpKeyPriv_h

#include <stdio.h>

#include "pgpPFLPriv.h"
#include "pgpBinaryTree.h"
#include "pgpEventPriv.h"
#include "pgpFileRef.h"
#include "pgpTypes.h"
#include "pgpUsuals.h"
#include "pgpErrors.h"
#include "pgpMem.h"
#include "pgpMemPool.h"
#include "pgpKeyFilterPriv.h"
#include "pgpPublicKey.h"
#include "pgpSDKPriv.h"


/************************** PGPKeyDB definitions * **************************/

#include "pgpRPCMsg.h"

/* Internal keyring object type definitions */
#define RINGTYPE_KEY	1
#define RINGTYPE_SUBKEY	2
#define RINGTYPE_USERID	3
#define RINGTYPE_SIG	4
#define RINGTYPE_CRL	5
#define RINGTYPE_UNK	6	/* Object of unknown type */
#define RINGTYPE_MAX	6

#define OBJISTOPKEY(obj) (pgpObjectType(obj)==RINGTYPE_KEY)
#define OBJISSUBKEY(obj) (pgpObjectType(obj)==RINGTYPE_SUBKEY)
#define OBJISUSERID(obj) (pgpObjectType(obj)==RINGTYPE_USERID)
#define OBJISSIG(obj)	 (pgpObjectType(obj)==RINGTYPE_SIG)
#define OBJISCRL(obj)	 (pgpObjectType(obj)==RINGTYPE_CRL)
#define OBJISKEY(obj)	 (OBJISTOPKEY(obj) || OBJISSUBKEY(obj))

/* Maximum size of a keyring object we try to read */
#define PGPOBJ_MAXSIZE		150000

/* CRL type values */
#define PGPCRLTYPE_X509			1
#define PGPCRLTYPE_X509DPOINT	2

/* Signature subpacket types.  Many of these are not supported yet. */
enum sigsubbyte {
	/* Signature specific properties */
	SIGSUB_VERSION			= 1,
	SIGSUB_CREATION,
	SIGSUB_EXPIRATION,
	SIGSUB_EXPORTABLE,
	SIGSUB_TRUST,
	SIGSUB_REGEXP,
	SIGSUB_REVOCABLE,
	/* Properties of key being self signed */
	SIGSUB_KEY_CAPABILITIES = 8,
	SIGSUB_KEY_EXPIRATION,
	SIGSUB_KEY_ADDITIONAL_RECIPIENT_REQUEST,
	SIGSUB_PREFERRED_ENCRYPTION_ALGS,
	SIGSUB_KEY_REVOCATION_KEY,
	/* Hints to find signer */
	SIGSUB_KEYID			= 16,
	SIGSUB_USERID,
	SIGSUB_URL,
	SIGSUB_FINGER,
	/* Miscellaneous packets */
	SIGSUB_NOTATION			= 20,
	SIGSUB_PREFERRED_HASH_ALGS,
	SIGSUB_PREFERRED_COMPRESSION_ALGS,
	SIGSUB_KEYSERVER_PREFERENCES,
	SIGSUB_PREFERRED_KEYSERVER,
	SIGSUB_PRIMARY_USERID,
	SIGSUB_POLICY_URL,
	SIGSUB_KEYFLAGS,
	SIGSUB_SIGNER_USERID	= 28,
	SIGSUB_REVOCATION_REASON,
	/* 100-110 are for private use */
	/* Reserve 100 for internal Network Associates use */
	SIGSUB_NAI				= 100,
	/* Used internally for unrecognized packet types */
	SIGSUB_UNRECOGNIZED		= 255	/* crit bit is ignored here */
};

/* Critical bit means we must handle this subpacket */
#define SIGSUBF_CRITICAL	0x80

/* Flag bits within SIGSUB_KEYFLAGS */
#define SIGSUBF_KEYFLAG0_USAGE_CERTIFY			0x01
#define SIGSUBF_KEYFLAG0_USAGE_SIGN				0x02
#define SIGSUBF_KEYFLAG0_USAGE_ENCRYPT_COMM		0x04
#define SIGSUBF_KEYFLAG0_USAGE_ENCRYPT_STORAGE	0x08
/* Meaningful only on self signature */
#define SIGSUBF_KEYFLAG0_PRIVATE_SPLIT			0x10
#define SIGSUBF_KEYFLAG0_PRIVATE_SHARED			0x80

/* Flag bits within SIGSUB_KEYSERVER_PREFERENCES */
#define SIGSUBF_KEYSERVER0_

/* Signature sub-subpacket types, within SIGSUB_NAI packets */
enum sigsubsubbyte {
	SIGSUBSUB_X509			= 1
};

/* Version of X509 translation code */
#define SIGSUBSUB_X509_VERSION_HI	0x01
#define SIGSUBSUB_X509_VERSION_LO	0x04

#define pgpKeyUse(k)					pgpKeyUseInternal(k,FALSE,FALSE,FALSE)
#define pgpKeyUnexpiredUse(k)			pgpKeyUseInternal(k,TRUE,FALSE,FALSE)
#define pgpKeyUseRevokedOK(k)			pgpKeyUseInternal(k,FALSE,TRUE,FALSE)
#define pgpKeyUseSubkeyCanVerify(k)		pgpKeyUseInternal(k,FALSE,FALSE,TRUE)

/* CRL type values */
#define PGPCRLTYPE_X509			1
#define PGPCRLTYPE_X509DPOINT	2




/************************ PGPKeyDB Data Structures **************************/


/* This is a path or a path segment.  next->src may be unequal to dest. */
typedef struct Path {
	struct Path         *next;
	PGPKeyDBObj         *src,
	                    *dest;
	double               confidence;
	DEBUG_STRUCT_CONSTRUCTOR( Path )
} Path;

/* This is a list of paths.  Some segments may be on multiple paths. */
typedef struct PathList {
	struct PathList     *next;
	Path                *path;
	Path               **ptail;
	double               confidence;
	DEBUG_STRUCT_CONSTRUCTOR( PathList )
} PathList, *pPathList;


struct PGPKeyDB
{
#define kPGPKeyDBMagic		0x4B594442	/* 'KYDB' */
	PGPUInt32			fixedMagic;
	
	struct PGPKeyDB *next;			/* Next keydb in list */
	PGPFile *		pubFile;		/* PGPFile for public keys */
	PGPFile *		privFile;		/* PGPFile for private keys */
	PFLFileSpecRef	pubFileRef;		/* Public keyring filename */
	PFLFileSpecRef	privFileRef;	/* Private keyring filename */
	FILE *			pubStdFile;		/* Pub keyring FILE (for locking only) */
	FILE *			privStdFile;	/* Priv keyring FILE (for locking only) */
	PGPBoolean		bmutable;		/* True if a writeable database */
	PGPBoolean		bdirty;			/* True if mutableSet has been changed */
	PGPBoolean		bcached;		/* True if have a cache timeout pending */
	PGPFlags		openFlags;		/* Flags used to open keyring */
	PGPTime			cacheclose;		/* If bcached, time to close this keydb */

	PGPInt32			refCount;
	PGPContextRef		context;
	PGPKeySetRef		rootSet;

/* Linked list of all sets, used for cleanup */
	PGPKeySetRef		firstSetInDB;

/* Allocation of new objects */
	MemPool				objPool;	/* For key objects */
	MemPool				structPool;	/* For key sets and iters and such */
	PGPKeyDBObj *		oldobjs[2];	/* Cache to speed up adding keys */
	PGPKeyDBObj *		newobjs[2];

/* Pointer to actual key data */
	PGPKeyDBObj *		firstKeyInDB;
	PGPKeyDBObj *		lastKeyInDB;
	PGPKeyDBObj *		treeKey;		/* keyid-sorted tree */
	long				numKeys;


	/* Values used for trust calculations */
    MemPool				pathpool;
    Path *				paths;
	PathList *			pathlists;
	MemPool				regexps;

	/* In case of error, the following is set */
	PGPError			err;

/* Front end only */
	PGPUInt32			id;			/* Corresponding backend keydb */
	PGPBinaryTreeRef	idToObj;	/* Translate backend ids to keydbobjs */

/* Back end only */
	struct PGPNotification *notifies;	/* Pending notifications */

	DEBUG_STRUCT_CONSTRUCTOR( PGPKeyDB )
};

/************************ PGPKeySet Data Structures *************************/


/*
 * These data structures do not span frontend/backend boundaries.  Each one
 * is either entirely in front end or entirely in back end.
 */

/*
 * A KeySet is the result of applying a filter (or series of filters) to
 * the KeyDB.  It does not have an explicit list of the objects in the
 * set, but rather those are determined when we actually use it, either
 * when we sort it or iterate over it.
 */
struct PGPKeySet
{
#define kPGPKeySetMagic	0x4B534554	/* 'KSET' */
	PGPUInt32			magic;
	void *				priv;			/* Private data, used for filtering */
	PGPInt32			refCount;
	PGPKeyDBRef			keyDB;
	PGPKeySetRef		prevSetInDB;
	PGPKeySetRef		nextSetInDB;
	PGPKeyListRef		firstListInSet;
	PGPBoolean			filterSubObjects;

	PGPBoolean			(*isMember)	(PGPKeySetRef set, PGPKeyDBObjRef key);
	PGPBoolean			(*isEmpty)	(PGPKeySetRef set);
	PGPError			(*makeUnion)(PGPKeySetRef set1, PGPKeySetRef set2,
									 PGPKeySetRef *newSet);
	void				(*destroy)	(PGPKeySetRef set);

	DEBUG_STRUCT_CONSTRUCTOR( PGPKeySet )
};


/*
 * A KeyList is a sorted version of a KeySet.  One type of "sort" is
 * unordered.  If it is an ordered sort, we identify which keys are in
 * the KeyList at the time it is created, and put them in the keys array.
 * For an unordered sort, we don't do this, and we leave keys as null and
 * keyCount as zero.
 */
struct PGPKeyList
{
#define kPGPKeyListMagic	0x4B4C5354	/* 'KLST' */
	PGPUInt32			magic;
	PGPInt32			refCount;
	PGPKeySetRef		keySet;
	PGPKeyOrdering		order;
	PGPByte				reverse;		/* 0 or 1 */

	PGPKeyListRef		prevListInSet;
	PGPKeyListRef		nextListInSet;
	PGPKeyIterRef		firstIterInList;

	long				keyCount;		/* size of keys array */
	PGPKeyDBObjRef*		keys;

	DEBUG_STRUCT_CONSTRUCTOR( PGPKeyList )
} ;


/* A KeyIter is used to iterate over a KeyList. */
struct PGPKeyIter
{
#define kPGPKeyIterMagic	0x4B495452	/* 'KITR' */
	PGPUInt32			magic;
	
	PGPBoolean			isKeyList;		/* based on keylist vs keyset */
	PGPKeyListRef		keyList;		/* parent keylist */
	PGPKeySetRef		keySet;			/* parent keyset */

	PGPKeyIterRef		prevIterInList;	/* next iter in keylist */
	PGPKeyIterRef		nextIterInList;	/* next iter in keylist */

	long				keyIndex;		/* current key index in keylist */
	PGPKeyDBObjRef		currentObject;	/* ptr to current obj */
	PGPInt8				level;			/* level of obj in hierarchy */
	PGPBoolean			atEndOfLevel;	/* at end of current level? */

	DEBUG_STRUCT_CONSTRUCTOR( PGPKeyIter )
} ;


/*********************** PGPKeyDBObj Data Structures ************************/



/* Generic reference to any kind of keydb object */
struct PGPKeyDBObj {
#define kPGPKeyDBObjMagic		0x4B4F424A	/* 'KOBJ' */
	PGPUInt32		magic;
	PGPKeyDBObj *	next;					/* Next object at this level */
	PGPKeyDBObj *	down;					/* First child of this object */

⌨️ 快捷键说明

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