Blame nss/lib/pk11wrap/pk11pub.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
#ifndef _PK11PUB_H_
Packit 40b132
#define _PK11PUB_H_
Packit 40b132
#include "plarena.h"
Packit 40b132
#include "seccomon.h"
Packit 40b132
#include "secoidt.h"
Packit 40b132
#include "secdert.h"
Packit 40b132
#include "keyt.h"
Packit 40b132
#include "certt.h"
Packit 40b132
#include "pkcs11t.h"
Packit 40b132
#include "secmodt.h"
Packit 40b132
#include "seccomon.h"
Packit 40b132
#include "pkcs7t.h"
Packit 40b132
#include "cmsreclist.h"
Packit 40b132
Packit 40b132
/*
Packit 40b132
 * Exported PK11 wrap functions.
Packit 40b132
 */
Packit 40b132
Packit 40b132
SEC_BEGIN_PROTOS
Packit 40b132
Packit 40b132
/************************************************************
Packit 40b132
 * Generic Slot Lists Management
Packit 40b132
 ************************************************************/
Packit 40b132
void PK11_FreeSlotList(PK11SlotList *list);
Packit 40b132
SECStatus PK11_FreeSlotListElement(PK11SlotList *list, PK11SlotListElement *le);
Packit 40b132
PK11SlotListElement * PK11_GetFirstSafe(PK11SlotList *list);
Packit 40b132
PK11SlotListElement *PK11_GetNextSafe(PK11SlotList *list, 
Packit 40b132
				PK11SlotListElement *le, PRBool restart);
Packit 40b132
Packit 40b132
/************************************************************
Packit 40b132
 * Generic Slot Management
Packit 40b132
 ************************************************************/
Packit 40b132
PK11SlotInfo *PK11_ReferenceSlot(PK11SlotInfo *slot);
Packit 40b132
void PK11_FreeSlot(PK11SlotInfo *slot);
Packit 40b132
SECStatus PK11_DestroyObject(PK11SlotInfo *slot,CK_OBJECT_HANDLE object);
Packit 40b132
SECStatus PK11_DestroyTokenObject(PK11SlotInfo *slot,CK_OBJECT_HANDLE object);
Packit 40b132
PK11SlotInfo *PK11_GetInternalKeySlot(void);
Packit 40b132
PK11SlotInfo *PK11_GetInternalSlot(void);
Packit 40b132
SECStatus PK11_Logout(PK11SlotInfo *slot);
Packit 40b132
void PK11_LogoutAll(void);
Packit 40b132
Packit 40b132
Packit 40b132
/************************************************************
Packit 40b132
 *  Slot Password Management
Packit 40b132
 ************************************************************/
Packit 40b132
void PK11_SetSlotPWValues(PK11SlotInfo *slot,int askpw, int timeout);
Packit 40b132
void PK11_GetSlotPWValues(PK11SlotInfo *slot,int *askpw, int *timeout);
Packit 40b132
SECStatus PK11_CheckSSOPassword(PK11SlotInfo *slot, char *ssopw);
Packit 40b132
SECStatus PK11_CheckUserPassword(PK11SlotInfo *slot, const char *pw);
Packit 40b132
PRBool PK11_IsLoggedIn(PK11SlotInfo *slot, void *wincx);
Packit 40b132
SECStatus PK11_InitPin(PK11SlotInfo *slot,const char *ssopw,
Packit 40b132
                       const char *pk11_userpwd);
Packit 40b132
SECStatus PK11_ChangePW(PK11SlotInfo *slot, const char *oldpw,
Packit 40b132
                        const char *newpw);
Packit 40b132
void PK11_SetPasswordFunc(PK11PasswordFunc func);
Packit 40b132
int PK11_GetMinimumPwdLength(PK11SlotInfo *slot);
Packit 40b132
SECStatus PK11_ResetToken(PK11SlotInfo *slot, char *sso_pwd);
Packit 40b132
SECStatus PK11_Authenticate(PK11SlotInfo *slot, PRBool loadCerts, void *wincx);
Packit 40b132
SECStatus PK11_TokenRefresh(PK11SlotInfo *slot);
Packit 40b132
Packit 40b132
Packit 40b132
/******************************************************************
Packit 40b132
 *           Slot info functions
Packit 40b132
 ******************************************************************/
Packit 40b132
PK11SlotInfo *PK11_FindSlotByName(const char *name);
Packit 40b132
/******************************************************************
Packit 40b132
 * PK11_FindSlotsByNames searches for a PK11SlotInfo using one or
Packit 40b132
 * more criteria : dllName, slotName and tokenName . In addition, if
Packit 40b132
 * presentOnly is set , only slots with a token inserted will be
Packit 40b132
 * returned.
Packit 40b132
 ******************************************************************/
Packit 40b132
PK11SlotList *PK11_FindSlotsByNames(const char *dllName,
Packit 40b132
        const char* slotName, const char* tokenName, PRBool presentOnly);
Packit 40b132
PRBool PK11_IsReadOnly(PK11SlotInfo *slot);
Packit 40b132
PRBool PK11_IsInternal(PK11SlotInfo *slot);
Packit 40b132
PRBool PK11_IsInternalKeySlot(PK11SlotInfo *slot);
Packit 40b132
char * PK11_GetTokenName(PK11SlotInfo *slot);
Packit 40b132
char * PK11_GetSlotName(PK11SlotInfo *slot);
Packit 40b132
PRBool PK11_NeedLogin(PK11SlotInfo *slot);
Packit 40b132
PRBool PK11_IsFriendly(PK11SlotInfo *slot);
Packit 40b132
PRBool PK11_IsHW(PK11SlotInfo *slot);
Packit 40b132
PRBool PK11_IsRemovable(PK11SlotInfo *slot);
Packit 40b132
PRBool PK11_NeedUserInit(PK11SlotInfo *slot);
Packit 40b132
PRBool PK11_ProtectedAuthenticationPath(PK11SlotInfo *slot);
Packit 40b132
int PK11_GetSlotSeries(PK11SlotInfo *slot);
Packit 40b132
int PK11_GetCurrentWrapIndex(PK11SlotInfo *slot);
Packit 40b132
unsigned long PK11_GetDefaultFlags(PK11SlotInfo *slot);
Packit 40b132
CK_SLOT_ID PK11_GetSlotID(PK11SlotInfo *slot);
Packit 40b132
SECMODModuleID PK11_GetModuleID(PK11SlotInfo *slot);
Packit 40b132
SECStatus PK11_GetSlotInfo(PK11SlotInfo *slot, CK_SLOT_INFO *info);
Packit 40b132
SECStatus PK11_GetTokenInfo(PK11SlotInfo *slot, CK_TOKEN_INFO *info);
Packit 40b132
PRBool PK11_IsDisabled(PK11SlotInfo *slot);
Packit 40b132
PRBool PK11_HasRootCerts(PK11SlotInfo *slot);
Packit 40b132
PK11DisableReasons PK11_GetDisabledReason(PK11SlotInfo *slot);
Packit 40b132
/* Prevents the slot from being used, and set disable reason to user-disable */
Packit 40b132
/* NOTE: Mechanisms that were ON continue to stay ON */
Packit 40b132
/*       Therefore, when the slot is enabled, it will remember */
Packit 40b132
/*       what mechanisms needs to be turned on */
Packit 40b132
PRBool PK11_UserDisableSlot(PK11SlotInfo *slot);
Packit 40b132
/* Allow all mechanisms that are ON before UserDisableSlot() */
Packit 40b132
/* was called to be available again */
Packit 40b132
PRBool PK11_UserEnableSlot(PK11SlotInfo *slot);
Packit 40b132
/*
Packit 40b132
 * wait for a specific slot event.
Packit 40b132
 * event is a specific event to wait for. Currently only 
Packit 40b132
 *    PK11TokenChangeOrRemovalEvent and PK11TokenPresentEvents are defined.
Packit 40b132
 * timeout can be an interval time to wait, PR_INTERVAL_NO_WAIT (meaning only
Packit 40b132
 * poll once), or PR_INTERVAL_NO_TIMEOUT (meaning block until a change).
Packit 40b132
 * pollInterval is a suggested pulling interval value. '0' means use the 
Packit 40b132
 *  default. Future implementations that don't poll may ignore this value.
Packit 40b132
 * series is the current series for the last slot. This should be the series 
Packit 40b132
 *  value for the slot the last time you read persistant information from the
Packit 40b132
 *  slot. For instance, if you publish a cert from the slot, you should obtain
Packit 40b132
 *  the slot series at that time. Then PK11_WaitForTokenEvent can detect a 
Packit 40b132
 *  a change in the slot between the time you publish and the time 
Packit 40b132
 *  PK11_WaitForTokenEvent is called, elliminating potential race conditions.
Packit 40b132
 *
Packit 40b132
 * The current status that is returned is:
Packit 40b132
 *   PK11TokenNotRemovable - always returned for any non-removable token.
Packit 40b132
 *   PK11TokenPresent - returned when the token is present and we are waiting
Packit 40b132
 *     on a PK11TokenPresentEvent. Then next event to look for is a 
Packit 40b132
 *     PK11TokenChangeOrRemovalEvent.
Packit 40b132
 *   PK11TokenChanged - returned when the old token has been removed and a new
Packit 40b132
 *     token ad been inserted, and we are waiting for a 
Packit 40b132
 *     PK11TokenChangeOrRemovalEvent. The next event to look for is another
Packit 40b132
 *     PK11TokenChangeOrRemovalEvent.
Packit 40b132
 *   PK11TokenRemoved - returned when the token is not present and we are 
Packit 40b132
 *     waiting for a PK11TokenChangeOrRemovalEvent. The next event to look for 
Packit 40b132
 *     is a PK11TokenPresentEvent.
Packit 40b132
 */
