Path: blob/master/src/jdk.crypto.cryptoki/share/native/libj2pkcs11/j2secmod.h
41149 views
/*1* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include <jni.h>2627#include "sun_security_pkcs11_Secmod.h"2829// #define SECMOD_DEBUG3031#include "j2secmod_md.h"3233#include "p11_md.h"343536void *findFunction(JNIEnv *env, jlong jHandle, const char *functionName);3738#ifdef SECMOD_DEBUG39#define dprintf(s) printf(s)40#define dprintf1(s, p1) printf(s, p1)41#define dprintf2(s, p1, p2) printf(s, p1, p2)42#define dprintf3(s, p1, p2, p3) printf(s, p1, p2, p3)43#else44#define dprintf(s)45#define dprintf1(s, p1)46#define dprintf2(s, p1, p2)47#define dprintf3(s, p1, p2, p3)48#endif4950// NSS types5152typedef int PRBool;53typedef unsigned short PRUint16;54typedef short PRInt16;55typedef unsigned int PRUint32;56typedef int PRInt32;57typedef long long PRInt64;5859typedef PRUint32 PRIntervalTime;60typedef PRInt64 PRTime;6162typedef struct PK11SlotInfoStr PK11SlotInfo;6364typedef struct SECMODModuleStr SECMODModule;65typedef struct SECMODModuleListStr SECMODModuleList;6667// Defined in NSS's secmodt.h header68/* PKCS #11 disable reasons */69typedef enum {70PK11_DIS_NONE = 0,71PK11_DIS_USER_SELECTED = 1,72PK11_DIS_COULD_NOT_INIT_TOKEN = 2,73PK11_DIS_TOKEN_VERIFY_FAILED = 3,74PK11_DIS_TOKEN_NOT_PRESENT = 475} PK11DisableReasons;7677// Slot IDs - defined in Secmod.java on the Java side78// Values obtained from NSS's pkcs11i.h header79#define NETSCAPE_SLOT_ID 180#define PRIVATE_KEY_SLOT_ID 281#define FIPS_SLOT_ID 38283// Defined in NSS's secmodti.h header84/* represent a pkcs#11 slot reference counted. */85struct PK11SlotInfoStr {86/* the PKCS11 function list for this slot */87void *functionList;88SECMODModule *module; /* our parent module */89/* Boolean to indicate the current state of this slot */90PRBool needTest; /* Has this slot been tested for Export complience */91PRBool isPerm; /* is this slot a permanment device */92PRBool isHW; /* is this slot a hardware device */93PRBool isInternal; /* is this slot one of our internal PKCS #11 devices */94PRBool disabled; /* is this slot disabled... */95PK11DisableReasons reason; /* Why this slot is disabled */96PRBool readOnly; /* is the token in this slot read-only */97PRBool needLogin; /* does the token of the type that needs98* authentication (still true even if token is logged99* in) */100PRBool hasRandom; /* can this token generated random numbers */101PRBool defRWSession; /* is the default session RW (we open our default102* session rw if the token can only handle one session103* at a time. */104PRBool isThreadSafe; /* copied from the module */105/* The actual flags (many of which are distilled into the above PRBools) */106CK_FLAGS flags; /* flags from PKCS #11 token Info */107/* a default session handle to do quick and dirty functions */108CK_SESSION_HANDLE session;109void *sessionLock; /* lock for this session */110/* our ID */111CK_SLOT_ID slotID;112/* persistant flags saved from startup to startup */113unsigned long defaultFlags;114/* keep track of who is using us so we don't accidently get freed while115* still in use */116PRInt32 refCount; /* to be in/decremented by atomic calls ONLY! */117void *freeListLock;118void *freeSymKeysWithSessionHead;119void *freeSymKeysHead;120int keyCount;121int maxKeyCount;122/* Password control functions for this slot. many of these are only123* active if the appropriate flag is on in defaultFlags */124int askpw; /* what our password options are */125int timeout; /* If we're ask_timeout, what is our timeout time is126* seconds */127int authTransact; /* allow multiple authentications off one password if128* they are all part of the same transaction */129PRTime authTime; /* when were we last authenticated */130int minPassword; /* smallest legal password */131int maxPassword; /* largest legal password */132PRUint16 series; /* break up the slot info into various groups of133* inserted tokens so that keys and certs can be134* invalidated */135PRUint16 flagSeries; /* record the last series for the last event136* returned for this slot */137PRBool flagState; /* record the state of the last event returned for this138* slot. */139PRUint16 wrapKey; /* current wrapping key for SSL master secrets */140CK_MECHANISM_TYPE wrapMechanism;141/* current wrapping mechanism for current wrapKey */142CK_OBJECT_HANDLE refKeys[1]; /* array of existing wrapping keys for */143CK_MECHANISM_TYPE *mechanismList; /* list of mechanism supported by this144* token */145int mechanismCount;146/* cache the certificates stored on the token of this slot */147void **cert_array;148int array_size;149int cert_count;150char serial[16];151/* since these are odd sizes, keep them last. They are odd sizes to152* allow them to become null terminated strings */153char slot_name[65];154char token_name[33];155PRBool hasRootCerts;156PRBool hasRootTrust;157PRBool hasRSAInfo;158CK_FLAGS RSAInfoFlags;159PRBool protectedAuthPath;160PRBool isActiveCard;161PRIntervalTime lastLoginCheck;162unsigned int lastState;163/* for Stan */164void *nssToken;165/* the tokeninfo struct */166CK_TOKEN_INFO tokenInfo;167/* fast mechanism lookup */168char mechanismBits[256];169CK_PROFILE_ID *profileList;170int profileCount;171};172173// Defined in NSS's secmodt.h header174struct SECMODModuleStr {175void *v1;176PRBool internal; /* true of internally linked modules, false177* for the loaded modules */178PRBool loaded; /* Set to true if module has been loaded */179PRBool isFIPS; /* Set to true if module is finst internal */180char *dllName; /* name of the shared library which implements181* this module */182char *commonName; /* name of the module to display to the user */183void *library; /* pointer to the library. opaque. used only by184* pk11load.c */185186void *functionList; /* The PKCS #11 function table */187void *refLock; /* only used pk11db.c */188int refCount; /* Module reference count */189PK11SlotInfo **slots; /* array of slot points attached to this mod*/190int slotCount; /* count of slot in above array */191void *slotInfo; /* special info about slots default settings */192int slotInfoCount; /* count */193// incomplete, sizeof() is wrong194};195196// Defined in NSS's secmodt.h header197struct SECMODModuleListStr {198SECMODModuleList *next;199SECMODModule *module;200};201202203