-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspnegoparse.h
executable file
·169 lines (141 loc) · 6.89 KB
/
spnegoparse.h
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
// Copyright (C) 2002 Microsoft Corporation
// All rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS"
// WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
// OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE IMPLIED WARRANTIES OF MERCHANTIBILITY
// AND/OR FITNESS FOR A PARTICULAR PURPOSE.
//
// Date - 10/08/2002
// Author - Sanj Surati
/////////////////////////////////////////////////////////////
//
// SPNEGOPARSE.H
//
// SPNEGO Token Parser Header File
//
// Contains the definitions required to properly parse a
// SPNEGO token using ASN.1 DER helpers.
//
/////////////////////////////////////////////////////////////
#ifndef __SPNEGOPARSE_H__
#define __SPNEGOPARSE_H__
// C++ Specific
#if defined(__cplusplus)
extern "C"
{
#endif
// Indicates if we copy data when creating a SPNEGO_TOKEN structure or not
#define SPNEGO_TOKEN_INTERNAL_COPYPTR 0
#define SPNEGO_TOKEN_INTERNAL_COPYDATA 0x1
// Internal flag dictates whether or not we will free the binary data when
// the SPNEG_TOKEN structure is destroyed
#define SPNEGO_TOKEN_INTERNAL_FLAGS_FREEDATA 0x1
//
// Each SPNEGO Token Type can be broken down into a
// maximum of 4 separate elements.
//
#define MAX_NUM_TOKEN_ELEMENTS 4
//
// Element offsets in the array
//
// INIT elements
#define SPNEGO_INIT_MECHTYPES_ELEMENT 0
#define SPNEGO_INIT_REQFLAGS_ELEMENT 1
#define SPNEGO_INIT_MECHTOKEN_ELEMENT 2
#define SPNEGO_INIT_MECHLISTMIC_ELEMENT 3
// Response elements
#define SPNEGO_TARG_NEGRESULT_ELEMENT 0
#define SPNEGO_TARG_SUPPMECH_ELEMENT 1
#define SPNEGO_TARG_RESPTOKEN_ELEMENT 2
#define SPNEGO_TARG_MECHLISTMIC_ELEMENT 3
//
// Defines an individual SPNEGO Token Element.
//
typedef struct SpnegoElement
{
size_t nStructSize; // Size of the element structure
int iElementPresent; // Is the field present? Must be either
// SPNEGO_TOKEN_ELEMENT_UNAVAILABLE or
// SPNEGO_TOKEN_ELEMENT_AVAILABLE
SPNEGO_ELEMENT_TYPE eElementType; // The Element Type
unsigned char type; // Data Type
unsigned char* pbData; // Points to actual Data
unsigned long nDatalength; // Actual Data Length
} SPNEGO_ELEMENT;
// Structure size in case we later choose to extend the structure
#define SPNEGO_ELEMENT_SIZE sizeof(SPNEGO_ELEMENT)
//
// Packages a SPNEGO Token Encoding. There are two types of
// encodings: NegTokenInit and NegTokenTarg. Each encoding can
// contain up to four distinct, optional elements.
//
typedef struct SpnegoToken
{
size_t nStructSize; // Size of the Token structure
unsigned long ulFlags; // Internal Structure Flags - Reserved!
int ucTokenType; // Token Type - Must be
// SPNEGO_TOKEN_INIT or
// SPNEGO_TOKEN_TARG
unsigned char* pbBinaryData; // Points to binary token data
unsigned long ulBinaryDataLen; // Length of the actual binary data
int nNumElements; // Number of elements
SPNEGO_ELEMENT aElementArray [MAX_NUM_TOKEN_ELEMENTS]; // Holds the elements for the token
} SPNEGO_TOKEN;
// Structure size in case we later choose to extend the structure
#define SPNEGO_TOKEN_SIZE sizeof(SPNEGO_TOKEN)
//
// Function definitions
//
SPNEGO_TOKEN* AllocEmptySpnegoToken( unsigned char ucCopyData, unsigned long ulFlags,
unsigned char * pbTokenData, unsigned long ulTokenSize );
void FreeSpnegoToken( SPNEGO_TOKEN* pSpnegoToken );
void InitSpnegoTokenElementArray( SPNEGO_TOKEN* pSpnegoToken );
int InitSpnegoTokenType( SPNEGO_TOKEN* pSpnegoToken, long* pnTokenLength,
long* pnRemainingTokenLength, unsigned char** ppbFirstElement );
int InitSpnegoTokenElements( SPNEGO_TOKEN* pSpnegoToken, unsigned char* pbTokenData,
long nRemainingTokenLength );
int GetSpnegoInitTokenMechList( unsigned char* pbTokenData, int nMechListLength,
SPNEGO_ELEMENT* pSpnegoElement );
int InitSpnegoTokenElementFromBasicType( unsigned char* pbTokenData, int nElementLength,
unsigned char ucExpectedType,
SPNEGO_ELEMENT_TYPE spnegoElementType,
SPNEGO_ELEMENT* pSpnegoElement );
int InitSpnegoTokenElementFromOID( unsigned char* pbTokenData, int nElementLength,
SPNEGO_ELEMENT_TYPE spnegoElementType,
SPNEGO_ELEMENT* pSpnegoElement );
int FindMechOIDInMechList( SPNEGO_ELEMENT* pSpnegoElement, SPNEGO_MECH_OID MechOID,
int * piMechTypeIndex );
int ValidateMechList( unsigned char* pbMechListData, long nBoundaryLength );
int CalculateMinSpnegoInitTokenSize( long nMechTokenLength, long nMechListMICLength,
SPNEGO_MECH_OID mechOid, int nReqFlagsAvailable,
long* plTokenSize, long* plInternalLength );
int CalculateMinSpnegoTargTokenSize( SPNEGO_MECH_OID MechType, SPNEGO_NEGRESULT spnegoNegResult,
long nMechTokenLen,
long nMechTokenMIC, long* pnTokenSize,
long* pnInternalTokenLength );
int CreateSpnegoInitToken( SPNEGO_MECH_OID MechType,
unsigned char ucContextFlags, unsigned char* pbMechToken,
unsigned long ulMechTokenLen, unsigned char* pbMechListMIC,
unsigned long ulMechListMICLen, unsigned char* pbTokenData,
long nTokenLength, long nInternalTokenLength );
int CreateSpnegoTargToken( SPNEGO_MECH_OID MechType,
SPNEGO_NEGRESULT eNegResult, unsigned char* pbMechToken,
unsigned long ulMechTokenLen, unsigned char* pbMechListMIC,
unsigned long ulMechListMICLen, unsigned char* pbTokenData,
long nTokenLength, long nInternalTokenLength );
int IsValidMechOid( SPNEGO_MECH_OID mechOid );
int IsValidContextFlags( unsigned char ucContextFlags );
int IsValidNegResult( SPNEGO_NEGRESULT negResult );
int IsValidSpnegoToken( SPNEGO_TOKEN* pSpnegoToken );
int IsValidSpnegoElement( SPNEGO_TOKEN* pSpnegoToken,SPNEGO_ELEMENT_TYPE spnegoElement );
int CalculateElementArrayIndex( SPNEGO_TOKEN* pSpnegoToken,SPNEGO_ELEMENT_TYPE spnegoElement );
int InitTokenFromBinary( unsigned char ucCopyData, unsigned long ulFlags,
unsigned char* pbTokenData, unsigned long ulLength,
SPNEGO_TOKEN** ppSpnegoToken );
// C++ Specific
#if defined(__cplusplus)
}
#endif
#endif