Packit 40b132
PK11TokenStatus PK11_WaitForTokenEvent(PK11SlotInfo *slot, PK11TokenEvent event,
Packit 40b132
	PRIntervalTime timeout, PRIntervalTime pollInterval, int series);
Packit 40b132
Packit 40b132
PRBool PK11_NeedPWInit(void);
Packit 40b132
PRBool PK11_TokenExists(CK_MECHANISM_TYPE);
Packit 40b132
SECStatus PK11_GetModInfo(SECMODModule *mod, CK_INFO *info);
Packit 40b132
PRBool PK11_IsFIPS(void);
Packit 40b132
SECMODModule *PK11_GetModule(PK11SlotInfo *slot);
Packit 40b132
Packit 40b132
/*********************************************************************
Packit 40b132
 *            Slot mapping utility functions.
Packit 40b132
 *********************************************************************/
Packit 40b132
PRBool PK11_IsPresent(PK11SlotInfo *slot);
Packit 40b132
PRBool PK11_DoesMechanism(PK11SlotInfo *slot, CK_MECHANISM_TYPE type);
Packit 40b132
PK11SlotList * PK11_GetAllTokens(CK_MECHANISM_TYPE type,PRBool needRW,
Packit 40b132
					PRBool loadCerts, void *wincx);
Packit 40b132
PK11SlotInfo *PK11_GetBestSlotMultipleWithAttributes(CK_MECHANISM_TYPE *type, 
Packit 40b132
		CK_FLAGS *mechFlag, unsigned int *keySize, 
Packit 40b132
		unsigned int count, void *wincx);
Packit 40b132
PK11SlotInfo *PK11_GetBestSlotMultiple(CK_MECHANISM_TYPE *type, 
Packit 40b132
					unsigned int count, void *wincx);
Packit 40b132
PK11SlotInfo *PK11_GetBestSlot(CK_MECHANISM_TYPE type, void *wincx);
Packit 40b132
PK11SlotInfo *PK11_GetBestSlotWithAttributes(CK_MECHANISM_TYPE type, 
Packit 40b132
		CK_FLAGS mechFlag, unsigned int keySize, void *wincx);
Packit 40b132
CK_MECHANISM_TYPE PK11_GetBestWrapMechanism(PK11SlotInfo *slot);
Packit 40b132
int PK11_GetBestKeyLength(PK11SlotInfo *slot, CK_MECHANISM_TYPE type);
Packit 40b132
Packit 40b132
/*
Packit 40b132
 * Open a new database using the softoken. The caller is responsible for making
Packit 40b132
 * sure the module spec is correct and usable. The caller should ask for one
Packit 40b132
 * new database per call if the caller wants to get meaningful information
Packit 40b132
 * about the new database.
Packit 40b132
 *
Packit 40b132
 * moduleSpec is the same data that you would pass to softoken at
Packit 40b132
 * initialization time under the 'tokens' options. For example, if you were
Packit 40b132
 * to specify tokens=<0x4=[configdir='./mybackup' tokenDescription='Backup']>
Packit 40b132
 * You would specify "configdir='./mybackup' tokenDescription='Backup'" as your
Packit 40b132
 * module spec here. The slot ID will be calculated for you by
Packit 40b132
 * SECMOD_OpenUserDB().
Packit 40b132
 *
Packit 40b132
 * Typical parameters here are configdir, tokenDescription and flags.
Packit 40b132
 *
Packit 40b132
 * a Full list is below:
Packit 40b132
 *
Packit 40b132
 *
Packit 40b132
 *  configDir - The location of the databases for this token. If configDir is
Packit 40b132
 *         not specified, and noCertDB and noKeyDB is not specified, the load
Packit 40b132
 *         will fail.
Packit 40b132
 *   certPrefix - Cert prefix for this token.
Packit 40b132
 *   keyPrefix - Prefix for the key database for this token. (if not specified,
Packit 40b132
 *         certPrefix will be used).
Packit 40b132
 *   tokenDescription - The label value for this token returned in the
Packit 40b132
 *         CK_TOKEN_INFO structure with an internationalize string (UTF8).
Packit 40b132
 *         This value will be truncated at 32 bytes (no NULL, partial UTF8
Packit 40b132
 *         characters dropped). You should specify a user friendly name here
Packit 40b132
 *         as this is the value the token will be referred to in most
Packit 40b132
 *         application UI's. You should make sure tokenDescription is unique.
Packit 40b132
 *   slotDescription - The slotDescription value for this token returned
Packit 40b132
 *         in the CK_SLOT_INFO structure with an internationalize string
Packit 40b132
 *         (UTF8). This value will be truncated at 64 bytes (no NULL, partial
Packit 40b132
 *         UTF8 characters dropped). This name will not change after the
Packit 40b132
 *         database is closed. It should have some number to make this unique.
Packit 40b132
 *   minPWLen - minimum password length for this token.
Packit 40b132
 *   flags - comma separated list of flag values, parsed case-insensitive.
Packit 40b132
 *         Valid flags are:
Packit 40b132
 *              readOnly - Databases should be opened read only.
Packit 40b132
 *              noCertDB - Don't try to open a certificate database.
Packit 40b132
 *              noKeyDB - Don't try to open a key database.
Packit 40b132
 *              forceOpen - Don't fail to initialize the token if the
Packit 40b132
 *                databases could not be opened.
Packit 40b132
 *              passwordRequired - zero length passwords are not acceptable
Packit 40b132
 *                (valid only if there is a keyDB).
Packit 40b132
 *              optimizeSpace - allocate smaller hash tables and lock tables.
Packit 40b132
 *                When this flag is not specified, Softoken will allocate
Packit 40b132
 *                large tables to prevent lock contention.
Packit 40b132
 */
Packit 40b132
PK11SlotInfo *SECMOD_OpenUserDB(const char *moduleSpec);
Packit 40b132
SECStatus SECMOD_CloseUserDB(PK11SlotInfo *slot);
Packit 40b132
Packit 40b132
/*
Packit 40b132
 * This is exactly the same as OpenUserDB except it can be called on any
Packit 40b132
 * module that understands softoken style new slot entries. The resulting
Packit 40b132
 * slot can be closed using SECMOD_CloseUserDB above. Value of moduleSpec
Packit 40b132
 * is token specific.
Packit 40b132
 */
Packit 40b132
PK11SlotInfo *SECMOD_OpenNewSlot(SECMODModule *mod, const char *moduleSpec);
Packit 40b132
Packit 40b132
Packit 40b132
/*
Packit 40b132
 * merge the permanent objects from on token to another 
Packit 40b132
 */
Packit 40b132
SECStatus PK11_MergeTokens(PK11SlotInfo *targetSlot, PK11SlotInfo *sourceSlot,
Packit 40b132
                PK11MergeLog *log, void *targetPwArg, void *sourcePwArg);
Packit 40b132
Packit 40b132
/*
Packit 40b132
 * create and destroy merge logs needed by PK11_MergeTokens
Packit 40b132
 */
Packit 40b132
PK11MergeLog * PK11_CreateMergeLog(void);
Packit 40b132
void PK11_DestroyMergeLog(PK11MergeLog *log);
Packit 40b132
Packit 40b132
Packit 40b132
Packit 40b132
/*********************************************************************
Packit 40b132
 *       Mechanism Mapping functions
Packit 40b132
 *********************************************************************/
