Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.crypto.cryptoki/share/native/libj2pkcs11/j2secmod.h
41149 views
1
/*
2
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
#include <jni.h>
27
28
#include "sun_security_pkcs11_Secmod.h"
29
30
// #define SECMOD_DEBUG
31
32
#include "j2secmod_md.h"
33
34
#include "p11_md.h"
35
36
37
void *findFunction(JNIEnv *env, jlong jHandle, const char *functionName);
38
39
#ifdef SECMOD_DEBUG
40
#define dprintf(s) printf(s)
41
#define dprintf1(s, p1) printf(s, p1)
42
#define dprintf2(s, p1, p2) printf(s, p1, p2)
43
#define dprintf3(s, p1, p2, p3) printf(s, p1, p2, p3)
44
#else
45
#define dprintf(s)
46
#define dprintf1(s, p1)
47
#define dprintf2(s, p1, p2)
48
#define dprintf3(s, p1, p2, p3)
49
#endif
50
51
// NSS types
52
53
typedef int PRBool;
54
typedef unsigned short PRUint16;
55
typedef short PRInt16;
56
typedef unsigned int PRUint32;
57
typedef int PRInt32;
58
typedef long long PRInt64;
59
60
typedef PRUint32 PRIntervalTime;
61
typedef PRInt64 PRTime;
62
63
typedef struct PK11SlotInfoStr PK11SlotInfo;
64
65
typedef struct SECMODModuleStr SECMODModule;
66
typedef struct SECMODModuleListStr SECMODModuleList;
67
68
// Defined in NSS's secmodt.h header
69
/* PKCS #11 disable reasons */
70
typedef enum {
71
PK11_DIS_NONE = 0,
72
PK11_DIS_USER_SELECTED = 1,
73
PK11_DIS_COULD_NOT_INIT_TOKEN = 2,
74
PK11_DIS_TOKEN_VERIFY_FAILED = 3,
75
PK11_DIS_TOKEN_NOT_PRESENT = 4
76
} PK11DisableReasons;
77
78
// Slot IDs - defined in Secmod.java on the Java side
79
// Values obtained from NSS's pkcs11i.h header
80
#define NETSCAPE_SLOT_ID 1
81
#define PRIVATE_KEY_SLOT_ID 2
82
#define FIPS_SLOT_ID 3
83
84
// Defined in NSS's secmodti.h header
85
/* represent a pkcs#11 slot reference counted. */
86
struct PK11SlotInfoStr {
87
/* the PKCS11 function list for this slot */
88
void *functionList;
89
SECMODModule *module; /* our parent module */
90
/* Boolean to indicate the current state of this slot */
91
PRBool needTest; /* Has this slot been tested for Export complience */
92
PRBool isPerm; /* is this slot a permanment device */
93
PRBool isHW; /* is this slot a hardware device */
94
PRBool isInternal; /* is this slot one of our internal PKCS #11 devices */
95
PRBool disabled; /* is this slot disabled... */
96
PK11DisableReasons reason; /* Why this slot is disabled */
97
PRBool readOnly; /* is the token in this slot read-only */
98
PRBool needLogin; /* does the token of the type that needs
99
* authentication (still true even if token is logged
100
* in) */
101
PRBool hasRandom; /* can this token generated random numbers */
102
PRBool defRWSession; /* is the default session RW (we open our default
103
* session rw if the token can only handle one session
104
* at a time. */
105
PRBool isThreadSafe; /* copied from the module */
106
/* The actual flags (many of which are distilled into the above PRBools) */
107
CK_FLAGS flags; /* flags from PKCS #11 token Info */
108
/* a default session handle to do quick and dirty functions */
109
CK_SESSION_HANDLE session;
110
void *sessionLock; /* lock for this session */
111
/* our ID */
112
CK_SLOT_ID slotID;
113
/* persistant flags saved from startup to startup */
114
unsigned long defaultFlags;
115
/* keep track of who is using us so we don't accidently get freed while
116
* still in use */
117
PRInt32 refCount; /* to be in/decremented by atomic calls ONLY! */
118
void *freeListLock;
119
void *freeSymKeysWithSessionHead;
120
void *freeSymKeysHead;
121
int keyCount;
122
int maxKeyCount;
123
/* Password control functions for this slot. many of these are only
124
* active if the appropriate flag is on in defaultFlags */
125
int askpw; /* what our password options are */
126
int timeout; /* If we're ask_timeout, what is our timeout time is
127
* seconds */
128
int authTransact; /* allow multiple authentications off one password if
129
* they are all part of the same transaction */
130
PRTime authTime; /* when were we last authenticated */
131
int minPassword; /* smallest legal password */
132
int maxPassword; /* largest legal password */
133
PRUint16 series; /* break up the slot info into various groups of
134
* inserted tokens so that keys and certs can be
135
* invalidated */
136
PRUint16 flagSeries; /* record the last series for the last event
137
* returned for this slot */
138
PRBool flagState; /* record the state of the last event returned for this
139
* slot. */
140
PRUint16 wrapKey; /* current wrapping key for SSL master secrets */
141
CK_MECHANISM_TYPE wrapMechanism;
142
/* current wrapping mechanism for current wrapKey */
143
CK_OBJECT_HANDLE refKeys[1]; /* array of existing wrapping keys for */
144
CK_MECHANISM_TYPE *mechanismList; /* list of mechanism supported by this
145
* token */
146
int mechanismCount;
147
/* cache the certificates stored on the token of this slot */
148
void **cert_array;
149
int array_size;
150
int cert_count;
151
char serial[16];
152
/* since these are odd sizes, keep them last. They are odd sizes to
153
* allow them to become null terminated strings */
154
char slot_name[65];
155
char token_name[33];
156
PRBool hasRootCerts;
157
PRBool hasRootTrust;
158
PRBool hasRSAInfo;
159
CK_FLAGS RSAInfoFlags;
160
PRBool protectedAuthPath;
161
PRBool isActiveCard;
162
PRIntervalTime lastLoginCheck;
163
unsigned int lastState;
164
/* for Stan */
165
void *nssToken;
166
/* the tokeninfo struct */
167
CK_TOKEN_INFO tokenInfo;
168
/* fast mechanism lookup */
169
char mechanismBits[256];
170
CK_PROFILE_ID *profileList;
171
int profileCount;
172
};
173
174
// Defined in NSS's secmodt.h header
175
struct SECMODModuleStr {
176
void *v1;
177
PRBool internal; /* true of internally linked modules, false
178
* for the loaded modules */
179
PRBool loaded; /* Set to true if module has been loaded */
180
PRBool isFIPS; /* Set to true if module is finst internal */
181
char *dllName; /* name of the shared library which implements
182
* this module */
183
char *commonName; /* name of the module to display to the user */
184
void *library; /* pointer to the library. opaque. used only by
185
* pk11load.c */
186
187
void *functionList; /* The PKCS #11 function table */
188
void *refLock; /* only used pk11db.c */
189
int refCount; /* Module reference count */
190
PK11SlotInfo **slots; /* array of slot points attached to this mod*/
191
int slotCount; /* count of slot in above array */
192
void *slotInfo; /* special info about slots default settings */
193
int slotInfoCount; /* count */
194
// incomplete, sizeof() is wrong
195
};
196
197
// Defined in NSS's secmodt.h header
198
struct SECMODModuleListStr {
199
SECMODModuleList *next;
200
SECMODModule *module;
201
};
202
203