xref: /onnv-gate/usr/src/lib/libsmbfs/smb/spnego.h (revision 6007:d57e38e8fdd1)
1*6007Sthurlow // Copyright (C) 2002 Microsoft Corporation
2*6007Sthurlow // All rights reserved.
3*6007Sthurlow //
4*6007Sthurlow // THIS CODE AND INFORMATION IS PROVIDED "AS IS"
5*6007Sthurlow // WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
6*6007Sthurlow // OR IMPLIED, INCLUDING BUT NOT LIMITED
7*6007Sthurlow // TO THE IMPLIED WARRANTIES OF MERCHANTIBILITY
8*6007Sthurlow // AND/OR FITNESS FOR A PARTICULAR PURPOSE.
9*6007Sthurlow //
10*6007Sthurlow // Date    - 10/08/2002
11*6007Sthurlow // Author  - Sanj Surati
12*6007Sthurlow 
13*6007Sthurlow /////////////////////////////////////////////////////////////
14*6007Sthurlow //
15*6007Sthurlow // SPNEGO.H
16*6007Sthurlow //
17*6007Sthurlow // SPNEGO Token Handler Header File
18*6007Sthurlow //
19*6007Sthurlow // Contains the definitions required to interpret and create
20*6007Sthurlow // SPNEGO tokens so that Kerberos GSS tokens can be
21*6007Sthurlow // Unpackaged/packaged.
22*6007Sthurlow //
23*6007Sthurlow /////////////////////////////////////////////////////////////
24*6007Sthurlow 
25*6007Sthurlow #pragma ident	"%Z%%M%	%I%	%E% SMI"
26*6007Sthurlow 
27*6007Sthurlow #ifndef __SPNEGO_H__
28*6007Sthurlow #define __SPNEGO_H__
29*6007Sthurlow 
30*6007Sthurlow // C++ Specific
31*6007Sthurlow #if defined(__cplusplus)
32*6007Sthurlow extern "C"
33*6007Sthurlow {
34*6007Sthurlow #endif
35*6007Sthurlow 
36*6007Sthurlow // Type Definitions
37*6007Sthurlow 
38*6007Sthurlow //
39*6007Sthurlow // Users of SPNEGO Token Handler API will request
40*6007Sthurlow // these as well as free them,
41*6007Sthurlow //
42*6007Sthurlow typedef void*  SPNEGO_TOKEN_HANDLE;
43*6007Sthurlow 
44*6007Sthurlow //
45*6007Sthurlow // Defines the element types that are found
46*6007Sthurlow // in each of the tokens.
47*6007Sthurlow //
48*6007Sthurlow 
49*6007Sthurlow typedef enum spnego_element_type
50*6007Sthurlow {
51*6007Sthurlow    spnego_element_min,  // Lower bound
52*6007Sthurlow 
53*6007Sthurlow    // Init token elements
54*6007Sthurlow    spnego_init_mechtypes,
55*6007Sthurlow    spnego_init_reqFlags,
56*6007Sthurlow    spnego_init_mechToken,
57*6007Sthurlow    spnego_init_mechListMIC,
58*6007Sthurlow 
59*6007Sthurlow    // Targ token elements
60*6007Sthurlow    spnego_targ_negResult,
61*6007Sthurlow    spnego_targ_supportedMech,
62*6007Sthurlow    spnego_targ_responseToken,
63*6007Sthurlow    spnego_targ_mechListMIC,
64*6007Sthurlow 
65*6007Sthurlow    spnego_element_max   // Upper bound
66*6007Sthurlow 
67*6007Sthurlow } SPNEGO_ELEMENT_TYPE;
68*6007Sthurlow 
69*6007Sthurlow //
70*6007Sthurlow // Token Element Availability.  Elements in both
71*6007Sthurlow // token types are optional.  Since there are only
72*6007Sthurlow // 4 elements in each Token, we will allocate space
73*6007Sthurlow // to hold the information, but we need a way to
74*6007Sthurlow // indicate whether or not an element is available
75*6007Sthurlow //
76*6007Sthurlow 
77*6007Sthurlow #define SPNEGO_TOKEN_ELEMENT_UNAVAILABLE 0
78*6007Sthurlow #define SPNEGO_TOKEN_ELEMENT_AVAILABLE 1
79*6007Sthurlow 
80*6007Sthurlow //
81*6007Sthurlow // Token type values.  SPNEGO has 2 token types:
82*6007Sthurlow // NegTokenInit and NegTokenTarg
83*6007Sthurlow //
84*6007Sthurlow 
85*6007Sthurlow #define SPNEGO_TOKEN_INIT 0
86*6007Sthurlow #define SPNEGO_TOKEN_TARG 1
87*6007Sthurlow 
88*6007Sthurlow //
89*6007Sthurlow // GSS Mechanism OID enumeration.  We only really handle
90*6007Sthurlow // 3 different OIDs.  These are stored in an array structure
91*6007Sthurlow // defined in the parsing code.
92*6007Sthurlow //
93*6007Sthurlow 
94*6007Sthurlow typedef enum spnego_mech_oid
95*6007Sthurlow {
96*6007Sthurlow    // Init token elements
97*6007Sthurlow    spnego_mech_oid_Kerberos_V5_Legacy, // Really V5, but OID off by 1 bit
98*6007Sthurlow    spnego_mech_oid_Kerberos_V5,
99*6007Sthurlow    spnego_mech_oid_Spnego,
100*6007Sthurlow    spnego_mech_oid_NTLMSSP,
101*6007Sthurlow    spnego_mech_oid_NotUsed = -1
102*6007Sthurlow 
103*6007Sthurlow } SPNEGO_MECH_OID;
104*6007Sthurlow 
105*6007Sthurlow //
106*6007Sthurlow // Defines the negResult values.
107*6007Sthurlow //
108*6007Sthurlow 
109*6007Sthurlow typedef enum spnego_negResult
110*6007Sthurlow {
111*6007Sthurlow    spnego_negresult_success,
112*6007Sthurlow    spnego_negresult_incomplete,
113*6007Sthurlow    spnego_negresult_rejected,
114*6007Sthurlow    spnego_negresult_NotUsed = -1
115*6007Sthurlow } SPNEGO_NEGRESULT;
116*6007Sthurlow 
117*6007Sthurlow //
118*6007Sthurlow // Context Flags in NegTokenInit
119*6007Sthurlow //
120*6007Sthurlow 
121*6007Sthurlow //
122*6007Sthurlow // ContextFlags values MUST be zero or a combination
123*6007Sthurlow // of the below
124*6007Sthurlow //
125*6007Sthurlow 
126*6007Sthurlow #define SPNEGO_NEGINIT_CONTEXT_DELEG_FLAG    0x80
127*6007Sthurlow #define SPNEGO_NEGINIT_CONTEXT_MUTUAL_FLAG   0x40
128*6007Sthurlow #define SPNEGO_NEGINIT_CONTEXT_REPLAY_FLAG   0x20
129*6007Sthurlow #define SPNEGO_NEGINIT_CONTEXT_SEQUENCE_FLAG 0x10
130*6007Sthurlow #define SPNEGO_NEGINIT_CONTEXT_ANON_FLAG     0x8
131*6007Sthurlow #define SPNEGO_NEGINIT_CONTEXT_CONF_FLAG     0x4
132*6007Sthurlow #define SPNEGO_NEGINIT_CONTEXT_INTEG_FLAG    0x2
133*6007Sthurlow 
134*6007Sthurlow //
135*6007Sthurlow // Mask to retrieve valid values.
136*6007Sthurlow //
137*6007Sthurlow 
138*6007Sthurlow #define SPNEGO_NEGINIT_CONTEXT_MASK          0xFE  // Logical combination of above flags
139*6007Sthurlow 
140*6007Sthurlow //
141*6007Sthurlow // SPNEGO API return codes.
142*6007Sthurlow //
143*6007Sthurlow 
144*6007Sthurlow // API function was successful
145*6007Sthurlow #define SPNEGO_E_SUCCESS               0
146*6007Sthurlow 
147*6007Sthurlow // The supplied Token was invalid
148*6007Sthurlow #define SPNEGO_E_INVALID_TOKEN         -1
149*6007Sthurlow 
150*6007Sthurlow // An invalid length was encountered
151*6007Sthurlow #define SPNEGO_E_INVALID_LENGTH        -2
152*6007Sthurlow 
153*6007Sthurlow // The Token Parse failed
154*6007Sthurlow #define SPNEGO_E_PARSE_FAILED          -3
155*6007Sthurlow 
156*6007Sthurlow // The requested value was not found
157*6007Sthurlow #define SPNEGO_E_NOT_FOUND             -4
158*6007Sthurlow 
159*6007Sthurlow // The requested element is not available
160*6007Sthurlow #define SPNEGO_E_ELEMENT_UNAVAILABLE   -5
161*6007Sthurlow 
162*6007Sthurlow // Out of Memory
163*6007Sthurlow #define SPNEGO_E_OUT_OF_MEMORY         -6
164*6007Sthurlow 
165*6007Sthurlow // Not Implemented
166*6007Sthurlow #define SPNEGO_E_NOT_IMPLEMENTED       -7
167*6007Sthurlow 
168*6007Sthurlow // Invalid Parameter
169*6007Sthurlow #define SPNEGO_E_INVALID_PARAMETER     -8
170*6007Sthurlow 
171*6007Sthurlow // Token Handler encountered an unexpected OID
172*6007Sthurlow #define SPNEGO_E_UNEXPECTED_OID        -9
173*6007Sthurlow 
174*6007Sthurlow // The requested token was not found
175*6007Sthurlow #define SPNEGO_E_TOKEN_NOT_FOUND       -10
176*6007Sthurlow 
177*6007Sthurlow // An unexpected type was encountered in the encoding
178*6007Sthurlow #define SPNEGO_E_UNEXPECTED_TYPE       -11
179*6007Sthurlow 
180*6007Sthurlow // The buffer was too small
181*6007Sthurlow #define SPNEGO_E_BUFFER_TOO_SMALL      -12
182*6007Sthurlow 
183*6007Sthurlow // A Token Element was invalid (e.g. improper length or value)
184*6007Sthurlow #define SPNEGO_E_INVALID_ELEMENT       -13
185*6007Sthurlow 
186*6007Sthurlow /* Miscelaneous API Functions */
187*6007Sthurlow 
188*6007Sthurlow // Frees opaque data
189*6007Sthurlow void spnegoFreeData( SPNEGO_TOKEN_HANDLE hSpnegoToken );
190*6007Sthurlow 
191*6007Sthurlow // Initializes SPNEGO_TOKEN structure from DER encoded binary data
192*6007Sthurlow int spnegoInitFromBinary( unsigned char* pbTokenData, unsigned long ulLength, SPNEGO_TOKEN_HANDLE* phSpnegoToken );
193*6007Sthurlow 
194*6007Sthurlow // Initializes SPNEGO_TOKEN structure for a NegTokenInit type using the
195*6007Sthurlow // supplied parameters
196*6007Sthurlow int spnegoCreateNegTokenInit( SPNEGO_MECH_OID MechType,
197*6007Sthurlow           unsigned char ucContextFlags, unsigned char* pbMechToken,
198*6007Sthurlow           unsigned long ulMechTokenLen, unsigned char* pbMechTokenMIC,
199*6007Sthurlow           unsigned long ulMechTokenMIC, SPNEGO_TOKEN_HANDLE* phSpnegoToken );
200*6007Sthurlow 
201*6007Sthurlow // Initializes SPNEGO_TOKEN structure for a NegTokenTarg type using the
202*6007Sthurlow // supplied parameters
203*6007Sthurlow int spnegoCreateNegTokenTarg( SPNEGO_MECH_OID MechType,
204*6007Sthurlow           SPNEGO_NEGRESULT spnegoNegResult, unsigned char* pbMechToken,
205*6007Sthurlow           unsigned long ulMechTokenLen, unsigned char* pbMechListMIC,
206*6007Sthurlow           unsigned long ulMechListMICLen, SPNEGO_TOKEN_HANDLE* phSpnegoToken );
207*6007Sthurlow 
208*6007Sthurlow // Copies binary representation of SPNEGO Data into user supplied buffer
209*6007Sthurlow int spnegoTokenGetBinary( SPNEGO_TOKEN_HANDLE hSpnegoToken, unsigned char* pbTokenData,
210*6007Sthurlow                            unsigned long * pulDataLen );
211*6007Sthurlow 
212*6007Sthurlow // Returns SPNEGO Token Type
213*6007Sthurlow int spnegoGetTokenType( SPNEGO_TOKEN_HANDLE hSpnegoToken, int * piTokenType );
214*6007Sthurlow 
215*6007Sthurlow /* Reading an Init Token */
216*6007Sthurlow 
217*6007Sthurlow // Returns the Initial Mech Type in the MechList element in the NegInitToken.
218*6007Sthurlow int spnegoIsMechTypeAvailable( SPNEGO_TOKEN_HANDLE hSpnegoToken, SPNEGO_MECH_OID MechOID, int * piMechTypeIndex );
219*6007Sthurlow 
220*6007Sthurlow // Returns the value from the context flags element in the NegInitToken as an unsigned long
221*6007Sthurlow int spnegoGetContextFlags( SPNEGO_TOKEN_HANDLE hSpnegoToken, unsigned char* pucContextFlags );
222*6007Sthurlow 
223*6007Sthurlow /* Reading a Response Token */
224*6007Sthurlow 
225*6007Sthurlow // Returns the value from the negResult element (Status code of GSS call - 0,1,2)
226*6007Sthurlow int spnegoGetNegotiationResult( SPNEGO_TOKEN_HANDLE hSpnegoToken, SPNEGO_NEGRESULT* pnegResult );
227*6007Sthurlow 
228*6007Sthurlow // Returns the Supported Mech Type from the NegTokenTarg.
229*6007Sthurlow int spnegoGetSupportedMechType( SPNEGO_TOKEN_HANDLE hSpnegoToken, SPNEGO_MECH_OID* pMechOID  );
230*6007Sthurlow 
231*6007Sthurlow /* Reading either Token Type */
232*6007Sthurlow 
233*6007Sthurlow // Returns the actual Mechanism data from the token (this is what is passed into GSS-API functions
234*6007Sthurlow int spnegoGetMechToken( SPNEGO_TOKEN_HANDLE hSpnegoToken, unsigned char* pbTokenData, unsigned long* pulDataLen );
235*6007Sthurlow 
236*6007Sthurlow // Returns the Message Integrity BLOB in the token
237*6007Sthurlow int spnegoGetMechListMIC( SPNEGO_TOKEN_HANDLE hSpnegoToken, unsigned char* pbMICData, unsigned long* pulDataLen );
238*6007Sthurlow 
239*6007Sthurlow // C++ Specific
240*6007Sthurlow #if defined(__cplusplus)
241*6007Sthurlow }
242*6007Sthurlow #endif
243*6007Sthurlow 
244*6007Sthurlow #endif
245