Packit 40b132
CK_KEY_TYPE PK11_GetKeyType(CK_MECHANISM_TYPE type,unsigned long len);
Packit 40b132
CK_MECHANISM_TYPE PK11_GetKeyGen(CK_MECHANISM_TYPE type);
Packit 40b132
int PK11_GetBlockSize(CK_MECHANISM_TYPE type,SECItem *params);
Packit 40b132
int PK11_GetIVLength(CK_MECHANISM_TYPE type);
Packit 40b132
SECItem *PK11_ParamFromIV(CK_MECHANISM_TYPE type,SECItem *iv);
Packit 40b132
unsigned char *PK11_IVFromParam(CK_MECHANISM_TYPE type,SECItem *param,int *len);
Packit 40b132
SECItem * PK11_BlockData(SECItem *data,unsigned long size);
Packit 40b132
Packit 40b132
/* PKCS #11 to DER mapping functions */
Packit 40b132
SECItem *PK11_ParamFromAlgid(SECAlgorithmID *algid);
Packit 40b132
SECItem *PK11_GenerateNewParam(CK_MECHANISM_TYPE, PK11SymKey *);
Packit 40b132
CK_MECHANISM_TYPE PK11_AlgtagToMechanism(SECOidTag algTag);
Packit 40b132
SECOidTag PK11_MechanismToAlgtag(CK_MECHANISM_TYPE type);
Packit 40b132
SECOidTag PK11_FortezzaMapSig(SECOidTag algTag);
Packit 40b132
SECStatus PK11_ParamToAlgid(SECOidTag algtag, SECItem *param,
Packit 40b132
                                   PLArenaPool *arena, SECAlgorithmID *algid);
Packit 40b132
SECStatus PK11_SeedRandom(PK11SlotInfo *,unsigned char *data,int len);
Packit 40b132
SECStatus PK11_GenerateRandomOnSlot(PK11SlotInfo *,unsigned char *data,int len);
Packit 40b132
SECStatus PK11_RandomUpdate(void *data, size_t bytes);
Packit 40b132
SECStatus PK11_GenerateRandom(unsigned char *data,int len);
Packit 40b132
Packit 40b132
/* warning: cannot work with pkcs 5 v2
Packit 40b132
 * use algorithm ID s instead of pkcs #11 mechanism pointers */
Packit 40b132
CK_RV PK11_MapPBEMechanismToCryptoMechanism(CK_MECHANISM_PTR pPBEMechanism,
Packit 40b132
					    CK_MECHANISM_PTR pCryptoMechanism,
Packit 40b132
					    SECItem *pbe_pwd, PRBool bad3DES);
Packit 40b132
CK_MECHANISM_TYPE PK11_GetPadMechanism(CK_MECHANISM_TYPE);
Packit 40b132
CK_MECHANISM_TYPE PK11_MapSignKeyType(KeyType keyType);
Packit 40b132
Packit 40b132
/**********************************************************************
Packit 40b132
 *                   Symmetric, Public, and Private Keys 
Packit 40b132
 **********************************************************************/
Packit 40b132
void PK11_FreeSymKey(PK11SymKey *key);
Packit 40b132
PK11SymKey *PK11_ReferenceSymKey(PK11SymKey *symKey);
Packit 40b132
PK11SymKey *PK11_ImportSymKey(PK11SlotInfo *slot, CK_MECHANISM_TYPE type,
Packit 40b132
    PK11Origin origin, CK_ATTRIBUTE_TYPE operation, SECItem *key, void *wincx);
Packit 40b132
PK11SymKey *PK11_ImportSymKeyWithFlags(PK11SlotInfo *slot, 
Packit 40b132
    CK_MECHANISM_TYPE type, PK11Origin origin, CK_ATTRIBUTE_TYPE operation, 
Packit 40b132
    SECItem *key, CK_FLAGS flags, PRBool isPerm, void *wincx);
Packit 40b132
PK11SymKey *PK11_SymKeyFromHandle(PK11SlotInfo *slot, PK11SymKey *parent,
Packit 40b132
    PK11Origin origin, CK_MECHANISM_TYPE type, CK_OBJECT_HANDLE keyID, 
Packit 40b132
    PRBool owner, void *wincx);
Packit 40b132
PK11SymKey *PK11_GetWrapKey(PK11SlotInfo *slot, int wrap,
Packit 40b132
			      CK_MECHANISM_TYPE type,int series, void *wincx);
Packit 40b132
/*
Packit 40b132
 * This function is not thread-safe.  It can only be called when only
Packit 40b132
 * one thread has a reference to wrapKey.
Packit 40b132
 */
Packit 40b132
void PK11_SetWrapKey(PK11SlotInfo *slot, int wrap, PK11SymKey *wrapKey);
Packit 40b132
CK_MECHANISM_TYPE PK11_GetMechanism(PK11SymKey *symKey);
Packit 40b132
/*
Packit 40b132
 * import a public key into the desired slot
Packit 40b132
 *  
Packit 40b132
 * This function takes a public key structure and creates a public key in a 
Packit 40b132
 * given slot. If isToken is set, then a persistant public key is created.
Packit 40b132
 *
Packit 40b132
 * Note: it is possible for this function to return a handle for a key which
Packit 40b132
 * is persistant, even if isToken is not set.
Packit 40b132
 */
Packit 40b132
CK_OBJECT_HANDLE PK11_ImportPublicKey(PK11SlotInfo *slot, 
Packit 40b132
				SECKEYPublicKey *pubKey, PRBool isToken);
Packit 40b132
PK11SymKey *PK11_KeyGen(PK11SlotInfo *slot,CK_MECHANISM_TYPE type,
Packit 40b132
				SECItem *param,	int keySize,void *wincx);
Packit 40b132
PK11SymKey *PK11_TokenKeyGen(PK11SlotInfo *slot, CK_MECHANISM_TYPE type,
Packit 40b132
				SECItem *param, int keySize, SECItem *keyid,
Packit 40b132
				PRBool isToken, void *wincx);
Packit 40b132
PK11SymKey *PK11_TokenKeyGenWithFlags(PK11SlotInfo *slot,
Packit 40b132
				CK_MECHANISM_TYPE type, SECItem *param,
Packit 40b132
				int keySize, SECItem *keyid, CK_FLAGS opFlags,
Packit 40b132
				PK11AttrFlags attrFlags, void *wincx);
Packit 40b132
/* Generates a key using the exact template supplied by the caller. The other
Packit 40b132
 * PK11_[Token]KeyGen mechanisms should be used instead of this one whenever
Packit 40b132
 * they work because they include/exclude the CKA_VALUE_LEN template value
Packit 40b132
 * based on the mechanism type as required by many tokens.
Packit 40b132
 * 
Packit 40b132
 * keyGenType should be PK11_GetKeyGenWithSize(type, <key size>) or it should
Packit 40b132
 * be equal to type if PK11_GetKeyGenWithSize cannot be used (e.g. because
Packit 40b132
 * pk11wrap does not know about the mechanisms).
Packit 40b132
 */
Packit 40b132
PK11SymKey *PK11_KeyGenWithTemplate(PK11SlotInfo *slot, CK_MECHANISM_TYPE type,
Packit 40b132
                                    CK_MECHANISM_TYPE keyGenType,
Packit 40b132
                                    SECItem *param, CK_ATTRIBUTE * attrs,
Packit 40b132
                                    unsigned int attrsCount, void *wincx);
Packit 40b132
PK11SymKey * PK11_ListFixedKeysInSlot(PK11SlotInfo *slot, char *nickname,
Packit 40b132
								void *wincx);
Packit 40b132
PK11SymKey *PK11_GetNextSymKey(PK11SymKey *symKey);
Packit 40b132
CK_KEY_TYPE PK11_GetSymKeyType(PK11SymKey *key);
Packit 40b132
CK_OBJECT_HANDLE PK11_GetSymKeyHandle(PK11SymKey *symKey);
Packit 40b132
Packit 40b132
Packit 40b132
/*
Packit 40b132
 * PK11_SetSymKeyUserData
Packit 40b132
 *   sets generic user data on keys (usually a pointer to a data structure)
Packit 40b132
 * that can later be retrieved by PK11_GetSymKeyUserData().
Packit 40b132
 *    symKey - key where data will be set.
Packit 40b132
 *    data - data to be set.
Packit 40b132
 *    freefunc - function used to free the data.
Packit 40b132
 * Setting user data on symKeys with existing user data already set will cause 
Packit 40b132
 * the existing user data to be freed before the new user data is set.
Packit 40b132
 * Freeing user data is done by calling the user specified freefunc. 
Packit 40b132
 * If freefunc is NULL, the user data is assumed to be global or static an 
Packit 40b132
 * not freed. Passing NULL for user data to PK11_SetSymKeyUserData has the 
Packit 40b132
 * effect of freeing any existing user data, and clearing the user data 
Packit 40b132
 * pointer. If user data exists when the symKey is finally freed, that 
Packit 40b132
 * data will be freed with freefunc.
Packit 40b132
 *
Packit 40b132
 * Applications should only use this function on keys which the application
Packit 40b132
 * has created directly, as there is only one user data value per key.
Packit 40b132
 */
