Blame nss/lib/pk11wrap/secmodti.h

Packit 40b132
/* This Source Code Form is subject to the terms of the Mozilla Public
Packit 40b132
 * License, v. 2.0. If a copy of the MPL was not distributed with this
Packit 40b132
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Packit 40b132
/*
Packit 40b132
 * Internal header file included only by files in pkcs11 dir, or in
Packit 40b132
 * pkcs11 specific client and server files.
Packit 40b132
 */
Packit 40b132
Packit 40b132
#ifndef  _SECMODTI_H_
Packit 40b132
#define  _SECMODTI_H_ 1
Packit 40b132
#include "prmon.h"
Packit 40b132
#include "prtypes.h"
Packit 40b132
#include "nssilckt.h"
Packit 40b132
#include "secmodt.h"
Packit 40b132
#include "pkcs11t.h"
Packit 40b132
Packit 40b132
#include "nssdevt.h"
Packit 40b132
Packit 40b132
/* internal data structures */
Packit 40b132
Packit 40b132
/* Traverse slots callback */
Packit 40b132
typedef struct pk11TraverseSlotStr {
Packit 40b132
    SECStatus (*callback)(PK11SlotInfo *,CK_OBJECT_HANDLE, void *);
Packit 40b132
    void *callbackArg;
Packit 40b132
    CK_ATTRIBUTE *findTemplate;
Packit 40b132
    int templateCount;
Packit 40b132
} pk11TraverseSlot;
Packit 40b132
Packit 40b132
Packit 40b132
/* represent a pkcs#11 slot reference counted. */
Packit 40b132
struct PK11SlotInfoStr {
Packit 40b132
    /* the PKCS11 function list for this slot */
Packit 40b132
    void *functionList;
Packit 40b132
    SECMODModule *module; /* our parent module */
Packit 40b132
    /* Boolean to indicate the current state of this slot */
Packit 40b132
    PRBool needTest;	/* Has this slot been tested for Export complience */
Packit 40b132
    PRBool isPerm;	/* is this slot a permanment device */
Packit 40b132
    PRBool isHW;	/* is this slot a hardware device */
Packit 40b132
    PRBool isInternal;  /* is this slot one of our internal PKCS #11 devices */
Packit 40b132
    PRBool disabled;	/* is this slot disabled... */
Packit 40b132
    PK11DisableReasons reason; 	/* Why this slot is disabled */
Packit 40b132
    PRBool readOnly;	/* is the token in this slot read-only */
Packit 40b132
    PRBool needLogin;	/* does the token of the type that needs 
Packit 40b132
			 * authentication (still true even if token is logged 
Packit 40b132
			 * in) */
Packit 40b132
    PRBool hasRandom;   /* can this token generated random numbers */
Packit 40b132
    PRBool defRWSession; /* is the default session RW (we open our default 
Packit 40b132
			  * session rw if the token can only handle one session
Packit 40b132
			  * at a time. */
Packit 40b132
    PRBool isThreadSafe; /* copied from the module */
Packit 40b132
    /* The actual flags (many of which are distilled into the above PRBools) */
Packit 40b132
    CK_FLAGS flags;      /* flags from PKCS #11 token Info */
Packit 40b132
    /* a default session handle to do quick and dirty functions */
Packit 40b132
    CK_SESSION_HANDLE session; 
Packit 40b132
    PZLock *sessionLock; /* lock for this session */
Packit 40b132
    /* our ID */
Packit 40b132
    CK_SLOT_ID slotID;
Packit 40b132
    /* persistant flags saved from startup to startup */
Packit 40b132
    unsigned long defaultFlags;
Packit 40b132
    /* keep track of who is using us so we don't accidently get freed while
Packit 40b132
     * still in use */
Packit 40b132
    PRInt32 refCount;    /* to be in/decremented by atomic calls ONLY! */
Packit 40b132
    PZLock *freeListLock;
Packit 40b132
    PK11SymKey *freeSymKeysWithSessionHead;
Packit 40b132
    PK11SymKey *freeSymKeysHead;
Packit 40b132
    int keyCount;
Packit 40b132
    int maxKeyCount;
Packit 40b132
    /* Password control functions for this slot. many of these are only
Packit 40b132
     * active if the appropriate flag is on in defaultFlags */
Packit 40b132
    int askpw;		/* what our password options are */
Packit 40b132
    int timeout;	/* If we're ask_timeout, what is our timeout time is 
Packit 40b132
			 * seconds */
Packit 40b132
    int authTransact;   /* allow multiple authentications off one password if
Packit 40b132
		         * they are all part of the same transaction */
Packit 40b132
    PRTime authTime;	/* when were we last authenticated */
Packit 40b132
    int minPassword;	/* smallest legal password */
Packit 40b132
    int maxPassword;	/* largest legal password */
Packit 40b132
    PRUint16 series;	/* break up the slot info into various groups of
Packit 40b132
			 * inserted tokens so that keys and certs can be
Packit 40b132
			 * invalidated */
Packit 40b132
    PRUint16 flagSeries;/* record the last series for the last event
Packit 40b132
                         * returned for this slot */
Packit 40b132
    PRBool flagState;	/* record the state of the last event returned for this
Packit 40b132
			 * slot. */
Packit 40b132
    PRUint16 wrapKey;	/* current wrapping key for SSL master secrets */
Packit 40b132
    CK_MECHANISM_TYPE wrapMechanism;
Packit 40b132
			/* current wrapping mechanism for current wrapKey */
Packit 40b132
    CK_OBJECT_HANDLE refKeys[1]; /* array of existing wrapping keys for */
Packit 40b132
    CK_MECHANISM_TYPE *mechanismList; /* list of mechanism supported by this
Packit 40b132
				       * token */
Packit 40b132
    int mechanismCount;
Packit 40b132
    /* cache the certificates stored on the token of this slot */
Packit 40b132
    CERTCertificate **cert_array;
Packit 40b132
    int array_size;
Packit 40b132
    int cert_count;
Packit 40b132
    char serial[16];
Packit 40b132
    /* since these are odd sizes, keep them last. They are odd sizes to 
Packit 40b132
     * allow them to become null terminated strings */
Packit 40b132
    char slot_name[65];
Packit 40b132
    char token_name[33];
Packit 40b132
    PRBool hasRootCerts;
Packit 40b132
    PRBool hasRootTrust;
Packit 40b132
    PRBool hasRSAInfo;
Packit 40b132
    CK_FLAGS RSAInfoFlags;
Packit 40b132
    PRBool protectedAuthPath;
Packit 40b132
    PRBool isActiveCard;
Packit 40b132
    PRIntervalTime lastLoginCheck;
Packit 40b132
    unsigned int lastState;
Packit 40b132
    /* for Stan */
Packit 40b132
    NSSToken *nssToken;
Packit 40b132
    /* fast mechanism lookup */
Packit 40b132
    char mechanismBits[256];
Packit 40b132
};
Packit 40b132
Packit 40b132
/* Symetric Key structure. Reference Counted */
Packit 40b132
struct PK11SymKeyStr {
Packit 40b132
    CK_MECHANISM_TYPE type;	/* type of operation this key was created for*/
Packit 40b132
    CK_OBJECT_HANDLE  objectID; /* object id of this key in the slot */
Packit 40b132
    PK11SlotInfo      *slot;    /* Slot this key is loaded into */
Packit 40b132
    void	      *cx;	/* window context in case we need to loggin */
Packit 40b132
    PK11SymKey	      *next;
Packit 40b132
    PRBool	      owner;
Packit 40b132
    SECItem	      data;	/* raw key data if available */
Packit 40b132
    CK_SESSION_HANDLE session;
Packit 40b132
    PRBool	      sessionOwner;
Packit 40b132
    PRInt32	      refCount;	/* number of references to this key */
Packit 40b132
    int		      size;	/* key size in bytes */
Packit 40b132
    PK11Origin	      origin;	/* where this key came from 
Packit 40b132
                                 * (see def in secmodt.h) */
Packit 40b132
    PK11SymKey        *parent;  /* potential owner key of the session */
Packit 40b132
    PRUint16 series;		/* break up the slot info into various groups
Packit 40b132
				 * of inserted tokens so that keys and certs 
Packit 40b132
				 * can be invalidated */
Packit 40b132
    void *userData;		/* random data the application can attach to
Packit 40b132
                                 * this key */
Packit 40b132
    PK11FreeDataFunc freeFunc;	/* function to free the user data */
Packit 40b132
};
Packit 40b132
Packit 40b132
Packit 40b132
/*
Packit 40b132
 * hold a hash, encryption or signing context for multi-part operations.
Packit 40b132
 * hold enough information so that multiple contexts can be interleaved
Packit 40b132
 * if necessary. ... Not RefCounted.
Packit 40b132
 */
