xref: /titanic_41/usr/src/lib/libsmbfs/smb/spnegoparse.h (revision 4bff34e37def8a90f9194d81bc345c52ba20086a)
1*4bff34e3Sthurlow // Copyright (C) 2002 Microsoft Corporation
2*4bff34e3Sthurlow // All rights reserved.
3*4bff34e3Sthurlow //
4*4bff34e3Sthurlow // THIS CODE AND INFORMATION IS PROVIDED "AS IS"
5*4bff34e3Sthurlow // WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
6*4bff34e3Sthurlow // OR IMPLIED, INCLUDING BUT NOT LIMITED
7*4bff34e3Sthurlow // TO THE IMPLIED WARRANTIES OF MERCHANTIBILITY
8*4bff34e3Sthurlow // AND/OR FITNESS FOR A PARTICULAR PURPOSE.
9*4bff34e3Sthurlow //
10*4bff34e3Sthurlow // Date    - 10/08/2002
11*4bff34e3Sthurlow // Author  - Sanj Surati
12*4bff34e3Sthurlow 
13*4bff34e3Sthurlow /////////////////////////////////////////////////////////////
14*4bff34e3Sthurlow //
15*4bff34e3Sthurlow // SPNEGOPARSE.H
16*4bff34e3Sthurlow //
17*4bff34e3Sthurlow // SPNEGO Token Parser Header File
18*4bff34e3Sthurlow //
19*4bff34e3Sthurlow // Contains the definitions required to properly parse a
20*4bff34e3Sthurlow // SPNEGO token using ASN.1 DER helpers.
21*4bff34e3Sthurlow //
22*4bff34e3Sthurlow /////////////////////////////////////////////////////////////
23*4bff34e3Sthurlow 
24*4bff34e3Sthurlow #pragma ident	"%Z%%M%	%I%	%E% SMI"
25*4bff34e3Sthurlow 
26*4bff34e3Sthurlow #ifndef __SPNEGOPARSE_H__
27*4bff34e3Sthurlow #define __SPNEGOPARSE_H__
28*4bff34e3Sthurlow 
29*4bff34e3Sthurlow // C++ Specific
30*4bff34e3Sthurlow #if defined(__cplusplus)
31*4bff34e3Sthurlow extern "C"
32*4bff34e3Sthurlow {
33*4bff34e3Sthurlow #endif
34*4bff34e3Sthurlow 
35*4bff34e3Sthurlow // Indicates if we copy data when creating a SPNEGO_TOKEN structure or not
36*4bff34e3Sthurlow #define SPNEGO_TOKEN_INTERNAL_COPYPTR           0
37*4bff34e3Sthurlow #define SPNEGO_TOKEN_INTERNAL_COPYDATA          0x1
38*4bff34e3Sthurlow 
39*4bff34e3Sthurlow // Internal flag dictates whether or not we will free the binary data when
40*4bff34e3Sthurlow // the SPNEG_TOKEN structure is destroyed
41*4bff34e3Sthurlow #define  SPNEGO_TOKEN_INTERNAL_FLAGS_FREEDATA   0x1
42*4bff34e3Sthurlow 
43*4bff34e3Sthurlow    //
44*4bff34e3Sthurlow // Each SPNEGO Token Type can be broken down into a
45*4bff34e3Sthurlow // maximum of 4 separate elements.
46*4bff34e3Sthurlow //
47*4bff34e3Sthurlow 
48*4bff34e3Sthurlow #define  MAX_NUM_TOKEN_ELEMENTS  4
49*4bff34e3Sthurlow 
50*4bff34e3Sthurlow //
51*4bff34e3Sthurlow // Element offsets in the array
52*4bff34e3Sthurlow //
53*4bff34e3Sthurlow 
54*4bff34e3Sthurlow // INIT elements
55*4bff34e3Sthurlow #define  SPNEGO_INIT_MECHTYPES_ELEMENT    0
56*4bff34e3Sthurlow #define  SPNEGO_INIT_REQFLAGS_ELEMENT     1
57*4bff34e3Sthurlow #define  SPNEGO_INIT_MECHTOKEN_ELEMENT    2
58*4bff34e3Sthurlow #define  SPNEGO_INIT_MECHLISTMIC_ELEMENT  3
59*4bff34e3Sthurlow 
60*4bff34e3Sthurlow // Response elements
61*4bff34e3Sthurlow #define  SPNEGO_TARG_NEGRESULT_ELEMENT    0
62*4bff34e3Sthurlow #define  SPNEGO_TARG_SUPPMECH_ELEMENT     1
63*4bff34e3Sthurlow #define  SPNEGO_TARG_RESPTOKEN_ELEMENT    2
64*4bff34e3Sthurlow #define  SPNEGO_TARG_MECHLISTMIC_ELEMENT  3
65*4bff34e3Sthurlow 
66*4bff34e3Sthurlow //
67*4bff34e3Sthurlow // Defines an individual SPNEGO Token Element.
68*4bff34e3Sthurlow //
69*4bff34e3Sthurlow 
70*4bff34e3Sthurlow typedef struct SpnegoElement
71*4bff34e3Sthurlow {
72*4bff34e3Sthurlow    size_t                nStructSize;        // Size of the element structure
73*4bff34e3Sthurlow    int                   iElementPresent;    // Is the field present?  Must be either
74*4bff34e3Sthurlow                                              // SPNEGO_TOKEN_ELEMENT_UNAVAILABLE or
75*4bff34e3Sthurlow                                              // SPNEGO_TOKEN_ELEMENT_AVAILABLE
76*4bff34e3Sthurlow 
77*4bff34e3Sthurlow    SPNEGO_ELEMENT_TYPE   eElementType;       // The Element Type
78*4bff34e3Sthurlow 
79*4bff34e3Sthurlow    unsigned char         type;               // Data Type
80*4bff34e3Sthurlow 
81*4bff34e3Sthurlow    unsigned char*        pbData;             // Points to actual Data
82*4bff34e3Sthurlow 
83*4bff34e3Sthurlow    unsigned long         nDatalength;        // Actual Data Length
84*4bff34e3Sthurlow 
85*4bff34e3Sthurlow } SPNEGO_ELEMENT;
86*4bff34e3Sthurlow 
87*4bff34e3Sthurlow // Structure size in case we later choose to extend the structure
88*4bff34e3Sthurlow #define  SPNEGO_ELEMENT_SIZE sizeof(SPNEGO_ELEMENT)
89*4bff34e3Sthurlow 
90*4bff34e3Sthurlow //
91*4bff34e3Sthurlow // Packages a SPNEGO Token Encoding.  There are two types of
92*4bff34e3Sthurlow // encodings: NegTokenInit and NegTokenTarg.  Each encoding can
93*4bff34e3Sthurlow // contain up to four distinct, optional elements.
94*4bff34e3Sthurlow //
95*4bff34e3Sthurlow 
96*4bff34e3Sthurlow typedef struct SpnegoToken
97*4bff34e3Sthurlow {
98*4bff34e3Sthurlow    size_t            nStructSize;                              // Size of the Token structure
99*4bff34e3Sthurlow    unsigned long     ulFlags;                                  // Internal Structure Flags - Reserved!
100*4bff34e3Sthurlow    int               ucTokenType;                              // Token Type - Must be
101*4bff34e3Sthurlow                                                                // SPNEGO_TOKEN_INIT or
102*4bff34e3Sthurlow                                                                // SPNEGO_TOKEN_TARG
103*4bff34e3Sthurlow 
104*4bff34e3Sthurlow    unsigned char*    pbBinaryData;                             // Points to binary token data
105*4bff34e3Sthurlow 
106*4bff34e3Sthurlow    unsigned long     ulBinaryDataLen;                          // Length of the actual binary data
107*4bff34e3Sthurlow    int               nNumElements;                             // Number of elements
108*4bff34e3Sthurlow    SPNEGO_ELEMENT    aElementArray [MAX_NUM_TOKEN_ELEMENTS];   // Holds the elements for the token
109*4bff34e3Sthurlow } SPNEGO_TOKEN;
110*4bff34e3Sthurlow 
111*4bff34e3Sthurlow // Structure size in case we later choose to extend the structure
112*4bff34e3Sthurlow #define  SPNEGO_TOKEN_SIZE sizeof(SPNEGO_TOKEN)
113*4bff34e3Sthurlow 
114*4bff34e3Sthurlow //
115*4bff34e3Sthurlow // Function definitions
116*4bff34e3Sthurlow //
117*4bff34e3Sthurlow 
118*4bff34e3Sthurlow SPNEGO_TOKEN* AllocEmptySpnegoToken( unsigned char ucCopyData, unsigned long ulFlags,
119*4bff34e3Sthurlow                                     unsigned char * pbTokenData, unsigned long ulTokenSize );
120*4bff34e3Sthurlow void FreeSpnegoToken( SPNEGO_TOKEN* pSpnegoToken );
121*4bff34e3Sthurlow void InitSpnegoTokenElementArray( SPNEGO_TOKEN* pSpnegoToken );
122*4bff34e3Sthurlow int InitSpnegoTokenType( SPNEGO_TOKEN* pSpnegoToken, long* pnTokenLength,
123*4bff34e3Sthurlow                            long* pnRemainingTokenLength, unsigned char** ppbFirstElement );
124*4bff34e3Sthurlow int InitSpnegoTokenElements( SPNEGO_TOKEN* pSpnegoToken, unsigned char* pbTokenData,
125*4bff34e3Sthurlow                            long nRemainingTokenLength  );
126*4bff34e3Sthurlow int GetSpnegoInitTokenMechList( unsigned char* pbTokenData, int nMechListLength,
127*4bff34e3Sthurlow                                  SPNEGO_ELEMENT* pSpnegoElement );
128*4bff34e3Sthurlow int InitSpnegoTokenElementFromBasicType( unsigned char* pbTokenData, int nElementLength,
129*4bff34e3Sthurlow                                           unsigned char ucExpectedType,
130*4bff34e3Sthurlow                                           SPNEGO_ELEMENT_TYPE spnegoElementType,
131*4bff34e3Sthurlow                                           SPNEGO_ELEMENT* pSpnegoElement );
132*4bff34e3Sthurlow int InitSpnegoTokenElementFromOID( unsigned char* pbTokenData, int nElementLength,
133*4bff34e3Sthurlow                                    SPNEGO_ELEMENT_TYPE spnegoElementType,
134*4bff34e3Sthurlow                                    SPNEGO_ELEMENT* pSpnegoElement );
135*4bff34e3Sthurlow int FindMechOIDInMechList( SPNEGO_ELEMENT* pSpnegoElement, SPNEGO_MECH_OID MechOID,
136*4bff34e3Sthurlow                            int * piMechTypeIndex );
137*4bff34e3Sthurlow int ValidateMechList( unsigned char* pbMechListData, long nBoundaryLength );
138*4bff34e3Sthurlow int CalculateMinSpnegoInitTokenSize( long nMechTokenLength, long nMechListMICLength,
139*4bff34e3Sthurlow                                     SPNEGO_MECH_OID mechOid, int nReqFlagsAvailable,
140*4bff34e3Sthurlow                                     long* plTokenSize, long* plInternalLength );
141*4bff34e3Sthurlow int CalculateMinSpnegoTargTokenSize( SPNEGO_MECH_OID MechType, SPNEGO_NEGRESULT spnegoNegResult,
142*4bff34e3Sthurlow                                     long nMechTokenLen,
143*4bff34e3Sthurlow                                     long nMechTokenMIC, long* pnTokenSize,
144*4bff34e3Sthurlow                                     long* pnInternalTokenLength );
145*4bff34e3Sthurlow int CreateSpnegoInitToken( SPNEGO_MECH_OID MechType,
146*4bff34e3Sthurlow           unsigned char ucContextFlags, unsigned char* pbMechToken,
147*4bff34e3Sthurlow           unsigned long ulMechTokenLen, unsigned char* pbMechListMIC,
148*4bff34e3Sthurlow           unsigned long ulMechListMICLen, unsigned char* pbTokenData,
149*4bff34e3Sthurlow           long nTokenLength, long nInternalTokenLength );
150*4bff34e3Sthurlow int CreateSpnegoTargToken( SPNEGO_MECH_OID MechType,
151*4bff34e3Sthurlow           SPNEGO_NEGRESULT eNegResult, unsigned char* pbMechToken,
152*4bff34e3Sthurlow           unsigned long ulMechTokenLen, unsigned char* pbMechListMIC,
153*4bff34e3Sthurlow           unsigned long ulMechListMICLen, unsigned char* pbTokenData,
154*4bff34e3Sthurlow           long nTokenLength, long nInternalTokenLength );
155*4bff34e3Sthurlow int IsValidMechOid( SPNEGO_MECH_OID mechOid );
156*4bff34e3Sthurlow int IsValidContextFlags( unsigned char ucContextFlags );
157*4bff34e3Sthurlow int IsValidNegResult( SPNEGO_NEGRESULT negResult );
158*4bff34e3Sthurlow int IsValidSpnegoToken( SPNEGO_TOKEN* pSpnegoToken );
159*4bff34e3Sthurlow int IsValidSpnegoElement( SPNEGO_TOKEN* pSpnegoToken,SPNEGO_ELEMENT_TYPE spnegoElement );
160*4bff34e3Sthurlow int CalculateElementArrayIndex( SPNEGO_TOKEN* pSpnegoToken,SPNEGO_ELEMENT_TYPE spnegoElement );
161*4bff34e3Sthurlow int InitTokenFromBinary( unsigned char ucCopyData, unsigned long ulFlags,
162*4bff34e3Sthurlow                         unsigned char* pbTokenData, unsigned long ulLength,
163*4bff34e3Sthurlow                         SPNEGO_TOKEN** ppSpnegoToken );
164*4bff34e3Sthurlow 
165*4bff34e3Sthurlow    // C++ Specific
166*4bff34e3Sthurlow #if defined(__cplusplus)
167*4bff34e3Sthurlow }
168*4bff34e3Sthurlow #endif
169*4bff34e3Sthurlow 
170*4bff34e3Sthurlow #endif
171