Packit 40b132
void PK11_SetSymKeyUserData(PK11SymKey *symKey, void *data, 
Packit 40b132
                                 PK11FreeDataFunc freefunc);
Packit 40b132
/* PK11_GetSymKeyUserData 
Packit 40b132
 *   retrieves generic user data which was set on a key by 
Packit 40b132
 * PK11_SetSymKeyUserData.
Packit 40b132
 *    symKey - key with data to be fetched
Packit 40b132
 *
Packit 40b132
 * If no data exists, or the data has been cleared, PK11_GetSymKeyUserData
Packit 40b132
 * will return NULL. Returned data is still owned and managed by the SymKey,
Packit 40b132
 * the caller should not free the data.
Packit 40b132
 *
Packit 40b132
 */
Packit 40b132
void *PK11_GetSymKeyUserData(PK11SymKey *symKey);
Packit 40b132
Packit 40b132
SECStatus PK11_PubWrapSymKey(CK_MECHANISM_TYPE type, SECKEYPublicKey *pubKey,
Packit 40b132
				PK11SymKey *symKey, SECItem *wrappedKey);
Packit 40b132
SECStatus PK11_WrapSymKey(CK_MECHANISM_TYPE type, SECItem *params,
Packit 40b132
	 PK11SymKey *wrappingKey, PK11SymKey *symKey, SECItem *wrappedKey);
Packit 40b132
/* move a key to 'slot' optionally set the key attributes according to either
Packit 40b132
 * operation or the  flags and making the key permanent at the same time.
Packit 40b132
 * If the key is moved to the same slot, operation and flags values are 
Packit 40b132
 * currently ignored */
Packit 40b132
PK11SymKey *PK11_MoveSymKey(PK11SlotInfo *slot, CK_ATTRIBUTE_TYPE operation, 
Packit 40b132
			CK_FLAGS flags, PRBool  perm, PK11SymKey *symKey);
Packit 40b132
/*
Packit 40b132
 * derive a new key from the base key.
Packit 40b132
 *  PK11_Derive returns a key which can do exactly one operation, and is
Packit 40b132
 * ephemeral (session key).
Packit 40b132
 *  PK11_DeriveWithFlags is the same as PK11_Derive, except you can use
Packit 40b132
 * CKF_ flags to enable more than one operation.
Packit 40b132
 *  PK11_DeriveWithFlagsPerm is the same as PK11_DeriveWithFlags except you can
Packit 40b132
 *  (optionally) make the key permanent (token key).
Packit 40b132
 */
Packit 40b132
PK11SymKey *PK11_Derive(PK11SymKey *baseKey, CK_MECHANISM_TYPE mechanism,
Packit 40b132
   			SECItem *param, CK_MECHANISM_TYPE target, 
Packit 40b132
		        CK_ATTRIBUTE_TYPE operation, int keySize);
Packit 40b132
PK11SymKey *PK11_DeriveWithFlags( PK11SymKey *baseKey, 
Packit 40b132
	CK_MECHANISM_TYPE derive, SECItem *param, CK_MECHANISM_TYPE target, 
Packit 40b132
	CK_ATTRIBUTE_TYPE operation, int keySize, CK_FLAGS flags);
Packit 40b132
PK11SymKey * PK11_DeriveWithFlagsPerm( PK11SymKey *baseKey, 
Packit 40b132
	CK_MECHANISM_TYPE derive, 
Packit 40b132
	SECItem *param, CK_MECHANISM_TYPE target, CK_ATTRIBUTE_TYPE operation, 
Packit 40b132
	int keySize, CK_FLAGS flags, PRBool isPerm);
Packit 40b132
PK11SymKey *
Packit 40b132
PK11_DeriveWithTemplate( PK11SymKey *baseKey, CK_MECHANISM_TYPE derive, 
Packit 40b132
	SECItem *param, CK_MECHANISM_TYPE target, CK_ATTRIBUTE_TYPE operation, 
Packit 40b132
	int keySize, CK_ATTRIBUTE *userAttr, unsigned int numAttrs,
Packit 40b132
							 PRBool isPerm);
Packit 40b132
Packit 40b132
Packit 40b132
PK11SymKey *PK11_PubDerive( SECKEYPrivateKey *privKey, 
Packit 40b132
 SECKEYPublicKey *pubKey, PRBool isSender, SECItem *randomA, SECItem *randomB,
Packit 40b132
 CK_MECHANISM_TYPE derive, CK_MECHANISM_TYPE target,
Packit 40b132
		 CK_ATTRIBUTE_TYPE operation, int keySize,void *wincx) ;
Packit 40b132
PK11SymKey *PK11_PubDeriveWithKDF( SECKEYPrivateKey *privKey, 
Packit 40b132
 SECKEYPublicKey *pubKey, PRBool isSender, SECItem *randomA, SECItem *randomB,
Packit 40b132
 CK_MECHANISM_TYPE derive, CK_MECHANISM_TYPE target,
Packit 40b132
		 CK_ATTRIBUTE_TYPE operation, int keySize,
Packit 40b132
		 CK_ULONG kdf, SECItem *sharedData, void *wincx);
Packit 40b132
Packit 40b132
/*
Packit 40b132
 * unwrap a new key with a symetric key.
Packit 40b132
 *  PK11_Unwrap returns a key which can do exactly one operation, and is
Packit 40b132
 * ephemeral (session key).
Packit 40b132
 *  PK11_UnwrapWithFlags is the same as PK11_Unwrap, except you can use
Packit 40b132
 * CKF_ flags to enable more than one operation.
Packit 40b132
 *  PK11_UnwrapWithFlagsPerm is the same as PK11_UnwrapWithFlags except you can
Packit 40b132
 *  (optionally) make the key permanent (token key).
Packit 40b132
 */
Packit 40b132
PK11SymKey *PK11_UnwrapSymKey(PK11SymKey *key, 
Packit 40b132
	CK_MECHANISM_TYPE wraptype, SECItem *param, SECItem *wrapppedKey,  
Packit 40b132
	CK_MECHANISM_TYPE target, CK_ATTRIBUTE_TYPE operation, int keySize);
Packit 40b132
PK11SymKey *PK11_UnwrapSymKeyWithFlags(PK11SymKey *wrappingKey, 
Packit 40b132
	CK_MECHANISM_TYPE wrapType, SECItem *param, SECItem *wrappedKey, 
Packit 40b132
	CK_MECHANISM_TYPE target, CK_ATTRIBUTE_TYPE operation, int keySize, 
Packit 40b132
	CK_FLAGS flags);
Packit 40b132
PK11SymKey * PK11_UnwrapSymKeyWithFlagsPerm(PK11SymKey *wrappingKey, 
Packit 40b132
	CK_MECHANISM_TYPE wrapType,
Packit 40b132
        SECItem *param, SECItem *wrappedKey, 
Packit 40b132
	CK_MECHANISM_TYPE target, CK_ATTRIBUTE_TYPE operation, 
Packit 40b132
	 int keySize, CK_FLAGS flags, PRBool isPerm);
Packit 40b132
Packit 40b132
/*
Packit 40b132
 * unwrap a new key with a private key.
Packit 40b132
 *  PK11_PubUnwrap returns a key which can do exactly one operation, and is
Packit 40b132
 * ephemeral (session key).
Packit 40b132
 *  PK11_PubUnwrapWithFlagsPerm is the same as PK11_PubUnwrap except you can 
Packit 40b132
 * use * CKF_ flags to enable more than one operation, and optionally make 
Packit 40b132
 * the key permanent (token key).
Packit 40b132
 */
Packit 40b132
PK11SymKey *PK11_PubUnwrapSymKey(SECKEYPrivateKey *key, SECItem *wrapppedKey,
Packit 40b132
	 CK_MECHANISM_TYPE target, CK_ATTRIBUTE_TYPE operation, int keySize);