Packit 40b132
struct PK11ContextStr {
Packit 40b132
    CK_ATTRIBUTE_TYPE	operation; /* type of operation this context is doing
Packit 40b132
				    * (CKA_ENCRYPT, CKA_SIGN, CKA_HASH, etc. */
Packit 40b132
    PK11SymKey  	*key;	   /* symetric key used in this context */
Packit 40b132
    PK11SlotInfo	*slot;	   /* slot this context is operationing on */
Packit 40b132
    CK_SESSION_HANDLE	session;   /* session this context is using */
Packit 40b132
    PZLock		*sessionLock; /* lock before accessing a PKCS #11 
Packit 40b132
				       * session */
Packit 40b132
    PRBool		ownSession;/* do we own the session? */
Packit 40b132
    void 		*cx;	   /* window context in case we need to loggin*/
Packit 40b132
    void		*savedData;/* save data when we are multiplexing on a
Packit 40b132
				    * single context */
Packit 40b132
    unsigned long	savedLength; /* length of the saved context */
Packit 40b132
    SECItem		*param;	    /* mechanism parameters used to build this
Packit 40b132
								context */
Packit 40b132
    PRBool		init;	    /* has this contexted been initialized */
Packit 40b132
    CK_MECHANISM_TYPE	type;	    /* what is the PKCS #11 this context is
Packit 40b132
				     * representing (usually what algorithm is
Packit 40b132
				     * being used (CKM_RSA_PKCS, CKM_DES,
Packit 40b132
				     * CKM_SHA, etc.*/
Packit 40b132
    PRBool		fortezzaHack; /*Fortezza SSL has some special
Packit 40b132
				       * non-standard semantics*/
Packit 40b132
};
Packit 40b132
Packit 40b132
/*
Packit 40b132
 * structure to hold a pointer to a unique PKCS #11 object 
Packit 40b132
 * (pointer to the slot and the object id).
Packit 40b132
 */
Packit 40b132
struct PK11GenericObjectStr {
Packit 40b132
    PK11GenericObject *prev;
Packit 40b132
    PK11GenericObject *next;
Packit 40b132
    PK11SlotInfo *slot;
Packit 40b132
    CK_OBJECT_HANDLE objectID;
Packit 40b132
};
Packit 40b132
Packit 40b132
Packit 40b132
#define MAX_TEMPL_ATTRS 16 /* maximum attributes in template */
Packit 40b132
Packit 40b132
/* This mask includes all CK_FLAGs with an equivalent CKA_ attribute. */
Packit 40b132
#define CKF_KEY_OPERATION_FLAGS 0x000e7b00UL
Packit 40b132
Packit 40b132
Packit 40b132
#endif /* _SECMODTI_H_ */