1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2000 by Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
*/
#ifndef _ISCSI_AUTHCLIENT_H
#define _ISCSI_AUTHCLIENT_H
/*
* This file is the include file for for iscsiAuthClient.c
*/
#ifdef __cplusplus
extern "C" {
#endif
enum { iscsiAuthStringMaxLength = 512 };
enum { iscsiAuthStringBlockMaxLength = 1024 };
enum { iscsiAuthLargeBinaryMaxLength = 1024 };
enum { iscsiAuthRecvEndMaxCount = 10 };
enum { iscsiAuthClientSignature = 0x5984B2E3 };
enum { iscsiAuthChapResponseLength = 16 };
/*
* Note: The ordering of these values are chosen to match
* the ordering of the keys as shown in the iSCSI spec.
* The table IscsiAuthClientKeyInfo in iscsiAuthClient.c
* must also match this order.
*/
enum iscsiAuthKeyType_t {
iscsiAuthKeyTypeNone = -1,
iscsiAuthKeyTypeFirst = 0,
iscsiAuthKeyTypeAuthMethod = iscsiAuthKeyTypeFirst,
iscsiAuthKeyTypeChapAlgorithm,
iscsiAuthKeyTypeChapUsername,
iscsiAuthKeyTypeChapResponse,
iscsiAuthKeyTypeChapIdentifier,
iscsiAuthKeyTypeChapChallenge,
iscsiAuthKeyTypeMaxCount,
iscsiAuthKeyTypeLast = iscsiAuthKeyTypeMaxCount - 1
};
typedef enum iscsiAuthKeyType_t IscsiAuthKeyType;
enum {
/*
* Common options for all keys.
*/
iscsiAuthOptionReject = -2,
iscsiAuthOptionNotPresent = -1,
iscsiAuthOptionNone = 1,
iscsiAuthMethodChap = 2,
iscsiAuthMethodMaxCount = 2,
iscsiAuthChapAlgorithmMd5 = 5,
iscsiAuthChapAlgorithmMaxCount = 2
};
enum iscsiAuthNegRole_t {
iscsiAuthNegRoleOriginator = 1,
iscsiAuthNegRoleResponder = 2
};
typedef enum iscsiAuthNegRole_t IscsiAuthNegRole;
/*
* Note: These values are chosen to map to the values sent
* in the iSCSI header.
*/
enum iscsiAuthVersion_t {
iscsiAuthVersionDraft8 = 2,
iscsiAuthVersionRfc = 0
};
typedef enum iscsiAuthVersion_t IscsiAuthVersion;
enum iscsiAuthStatus_t {
iscsiAuthStatusNoError = 0,
iscsiAuthStatusError,
iscsiAuthStatusPass,
iscsiAuthStatusFail,
iscsiAuthStatusContinue,
iscsiAuthStatusInProgress
};
typedef enum iscsiAuthStatus_t IscsiAuthStatus;
enum iscsiAuthDebugStatus_t {
iscsiAuthDebugStatusNotSet = 0,
iscsiAuthDebugStatusAuthPass,
iscsiAuthDebugStatusAuthRemoteFalse,
iscsiAuthDebugStatusAuthFail,
iscsiAuthDebugStatusAuthMethodBad,
iscsiAuthDebugStatusChapAlgorithmBad,
iscsiAuthDebugStatusPasswordDecryptFailed,
iscsiAuthDebugStatusPasswordTooShortWithNoIpSec,
iscsiAuthDebugStatusAuthServerError,
iscsiAuthDebugStatusAuthStatusBad,
iscsiAuthDebugStatusAuthPassNotValid,
iscsiAuthDebugStatusSendDuplicateSetKeyValue,
iscsiAuthDebugStatusSendStringTooLong,
iscsiAuthDebugStatusSendTooMuchData,
iscsiAuthDebugStatusAuthMethodExpected,
iscsiAuthDebugStatusChapAlgorithmExpected,
iscsiAuthDebugStatusChapIdentifierExpected,
iscsiAuthDebugStatusChapChallengeExpected,
iscsiAuthDebugStatusChapResponseExpected,
iscsiAuthDebugStatusChapUsernameExpected,
iscsiAuthDebugStatusAuthMethodNotPresent,
iscsiAuthDebugStatusAuthMethodReject,
iscsiAuthDebugStatusAuthMethodNone,
iscsiAuthDebugStatusChapAlgorithmReject,
iscsiAuthDebugStatusChapChallengeReflected,
iscsiAuthDebugStatusPasswordIdentical,
iscsiAuthDebugStatusLocalPasswordNotSet,
iscsiAuthDebugStatusChapIdentifierBad,
iscsiAuthDebugStatusChapChallengeBad,
iscsiAuthDebugStatusChapResponseBad,
iscsiAuthDebugStatusUnexpectedKeyPresent,
iscsiAuthDebugStatusTbitSetIllegal,
iscsiAuthDebugStatusTbitSetPremature,
iscsiAuthDebugStatusRecvMessageCountLimit,
iscsiAuthDebugStatusRecvDuplicateSetKeyValue,
iscsiAuthDebugStatusRecvStringTooLong,
iscsiAuthDebugStatusRecvTooMuchData
};
typedef enum iscsiAuthDebugStatus_t IscsiAuthDebugStatus;
enum iscsiAuthNodeType_t {
iscsiAuthNodeTypeInitiator = 1,
iscsiAuthNodeTypeTarget = 2
};
typedef enum iscsiAuthNodeType_t IscsiAuthNodeType;
enum iscsiAuthPhase_t {
iscsiAuthPhaseConfigure = 1,
iscsiAuthPhaseNegotiate, /* Negotiating */
iscsiAuthPhaseAuthenticate, /* Authenticating */
iscsiAuthPhaseDone, /* Authentication done */
iscsiAuthPhaseError
};
typedef enum iscsiAuthPhase_t IscsiAuthPhase;
enum iscsiAuthLocalState_t {
iscsiAuthLocalStateSendAlgorithm = 1,
iscsiAuthLocalStateRecvAlgorithm,
iscsiAuthLocalStateRecvChallenge,
iscsiAuthLocalStateDone,
iscsiAuthLocalStateError
};
typedef enum iscsiAuthLocalState_t IscsiAuthLocalState;
enum iscsiAuthRemoteState_t {
iscsiAuthRemoteStateSendAlgorithm = 1,
iscsiAuthRemoteStateSendChallenge,
iscsiAuthRemoteStateRecvResponse,
iscsiAuthRemoteStateAuthRequest,
iscsiAuthRemoteStateDone,
iscsiAuthRemoteStateError
};
typedef enum iscsiAuthRemoteState_t IscsiAuthRemoteState;
typedef void IscsiAuthClientCallback(void *, void *, int);
struct iscsiAuthClientGlobalStats_t {
unsigned long requestSent;
unsigned long responseReceived;
};
typedef struct iscsiAuthClientGlobalStats_t IscsiAuthClientGlobalStats;
struct iscsiAuthBufferDesc_t {
unsigned int length;
void *address;
};
typedef struct iscsiAuthBufferDesc_t IscsiAuthBufferDesc;
struct iscsiAuthKey_t {
unsigned int present:1;
unsigned int processed:1;
unsigned int valueSet:1; /* 1 if the value is set to be valid */
char *string;
};
typedef struct iscsiAuthKey_t IscsiAuthKey;
struct iscsiAuthLargeBinaryKey_t {
unsigned int length;
unsigned char *largeBinary;
};
typedef struct iscsiAuthLargeBinaryKey_t IscsiAuthLargeBinaryKey;
struct iscsiAuthKeyBlock_t {
unsigned int transitBit:1; /* To transit: TRUE or FALSE */
unsigned int duplicateSet:1; /* Set the value more than once */
unsigned int stringTooLong:1; /* Key value too long */
unsigned int tooMuchData:1; /* The keypair data blk overflows */
unsigned int blockLength:16; /* The length of the keypair data blk */
char *stringBlock;
IscsiAuthKey key[iscsiAuthKeyTypeMaxCount];
};
typedef struct iscsiAuthKeyBlock_t IscsiAuthKeyBlock;
struct iscsiAuthStringBlock_t {
char stringBlock[iscsiAuthStringBlockMaxLength];
};
typedef struct iscsiAuthStringBlock_t IscsiAuthStringBlock;
struct iscsiAuthLargeBinary_t {
unsigned char largeBinary[iscsiAuthLargeBinaryMaxLength];
};
typedef struct iscsiAuthLargeBinary_t IscsiAuthLargeBinary;
struct iscsiAuthClient_t {
unsigned long signature;
void *glueHandle;
struct iscsiAuthClient_t *next;
unsigned int authRequestId;
IscsiAuthNodeType nodeType;
unsigned int authMethodCount;
int authMethodList[iscsiAuthMethodMaxCount];
IscsiAuthNegRole authMethodNegRole;
unsigned int chapAlgorithmCount;
int chapAlgorithmList[iscsiAuthChapAlgorithmMaxCount];
/*
* To indicate if remote authentication is enabled (0 = no 1 = yes)
* For the case of initiator, remote authentication enabled means
* enabling target authentication.
*/
int authRemote;
char username[iscsiAuthStringMaxLength];
int passwordPresent;
unsigned int passwordLength;
unsigned char passwordData[iscsiAuthStringMaxLength];
char methodListName[iscsiAuthStringMaxLength];
IscsiAuthVersion version;
unsigned int chapChallengeLength;
int ipSec;
int base64;
unsigned int authMethodValidCount;
int authMethodValidList[iscsiAuthMethodMaxCount];
int authMethodValidNegRole;
const char *rejectOptionName;
const char *noneOptionName;
int recvInProgressFlag;
int recvEndCount;
IscsiAuthClientCallback *callback;
void *userHandle;
void *messageHandle;
IscsiAuthPhase phase;
IscsiAuthLocalState localState;
IscsiAuthRemoteState remoteState;
IscsiAuthStatus remoteAuthStatus;
IscsiAuthDebugStatus debugStatus;
int negotiatedAuthMethod;
int negotiatedChapAlgorithm;
int authResponseFlag;
int authServerErrorFlag;
int transitBitSentFlag;
unsigned int sendChapIdentifier;
IscsiAuthLargeBinaryKey sendChapChallenge;
char chapUsername[iscsiAuthStringMaxLength];
int recvChapChallengeStatus;
IscsiAuthLargeBinaryKey recvChapChallenge;
char scratchKeyValue[iscsiAuthStringMaxLength];
IscsiAuthKeyBlock recvKeyBlock; /* Received keypair data */
IscsiAuthKeyBlock sendKeyBlock; /* Keypair data to be sent */
};
typedef struct iscsiAuthClient_t IscsiAuthClient;
#ifdef __cplusplus
}
#endif
#include <sys/iscsi_authclientglue.h>
#ifdef __cplusplus
extern "C" {
#endif
extern IscsiAuthClientGlobalStats iscsiAuthClientGlobalStats;
extern int iscsiAuthClientInit(int, int, IscsiAuthBufferDesc *);
extern int iscsiAuthClientFinish(IscsiAuthClient *);
extern int iscsiAuthClientRecvBegin(IscsiAuthClient *);
extern int iscsiAuthClientRecvEnd(IscsiAuthClient *,
IscsiAuthClientCallback *, void *, void *);
extern const char *iscsiAuthClientGetKeyName(int);
extern int iscsiAuthClientGetNextKeyType(int *);
extern int iscsiAuthClientKeyNameToKeyType(const char *);
extern int iscsiAuthClientRecvKeyValue(IscsiAuthClient *, int, const char *);
extern int iscsiAuthClientSendKeyValue(IscsiAuthClient *, int, int *, char *,
unsigned int);
extern int iscsiAuthClientRecvTransitBit(IscsiAuthClient *, int);
extern int iscsiAuthClientSendTransitBit(IscsiAuthClient *, int *);
extern int iscsiAuthClientSetAuthMethodList(IscsiAuthClient *, unsigned int,
const int *);
extern int iscsiAuthClientSetAuthMethodNegRole(IscsiAuthClient *, int);
extern int iscsiAuthClientSetChapAlgorithmList(IscsiAuthClient *, unsigned int,
const int *);
extern int iscsiAuthClientSetUsername(IscsiAuthClient *, const char *);
extern int iscsiAuthClientSetPassword(IscsiAuthClient *, const unsigned char *,
unsigned int);
extern int iscsiAuthClientSetAuthRemote(IscsiAuthClient *, int);
extern int iscsiAuthClientSetGlueHandle(IscsiAuthClient *, void *);
extern int iscsiAuthClientSetMethodListName(IscsiAuthClient *, const char *);
extern int iscsiAuthClientSetIpSec(IscsiAuthClient *, int);
extern int iscsiAuthClientSetBase64(IscsiAuthClient *, int);
extern int iscsiAuthClientSetChapChallengeLength(IscsiAuthClient *,
unsigned int);
extern int iscsiAuthClientSetVersion(IscsiAuthClient *, int);
extern int iscsiAuthClientCheckPasswordNeeded(IscsiAuthClient *, int *);
extern int iscsiAuthClientGetAuthPhase(IscsiAuthClient *, int *);
extern int iscsiAuthClientGetAuthStatus(IscsiAuthClient *, int *);
extern int iscsiAuthClientAuthStatusPass(int);
extern int iscsiAuthClientGetAuthMethod(IscsiAuthClient *, int *);
extern int iscsiAuthClientGetChapAlgorithm(IscsiAuthClient *, int *);
extern int iscsiAuthClientGetChapUsername(IscsiAuthClient *, char *,
unsigned int);
extern int iscsiAuthClientSendStatusCode(IscsiAuthClient *, int *);
extern int iscsiAuthClientGetDebugStatus(IscsiAuthClient *, int *);
extern const char *iscsiAuthClientDebugStatusToText(int);
/*
* The following is called by platform dependent code.
*/
extern void iscsiAuthClientAuthResponse(IscsiAuthClient *, int);
/*
* The following routines are considered platform dependent,
* and need to be implemented for use by iscsiAuthClient.c.
*/
extern int iscsiAuthClientChapAuthRequest(IscsiAuthClient *, char *,
unsigned int,
unsigned char *, unsigned int, unsigned char *, unsigned int);
extern void iscsiAuthClientChapAuthCancel(IscsiAuthClient *);
extern int iscsiAuthClientTextToNumber(const char *, unsigned long *);
extern void iscsiAuthClientNumberToText(unsigned long, char *, unsigned int);
extern void iscsiAuthRandomSetData(unsigned char *, unsigned int);
extern void iscsiAuthMd5Init(IscsiAuthMd5Context *);
extern void iscsiAuthMd5Update(IscsiAuthMd5Context *, unsigned char *,
unsigned int);
extern void iscsiAuthMd5Final(unsigned char *, IscsiAuthMd5Context *);
extern int iscsiAuthClientData(unsigned char *, unsigned int *, unsigned char *,
unsigned int);
#ifdef __cplusplus
}
#endif
#endif /* _ISCSI_AUTHCLIENT_H */
|