Packit 40b132
PK11SymKey * PK11_PubUnwrapSymKeyWithFlagsPerm(SECKEYPrivateKey *wrappingKey, 
Packit 40b132
	  SECItem *wrappedKey, CK_MECHANISM_TYPE target, 
Packit 40b132
	  CK_ATTRIBUTE_TYPE operation, int keySize,
Packit 40b132
	  CK_FLAGS flags, PRBool isPerm);
Packit 40b132
PK11SymKey *PK11_FindFixedKey(PK11SlotInfo *slot, CK_MECHANISM_TYPE type, 
Packit 40b132
						SECItem *keyID, void *wincx);
Packit 40b132
SECStatus PK11_DeleteTokenPrivateKey(SECKEYPrivateKey *privKey,PRBool force);
Packit 40b132
SECStatus PK11_DeleteTokenPublicKey(SECKEYPublicKey *pubKey);
Packit 40b132
SECStatus PK11_DeleteTokenSymKey(PK11SymKey *symKey);
Packit 40b132
SECStatus PK11_DeleteTokenCertAndKey(CERTCertificate *cert,void *wincx);
Packit 40b132
SECKEYPrivateKey * PK11_LoadPrivKey(PK11SlotInfo *slot,
Packit 40b132
		SECKEYPrivateKey *privKey, SECKEYPublicKey *pubKey, 
Packit 40b132
					PRBool token, PRBool sensitive);
Packit 40b132
char * PK11_GetSymKeyNickname(PK11SymKey *symKey);
Packit 40b132
char * PK11_GetPrivateKeyNickname(SECKEYPrivateKey *privKey);
Packit 40b132
char * PK11_GetPublicKeyNickname(SECKEYPublicKey *pubKey);
Packit 40b132
SECStatus PK11_SetSymKeyNickname(PK11SymKey *symKey, const char *nickname);
Packit 40b132
SECStatus PK11_SetPrivateKeyNickname(SECKEYPrivateKey *privKey, 
Packit 40b132
							const char *nickname);
Packit 40b132
SECStatus PK11_SetPublicKeyNickname(SECKEYPublicKey *pubKey, 
Packit 40b132
							const char *nickname);
Packit 40b132
Packit 40b132
/*
Packit 40b132
 * Using __PK11_SetCertificateNickname is *DANGEROUS*.
Packit 40b132
 *
Packit 40b132
 * The API will update the NSS database, but it *will NOT* update the in-memory data.
Packit 40b132
 * As a result, after calling this API, there will be INCONSISTENCY between
Packit 40b132
 * in-memory data and the database.
Packit 40b132
 *
Packit 40b132
 * Use of the API should be limited to short-lived tools, which will exit immediately
Packit 40b132
 * after using this API.
Packit 40b132
 *
Packit 40b132
 * If you ignore this warning, your process is TAINTED and will most likely misbehave.
Packit 40b132
 */
Packit 40b132
SECStatus __PK11_SetCertificateNickname(CERTCertificate *cert,
Packit 40b132
                                      const char *nickname);
Packit 40b132
Packit 40b132
/* size to hold key in bytes */
Packit 40b132
unsigned int PK11_GetKeyLength(PK11SymKey *key);
Packit 40b132
/* size of actual secret parts of key in bits */
Packit 40b132
/* algid is because RC4 strength is determined by the effective bits as well
Packit 40b132
 * as the key bits */
Packit 40b132
unsigned int PK11_GetKeyStrength(PK11SymKey *key,SECAlgorithmID *algid);
Packit 40b132
SECStatus PK11_ExtractKeyValue(PK11SymKey *symKey);
Packit 40b132
SECItem * PK11_GetKeyData(PK11SymKey *symKey);
Packit 40b132
PK11SlotInfo * PK11_GetSlotFromKey(PK11SymKey *symKey);
Packit 40b132
void *PK11_GetWindow(PK11SymKey *symKey);
Packit 40b132
Packit 40b132
/*
Packit 40b132
 * Explicitly set the key usage for the generated private key.
Packit 40b132
 *
Packit 40b132
 * This allows us to specify single use EC and RSA keys whose usage
Packit 40b132
 * can be regulated by the underlying token.
Packit 40b132
 *
Packit 40b132
 * The underlying key usage is set using opFlags. opFlagsMask specifies
Packit 40b132
 * which operations are specified by opFlags. For instance to turn encrypt
Packit 40b132
 * on and signing off, opFlags would be CKF_ENCRYPT|CKF_DECRYPT and 
Packit 40b132
 * opFlagsMask would be CKF_ENCRYPT|CKF_DECRYPT|CKF_SIGN|CKF_VERIFY. You
Packit 40b132
 * need to specify both the public and private key flags, 
Packit 40b132
 * PK11_GenerateKeyPairWithOpFlags will sort out the correct flag to the 
Packit 40b132
 * correct key type. Flags not specified in opFlagMask will be defaulted 
Packit 40b132
 * according to mechanism type and token capabilities.
Packit 40b132
 */
Packit 40b132
SECKEYPrivateKey *PK11_GenerateKeyPairWithOpFlags(PK11SlotInfo *slot,
Packit 40b132
   CK_MECHANISM_TYPE type, void *param, SECKEYPublicKey **pubk,
Packit 40b132
   PK11AttrFlags attrFlags, CK_FLAGS opFlags, CK_FLAGS opFlagsMask,
Packit 40b132
    void *wincx);
Packit 40b132
/*
Packit 40b132
 * The attrFlags is the logical OR of the PK11_ATTR_XXX bitflags.
Packit 40b132
 * These flags apply to the private key.  The PK11_ATTR_TOKEN,
Packit 40b132
 * PK11_ATTR_SESSION, PK11_ATTR_MODIFIABLE, and PK11_ATTR_UNMODIFIABLE
Packit 40b132
 * flags also apply to the public key.
Packit 40b132
 */
Packit 40b132
SECKEYPrivateKey *PK11_GenerateKeyPairWithFlags(PK11SlotInfo *slot,
Packit 40b132
   CK_MECHANISM_TYPE type, void *param, SECKEYPublicKey **pubk,
Packit 40b132
		 	    PK11AttrFlags attrFlags, void *wincx);
Packit 40b132
SECKEYPrivateKey *PK11_GenerateKeyPair(PK11SlotInfo *slot,
Packit 40b132
   CK_MECHANISM_TYPE type, void *param, SECKEYPublicKey **pubk,
Packit 40b132
		 	    PRBool isPerm, PRBool isSensitive, void *wincx);
Packit 40b132
SECKEYPrivateKey * PK11_FindPrivateKeyFromCert(PK11SlotInfo *slot,
Packit 40b132
				 	CERTCertificate *cert, void *wincx);
Packit 40b132
SECKEYPrivateKey * PK11_FindKeyByAnyCert(CERTCertificate *cert, void *wincx);
Packit 40b132
SECKEYPrivateKey * PK11_FindKeyByKeyID(PK11SlotInfo *slot, SECItem *keyID,
Packit 40b132
				       void *wincx);
Packit 40b132
int PK11_GetPrivateModulusLen(SECKEYPrivateKey *key); 
Packit 40b132
Packit 40b132
SECStatus PK11_Decrypt(PK11SymKey *symkey,
Packit 40b132
		       CK_MECHANISM_TYPE mechanism, SECItem *param,
Packit 40b132
		       unsigned char *out, unsigned int *outLen,
Packit 40b132
		       unsigned int maxLen,
Packit 40b132
		       const unsigned char *enc, unsigned int encLen);
Packit 40b132
SECStatus PK11_Encrypt(PK11SymKey *symKey,
Packit 40b132
		       CK_MECHANISM_TYPE mechanism, SECItem *param,
Packit 40b132
		       unsigned char *out, unsigned int *outLen,
Packit 40b132
		       unsigned int maxLen,
Packit 40b132
		       const unsigned char *data, unsigned int dataLen);
Packit 40b132
Packit 40b132
/* note: despite the name, this function takes a private key. */
Packit 40b132
SECStatus PK11_PubDecryptRaw(SECKEYPrivateKey *key,
Packit 40b132
                             unsigned char *data, unsigned *outLen,
Packit 40b132
                             unsigned int maxLen,
Packit 40b132
                             const unsigned char *enc, unsigned encLen);
Packit 40b132
#define PK11_PrivDecryptRaw PK11_PubDecryptRaw
Packit 40b132
/* The encrypt function that complements the above decrypt function. */
Packit 40b132
SECStatus PK11_PubEncryptRaw(SECKEYPublicKey *key,
Packit 40b132
                             unsigned char *enc,
Packit 40b132
                             const unsigned char *data, unsigned dataLen,
Packit 40b132
                             void *wincx);
Packit 40b132
Packit 40b132
SECStatus PK11_PrivDecryptPKCS1(SECKEYPrivateKey *key,
Packit 40b132
                                unsigned char *data, unsigned *outLen,
Packit 40b132
                                unsigned int maxLen,
Packit 40b132
                                const unsigned char *enc, unsigned encLen);
Packit 40b132
/* The encrypt function that complements the above decrypt function. */
Packit 40b132
SECStatus PK11_PubEncryptPKCS1(SECKEYPublicKey *key,
Packit 40b132
                               unsigned char *enc,
Packit 40b132
                               const unsigned char *data, unsigned dataLen,
Packit 40b132
                               void *wincx);
Packit 40b132
Packit 40b132
SECStatus PK11_PrivDecrypt(SECKEYPrivateKey *key,
Packit 40b132
                           CK_MECHANISM_TYPE mechanism, SECItem *param,
Packit 40b132
                           unsigned char *out, unsigned int *outLen,
Packit 40b132
                           unsigned int maxLen,
Packit 40b132
                           const unsigned char *enc, unsigned int encLen);
Packit 40b132
SECStatus PK11_PubEncrypt(SECKEYPublicKey *key,
Packit 40b132
                          CK_MECHANISM_TYPE mechanism, SECItem *param,
Packit 40b132
                          unsigned char *out, unsigned int *outLen,
Packit 40b132
                          unsigned int maxLen,
Packit 40b132
                          const unsigned char *data, unsigned int dataLen,
Packit 40b132
                          void *wincx);
Packit 40b132
Packit 40b132
SECStatus PK11_ImportPrivateKeyInfo(PK11SlotInfo *slot, 
Packit 40b132
		SECKEYPrivateKeyInfo *pki, SECItem *nickname,
Packit 40b132
		SECItem *publicValue, PRBool isPerm, PRBool isPrivate,
Packit 40b132
		unsigned int usage, void *wincx);
Packit 40b132
SECStatus PK11_ImportPrivateKeyInfoAndReturnKey(PK11SlotInfo *slot, 
Packit 40b132
		SECKEYPrivateKeyInfo *pki, SECItem *nickname,
Packit 40b132
		SECItem *publicValue, PRBool isPerm, PRBool isPrivate,
Packit 40b132
		unsigned int usage, SECKEYPrivateKey** privk, void *wincx);
Packit 40b132
SECStatus PK11_ImportDERPrivateKeyInfo(PK11SlotInfo *slot, 
Packit 40b132
		SECItem *derPKI, SECItem *nickname,
Packit 40b132
		SECItem *publicValue, PRBool isPerm, PRBool isPrivate,
Packit 40b132
		unsigned int usage, void *wincx);
Packit 40b132
SECStatus PK11_ImportDERPrivateKeyInfoAndReturnKey(PK11SlotInfo *slot, 
Packit 40b132
		SECItem *derPKI, SECItem *nickname,
Packit 40b132
		SECItem *publicValue, PRBool isPerm, PRBool isPrivate,
Packit 40b132
		unsigned int usage, SECKEYPrivateKey** privk, void *wincx);
Packit 40b132
SECStatus PK11_ImportEncryptedPrivateKeyInfo(PK11SlotInfo *slot, 
Packit 40b132
		SECKEYEncryptedPrivateKeyInfo *epki, SECItem *pwitem, 
Packit 40b132
		SECItem *nickname, SECItem *publicValue, PRBool isPerm,
Packit 40b132
		PRBool isPrivate, KeyType type, 
Packit 40b132
		unsigned int usage, void *wincx);
Packit 40b132
SECStatus PK11_ImportEncryptedPrivateKeyInfoAndReturnKey(PK11SlotInfo *slot, 
Packit 40b132
		SECKEYEncryptedPrivateKeyInfo *epki, SECItem *pwitem, 
Packit 40b132
		SECItem *nickname, SECItem *publicValue, PRBool isPerm,
Packit 40b132
		PRBool isPrivate, KeyType type, 
Packit 40b132
		unsigned int usage, SECKEYPrivateKey** privk, void *wincx);
Packit 40b132
SECItem *PK11_ExportDERPrivateKeyInfo(SECKEYPrivateKey *pk, void *wincx);
Packit 40b132
SECKEYPrivateKeyInfo *PK11_ExportPrivKeyInfo(
Packit 40b132
		SECKEYPrivateKey *pk, void *wincx);
Packit 40b132
SECKEYPrivateKeyInfo *PK11_ExportPrivateKeyInfo(
Packit 40b132
		CERTCertificate *cert, void *wincx);
Packit 40b132
SECKEYEncryptedPrivateKeyInfo *PK11_ExportEncryptedPrivKeyInfo(
Packit 40b132
		PK11SlotInfo *slot, SECOidTag algTag, SECItem *pwitem,
Packit 40b132
		SECKEYPrivateKey *pk, int iteration, void *wincx);
Packit 40b132
SECKEYEncryptedPrivateKeyInfo *PK11_ExportEncryptedPrivateKeyInfo(
Packit 40b132
		PK11SlotInfo *slot, SECOidTag algTag, SECItem *pwitem,
Packit 40b132
		CERTCertificate *cert, int iteration, void *wincx);
Packit 40b132
SECKEYPrivateKey *PK11_FindKeyByDERCert(PK11SlotInfo *slot, 
Packit 40b132
					CERTCertificate *cert, void *wincx);
Packit 40b132
SECKEYPublicKey *PK11_MakeKEAPubKey(unsigned char *data, int length);
Packit 40b132
SECStatus PK11_DigestKey(PK11Context *context, PK11SymKey *key);
Packit 40b132
PRBool PK11_VerifyKeyOK(PK11SymKey *key);
Packit 40b132
SECKEYPrivateKey *PK11_UnwrapPrivKey(PK11SlotInfo *slot, 
Packit 40b132
		PK11SymKey *wrappingKey, CK_MECHANISM_TYPE wrapType,
Packit 40b132
		SECItem *param, SECItem *wrappedKey, SECItem *label, 
Packit 40b132
		SECItem *publicValue, PRBool token, PRBool sensitive,
Packit 40b132
		CK_KEY_TYPE keyType, CK_ATTRIBUTE_TYPE *usage, int usageCount,
Packit 40b132
		void *wincx);
Packit 40b132
SECStatus PK11_WrapPrivKey(PK11SlotInfo *slot, PK11SymKey *wrappingKey,
Packit 40b132
			   SECKEYPrivateKey *privKey, CK_MECHANISM_TYPE wrapType,
Packit 40b132
			   SECItem *param, SECItem *wrappedKey, void *wincx);
Packit 40b132
/*
Packit 40b132
 * The caller of PK11_DEREncodePublicKey should free the returned SECItem with
Packit 40b132
 * a SECITEM_FreeItem(..., PR_TRUE) call.
Packit 40b132
 */
Packit 40b132
SECItem* PK11_DEREncodePublicKey(const SECKEYPublicKey *pubk);
Packit 40b132
PK11SymKey* PK11_CopySymKeyForSigning(PK11SymKey *originalKey,
Packit 40b132
	CK_MECHANISM_TYPE mech);
Packit 40b132
SECKEYPrivateKeyList* PK11_ListPrivKeysInSlot(PK11SlotInfo *slot,
Packit 40b132
						 char *nickname, void *wincx);
Packit 40b132
SECKEYPublicKeyList* PK11_ListPublicKeysInSlot(PK11SlotInfo *slot,
Packit 40b132
							char *nickname);
Packit 40b132
SECKEYPQGParams *PK11_GetPQGParamsFromPrivateKey(SECKEYPrivateKey *privKey);
Packit 40b132
/* deprecated */
Packit 40b132
SECKEYPrivateKeyList* PK11_ListPrivateKeysInSlot(PK11SlotInfo *slot);
Packit 40b132
Packit 40b132
PK11SymKey *PK11_ConvertSessionSymKeyToTokenSymKey(PK11SymKey *symk,
Packit 40b132
	void *wincx);
Packit 40b132
SECKEYPrivateKey *PK11_ConvertSessionPrivKeyToTokenPrivKey(
Packit 40b132
	SECKEYPrivateKey *privk, void* wincx);
Packit 40b132
SECKEYPrivateKey * PK11_CopyTokenPrivKeyToSessionPrivKey(PK11SlotInfo *destSlot,
Packit 40b132
				      SECKEYPrivateKey *privKey);
Packit 40b132
Packit 40b132
/**********************************************************************
Packit 40b132
 *                   Certs
Packit 40b132
 **********************************************************************/
Packit 40b132
SECItem *PK11_MakeIDFromPubKey(SECItem *pubKeyData);
Packit 40b132
SECStatus PK11_TraverseSlotCerts(
Packit 40b132
     SECStatus(* callback)(CERTCertificate*,SECItem *,void *),
Packit 40b132
                                                void *arg, void *wincx);
Packit 40b132
CERTCertificate * PK11_FindCertFromNickname(const char *nickname, void *wincx);
Packit 40b132
CERTCertList * PK11_FindCertsFromEmailAddress(const char *email, void *wincx);
Packit 40b132
CERTCertList * PK11_FindCertsFromNickname(const char *nickname, void *wincx);
Packit 40b132
CERTCertificate *PK11_GetCertFromPrivateKey(SECKEYPrivateKey *privKey);
Packit 40b132
SECStatus PK11_ImportCert(PK11SlotInfo *slot, CERTCertificate *cert,
Packit 40b132
                CK_OBJECT_HANDLE key, const char *nickname, 
Packit 40b132
                PRBool includeTrust);
Packit 40b132
SECStatus PK11_ImportDERCert(PK11SlotInfo *slot, SECItem *derCert,
Packit 40b132
                CK_OBJECT_HANDLE key, char *nickname, PRBool includeTrust);
Packit 40b132
PK11SlotInfo *PK11_ImportCertForKey(CERTCertificate *cert, 
Packit 40b132
                                    const char *nickname, void *wincx);
Packit 40b132
PK11SlotInfo *PK11_ImportDERCertForKey(SECItem *derCert, char *nickname,
Packit 40b132
								void *wincx);
Packit 40b132
PK11SlotInfo *PK11_KeyForCertExists(CERTCertificate *cert,
Packit 40b132
					CK_OBJECT_HANDLE *keyPtr, void *wincx);
Packit 40b132
PK11SlotInfo *PK11_KeyForDERCertExists(SECItem *derCert,
Packit 40b132
					CK_OBJECT_HANDLE *keyPtr, void *wincx);
Packit 40b132
CERTCertificate * PK11_FindCertByIssuerAndSN(PK11SlotInfo **slot,
Packit 40b132
					CERTIssuerAndSN *sn, void *wincx);
Packit 40b132
CERTCertificate * PK11_FindCertAndKeyByRecipientList(PK11SlotInfo **slot,
Packit 40b132
	SEC_PKCS7RecipientInfo **array, SEC_PKCS7RecipientInfo **rip,
Packit 40b132
				SECKEYPrivateKey**privKey, void *wincx);
Packit 40b132
int PK11_FindCertAndKeyByRecipientListNew(NSSCMSRecipient **recipientlist,
Packit 40b132
				void *wincx);
Packit 40b132
SECStatus PK11_TraverseCertsForSubjectInSlot(CERTCertificate *cert,
Packit 40b132
	PK11SlotInfo *slot, SECStatus(*callback)(CERTCertificate *, void *),
Packit 40b132
	void *arg);
Packit 40b132
CERTCertificate *PK11_FindCertFromDERCert(PK11SlotInfo *slot, 
Packit 40b132
					  CERTCertificate *cert, void *wincx);
Packit 40b132
CERTCertificate *PK11_FindCertFromDERCertItem(PK11SlotInfo *slot,
Packit 40b132
                                          const SECItem *derCert, void *wincx);
Packit 40b132
SECStatus PK11_ImportCertForKeyToSlot(PK11SlotInfo *slot, CERTCertificate *cert,
Packit 40b132
					char *nickname, PRBool addUsage,
Packit 40b132
					void *wincx);
Packit 40b132
CERTCertificate *PK11_FindBestKEAMatch(CERTCertificate *serverCert,void *wincx);
Packit 40b132
PRBool PK11_FortezzaHasKEA(CERTCertificate *cert);
Packit 40b132
CK_OBJECT_HANDLE PK11_FindCertInSlot(PK11SlotInfo *slot, CERTCertificate *cert,
Packit 40b132
				     void *wincx);
Packit 40b132
SECStatus PK11_TraverseCertsForNicknameInSlot(SECItem *nickname,
Packit 40b132
	PK11SlotInfo *slot, SECStatus(*callback)(CERTCertificate *, void *),
Packit 40b132
	void *arg);
Packit 40b132
CERTCertList * PK11_ListCerts(PK11CertListType type, void *pwarg);
Packit 40b132
CERTCertList * PK11_ListCertsInSlot(PK11SlotInfo *slot);
Packit 40b132
CERTSignedCrl* PK11_ImportCRL(PK11SlotInfo * slot, SECItem *derCRL, char *url,
Packit 40b132
    int type, void *wincx, PRInt32 importOptions, PLArenaPool* arena, PRInt32 decodeOptions);
Packit 40b132
Packit 40b132
/**********************************************************************
Packit 40b132
 *                   Sign/Verify 
Packit 40b132
 **********************************************************************/
Packit 40b132
Packit 40b132
/*
Packit 40b132
 * Return the length in bytes of a signature generated with the
Packit 40b132
 * private key.
Packit 40b132
 *
Packit 40b132
 * Return 0 or -1 on failure.  (XXX Should we fix it to always return
Packit 40b132
 * -1 on failure?)
Packit 40b132
 */
Packit 40b132
int PK11_SignatureLen(SECKEYPrivateKey *key);
Packit 40b132
PK11SlotInfo * PK11_GetSlotFromPrivateKey(SECKEYPrivateKey *key);
Packit 40b132
SECStatus PK11_Sign(SECKEYPrivateKey *key, SECItem *sig,
Packit 40b132
		    const SECItem *hash);
Packit 40b132
SECStatus PK11_SignWithSymKey(PK11SymKey *symKey, CK_MECHANISM_TYPE mechanism,
Packit 40b132
		    SECItem *param, SECItem *sig, const SECItem *data);
Packit 40b132
SECStatus PK11_VerifyRecover(SECKEYPublicKey *key, const SECItem *sig,
Packit 40b132
			     SECItem *dsig, void * wincx);
Packit 40b132
SECStatus PK11_Verify(SECKEYPublicKey *key, const SECItem *sig,
Packit 40b132
		      const SECItem *hash, void *wincx);
Packit 40b132
Packit 40b132
Packit 40b132
Packit 40b132
/**********************************************************************
Packit 40b132
 *                   Crypto Contexts
Packit 40b132
 **********************************************************************/
Packit 40b132
void PK11_DestroyContext(PK11Context *context, PRBool freeit);
Packit 40b132
PK11Context *PK11_CreateContextBySymKey(CK_MECHANISM_TYPE type,
Packit 40b132
	CK_ATTRIBUTE_TYPE operation, PK11SymKey *symKey, SECItem *param);
Packit 40b132
PK11Context *PK11_CreateDigestContext(SECOidTag hashAlg);
Packit 40b132
PK11Context *PK11_CloneContext(PK11Context *old);
Packit 40b132
SECStatus PK11_DigestBegin(PK11Context *cx);
Packit 40b132
/*
Packit 40b132
 * The output buffer 'out' must be big enough to hold the output of
Packit 40b132
 * the hash algorithm 'hashAlg'.
Packit 40b132
 */
Packit 40b132
SECStatus PK11_HashBuf(SECOidTag hashAlg, unsigned char *out,
Packit 40b132
		       const unsigned char *in, PRInt32 len);
Packit 40b132
SECStatus PK11_DigestOp(PK11Context *context, const unsigned char *in, 
Packit 40b132
                        unsigned len);
Packit 40b132
SECStatus PK11_CipherOp(PK11Context *context, unsigned char * out, int *outlen, 
Packit 40b132
			int maxout, const unsigned char *in, int inlen);
Packit 40b132
SECStatus PK11_Finalize(PK11Context *context);
Packit 40b132
SECStatus PK11_DigestFinal(PK11Context *context, unsigned char *data, 
Packit 40b132
				unsigned int *outLen, unsigned int length);
Packit 40b132
#define PK11_CipherFinal PK11_DigestFinal
Packit 40b132
SECStatus PK11_SaveContext(PK11Context *cx,unsigned char *save,
Packit 40b132
						int *len, int saveLength);
Packit 40b132
Packit 40b132
/* Save the context's state, with possible allocation.
Packit 40b132
 * The caller may supply an already allocated buffer in preAllocBuf,
Packit 40b132
 * with length pabLen.  If the buffer is large enough for the context's
Packit 40b132
 * state, it will receive the state.
Packit 40b132
 * If the buffer is not large enough (or NULL), then a new buffer will
Packit 40b132
 * be allocated with PORT_Alloc.
Packit 40b132
 * In either case, the state will be returned as a buffer, and the length
Packit 40b132
 * of the state will be given in *stateLen.
Packit 40b132
 */
Packit 40b132
unsigned char *
Packit 40b132
PK11_SaveContextAlloc(PK11Context *cx,
Packit 40b132
                      unsigned char *preAllocBuf, unsigned int pabLen,
Packit 40b132
                      unsigned int *stateLen);
Packit 40b132
Packit 40b132
SECStatus PK11_RestoreContext(PK11Context *cx,unsigned char *save,int len);
Packit 40b132
SECStatus PK11_GenerateFortezzaIV(PK11SymKey *symKey,unsigned char *iv,int len);
Packit 40b132
void PK11_SetFortezzaHack(PK11SymKey *symKey) ;
Packit 40b132
Packit 40b132
Packit 40b132
/**********************************************************************
Packit 40b132
 *                   PBE functions 
Packit 40b132
 **********************************************************************/
Packit 40b132
Packit 40b132
/* This function creates PBE parameters from the given inputs.  The result
Packit 40b132
 * can be used to create a password integrity key for PKCS#12, by sending
Packit 40b132
 * the return value to PK11_KeyGen along with the appropriate mechanism.
Packit 40b132
 */
Packit 40b132
SECItem * 
Packit 40b132
PK11_CreatePBEParams(SECItem *salt, SECItem *pwd, unsigned int iterations);
Packit 40b132
Packit 40b132
/* free params created above (can be called after keygen is done */
Packit 40b132
void PK11_DestroyPBEParams(SECItem *params);
Packit 40b132
Packit 40b132
SECAlgorithmID *
Packit 40b132
PK11_CreatePBEAlgorithmID(SECOidTag algorithm, int iteration, SECItem *salt);
Packit 40b132
Packit 40b132
/* use to create PKCS5 V2 algorithms with finder control than that provided
Packit 40b132
 * by PK11_CreatePBEAlgorithmID. */
Packit 40b132
SECAlgorithmID *
Packit 40b132
PK11_CreatePBEV2AlgorithmID(SECOidTag pbeAlgTag, SECOidTag cipherAlgTag,
Packit 40b132
                            SECOidTag prfAlgTag, int keyLength, int iteration,
Packit 40b132
                            SECItem *salt);
Packit 40b132
PK11SymKey *
Packit 40b132
PK11_PBEKeyGen(PK11SlotInfo *slot, SECAlgorithmID *algid,  SECItem *pwitem,
Packit 40b132
	       PRBool faulty3DES, void *wincx);
Packit 40b132
Packit 40b132
/* warning: cannot work with PKCS 5 v2 use PK11_PBEKeyGen instead */
Packit 40b132
PK11SymKey *
Packit 40b132
PK11_RawPBEKeyGen(PK11SlotInfo *slot, CK_MECHANISM_TYPE type, SECItem *params,
Packit 40b132
		SECItem *pwitem, PRBool faulty3DES, void *wincx);
Packit 40b132
SECItem *
Packit 40b132
PK11_GetPBEIV(SECAlgorithmID *algid, SECItem *pwitem);
Packit 40b132
/*
Packit 40b132
 * Get the Mechanism and parameter of the base encryption or mac scheme from
Packit 40b132
 * a PBE algorithm ID.
Packit 40b132
 *  Caller is responsible for freeing the return parameter (param).
Packit 40b132
 */
Packit 40b132
CK_MECHANISM_TYPE
Packit 40b132
PK11_GetPBECryptoMechanism(SECAlgorithmID *algid, 
Packit 40b132
			   SECItem **param, SECItem *pwd);
Packit 40b132
Packit 40b132
/**********************************************************************
Packit 40b132
 * Functions to manage secmod flags
Packit 40b132
 **********************************************************************/
Packit 40b132
const PK11DefaultArrayEntry *PK11_GetDefaultArray(int *size);
Packit 40b132
SECStatus PK11_UpdateSlotAttribute(PK11SlotInfo *slot,
Packit 40b132
				   const PK11DefaultArrayEntry *entry,
Packit 40b132
				   PRBool add);
Packit 40b132
Packit 40b132
/**********************************************************************
Packit 40b132
 * Functions to look at PKCS #11 dependent data
Packit 40b132
 **********************************************************************/
Packit 40b132
PK11GenericObject *PK11_FindGenericObjects(PK11SlotInfo *slot, 
Packit 40b132
						CK_OBJECT_CLASS objClass);
Packit 40b132
PK11GenericObject *PK11_GetNextGenericObject(PK11GenericObject *object);
Packit 40b132
PK11GenericObject *PK11_GetPrevGenericObject(PK11GenericObject *object);
Packit 40b132
SECStatus PK11_UnlinkGenericObject(PK11GenericObject *object);
Packit 40b132
SECStatus PK11_LinkGenericObject(PK11GenericObject *list,
Packit 40b132
				 PK11GenericObject *object);
Packit 40b132
SECStatus PK11_DestroyGenericObjects(PK11GenericObject *object);
Packit 40b132
SECStatus PK11_DestroyGenericObject(PK11GenericObject *object);
Packit 40b132
PK11GenericObject *PK11_CreateGenericObject(PK11SlotInfo *slot, 
Packit 40b132
				   const CK_ATTRIBUTE *pTemplate, 
Packit 40b132
				   int count, PRBool token);
Packit 40b132
Packit 40b132
/*
Packit 40b132
 * PK11_ReadRawAttribute and PK11_WriteRawAttribute are generic
Packit 40b132
 * functions to read and modify the actual PKCS #11 attributes of
Packit 40b132
 * the underlying pkcs #11 object.
Packit 40b132
 * 
Packit 40b132
 * object is a pointer to an NSS object that represents the underlying
Packit 40b132
 *  PKCS #11 object. It's type must match the type of PK11ObjectType
Packit 40b132
 *  as follows:
Packit 40b132
 *
Packit 40b132
 *     type                           object
Packit 40b132
 *   PK11_TypeGeneric            PK11GenericObject *
Packit 40b132
 *   PK11_TypePrivKey            SECKEYPrivateKey *
Packit 40b132
 *   PK11_TypePubKey             SECKEYPublicKey *
Packit 40b132
 *   PK11_TypeSymKey             PK11SymKey *
Packit 40b132
 *
Packit 40b132
 *  All other types are considered invalid. If type does not match the object
Packit 40b132
 *  passed, unpredictable results will occur.
Packit 40b132
 *
Packit 40b132
 * PK11_ReadRawAttribute allocates the buffer for returning the attribute
Packit 40b132
 * value.  The caller of PK11_ReadRawAttribute should free the data buffer
Packit 40b132
 * pointed to by item using a SECITEM_FreeItem(item, PR_FALSE) or
Packit 40b132
 * PORT_Free(item->data) call.
Packit 40b132
 */
Packit 40b132
SECStatus PK11_ReadRawAttribute(PK11ObjectType type, void *object, 
Packit 40b132
				CK_ATTRIBUTE_TYPE attr, SECItem *item);
Packit 40b132
SECStatus PK11_WriteRawAttribute(PK11ObjectType type, void *object, 
Packit 40b132
				CK_ATTRIBUTE_TYPE attr, SECItem *item);
Packit 40b132
Packit 40b132
/*
Packit 40b132
 * PK11_GetAllSlotsForCert returns all the slots that a given certificate
Packit 40b132
 * exists on, since it's possible for a cert to exist on more than one
Packit 40b132
 * PKCS#11 token.
Packit 40b132
 */
Packit 40b132
PK11SlotList *
Packit 40b132
PK11_GetAllSlotsForCert(CERTCertificate *cert, void *arg);
Packit 40b132
Packit 40b132
/**********************************************************************
Packit 40b132
 * New functions which are already deprecated....
Packit 40b132
 **********************************************************************/
Packit 40b132
SECItem *
Packit 40b132
PK11_GetLowLevelKeyIDForCert(PK11SlotInfo *slot,
Packit 40b132
					CERTCertificate *cert, void *pwarg);
Packit 40b132
SECItem *
Packit 40b132
PK11_GetLowLevelKeyIDForPrivateKey(SECKEYPrivateKey *key);
Packit 40b132
Packit 40b132
PRBool SECMOD_HasRootCerts(void);
Packit 40b132
Packit 40b132
SEC_END_PROTOS
Packit 40b132
Packit 40b132
#endif