"Fossies" - the Fresh Open Source Software Archive

Member "spnegohelp/derparse.h" (10 Apr 2005, 8345 Bytes) of package /linux/www/apache_httpd_modules/old/modgssapache-0.0.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Copyright (C) 2002 Microsoft Corporation
    2 // All rights reserved.
    3 //
    4 // THIS CODE AND INFORMATION IS PROVIDED "AS IS"
    5 // WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
    6 // OR IMPLIED, INCLUDING BUT NOT LIMITED
    7 // TO THE IMPLIED WARRANTIES OF MERCHANTIBILITY
    8 // AND/OR FITNESS FOR A PARTICULAR PURPOSE.
    9 //
   10 // Date    - 10/08/2002
   11 // Author  - Sanj Surati
   12 
   13 /////////////////////////////////////////////////////////////
   14 //
   15 // DERPARSE.H
   16 //
   17 // SPNEGO Token Handler Header File
   18 //
   19 // Contains the definitions required to properly parse the
   20 // SPNEGO DER encoding.
   21 //
   22 /////////////////////////////////////////////////////////////
   23 
   24 #ifndef __DERPARSE_H__
   25 #define __DERPARSE_H__
   26 
   27 // C++ Specific
   28 #if defined(__cplusplus)
   29 extern "C"
   30 {
   31 #endif
   32 
   33 /* Identifier Types */
   34 #define  IDENTIFIER_MASK               0xC0  // Bits 7 and 8
   35 #define  IDENTIFIER_UNIVERSAL          0x00  // 00 = universal
   36 #define  IDENTIFIER_APPLICATION        0x40  // 01 = application
   37 #define  IDENTIFIER_CONTEXT_SPECIFIC   0x80  // 10 = context specific
   38 #define  IDENTIFIER_PRIVATE            0xC0  // 11 = Private
   39 
   40 /* Encoding type */
   41 
   42 #define FORM_MASK       0x20    /* Bit 6 */
   43 #define PRIMITIVE       0x00    /* 0 = primitive */
   44 #define CONSTRUCTED     0x20    /* 1 = constructed */
   45 
   46 /* Universal tags */
   47 
   48 #define TAG_MASK        0x1F    /* Bits 5 - 1 */
   49 #define BOOLEAN         0x01    /*  1: TRUE or FALSE */
   50 #define INTEGER         0x02    /*  2: Arbitrary precision integer */
   51 #define BITSTRING       0x03    /*  2: Sequence of bits */
   52 #define OCTETSTRING     0x04    /*  4: Sequence of bytes */
   53 #define NULLTAG         0x05    /*  5: NULL */
   54 #define OID             0x06    /*  6: Object Identifier (numeric sequence) */
   55 #define OBJDESCRIPTOR   0x07    /*  7: Object Descriptor (human readable) */
   56 #define EXTERNAL        0x08    /*  8: External / Instance Of */
   57 #define REAL            0x09    /*  9: Real (Mantissa * Base^Exponent) */
   58 #define ENUMERATED      0x0A    /* 10: Enumerated */
   59 #define EMBEDDED_PDV    0x0B    /* 11: Embedded Presentation Data Value */
   60 #define SEQUENCE        0x10    /* 16: Constructed Sequence / Sequence Of */
   61 #define SET             0x11    /* 17: Constructed Set / Set Of */
   62 #define NUMERICSTR      0x12    /* 18: Numeric String (digits only) */
   63 #define PRINTABLESTR    0x13    /* 19: Printable String */
   64 #define T61STR          0x14    /* 20: T61 String (Teletex) */
   65 #define VIDEOTEXSTR     0x15    /* 21: Videotex String */
   66 #define IA5STR          0x16    /* 22: IA5 String */
   67 #define UTCTIME         0x17    /* 23: UTC Time */
   68 #define GENERALIZEDTIME 0x18    /* 24: Generalized Time */
   69 #define GRAPHICSTR      0x19    /* 25: Graphic String */
   70 #define VISIBLESTR      0x1A    /* 26: Visible String (ISO 646) */
   71 #define GENERALSTR      0x1B    /* 27: General String */
   72 #define UNIVERSALSTR    0x1C    /* 28: Universal String */
   73 #define BMPSTR          0x1E    /* 30: Basic Multilingual Plane String */
   74 
   75 /* Length encoding */
   76 
   77 #define LEN_XTND  0x80      /* Indefinite or long form */
   78 #define LEN_MASK  0x7f      /* Bits 7 - 1 */
   79 
   80 //
   81 // SPNEGO Token Parsing Constants
   82 //
   83 
   84 
   85 // Fixed Length of NegTokenInit ReqFlags field
   86 #define  SPNEGO_NEGINIT_MAXLEN_REQFLAGS   2
   87 
   88 // Difference in bits for ReqFlags token
   89 #define  SPNEGO_NEGINIT_REQFLAGS_BITDIFF  1
   90 
   91 // Fixed Length of NegTokenTarg NegResult field
   92 #define  SPNEGO_NEGTARG_MAXLEN_NEGRESULT  1
   93 
   94 // Application Specific Construct - Always at the start of a NegTokenInit
   95 #define  SPNEGO_NEGINIT_APP_CONSTRUCT     ( IDENTIFIER_APPLICATION | CONSTRUCTED ) // 0x60
   96 
   97 // Constructed Sequence token - after the actual token identifier token
   98 #define  SPNEGO_CONSTRUCTED_SEQUENCE      ( SEQUENCE | CONSTRUCTED )
   99 
  100 // MechList Type Identifier
  101 #define  SPNEGO_MECHLIST_TYPE      ( SEQUENCE | CONSTRUCTED | OID )
  102 
  103 //
  104 // NegTokenInit - Token Identifier and Elements
  105 //
  106 
  107 // NegTokenInit - 0xa0
  108 #define  SPNEGO_NEGINIT_TOKEN_IDENTIFIER  ( IDENTIFIER_CONTEXT_SPECIFIC | CONSTRUCTED |  \
  109                                              SPNEGO_TOKEN_INIT )
  110 
  111 // Structure elements for NegTokenInit
  112 #define  SPNEGO_NEGINIT_MECHTYPES   0x0   // MechTypes is element 0
  113 #define  SPNEGO_NEGINIT_REQFLAGS    0x1   // ReqFlags is element 1
  114 #define  SPNEGO_NEGINIT_MECHTOKEN   0x2   // MechToken is element 2
  115 #define  SPNEGO_NEGINIT_MECHLISTMIC 0x3   // MechListMIC is element 3
  116 
  117 // MechTypes element is 0xa0
  118 #define  SPNEGO_NEGINIT_ELEMENT_MECHTYPES    ( IDENTIFIER_CONTEXT_SPECIFIC | CONSTRUCTED |  \
  119                                                 SPNEGO_NEGINIT_MECHTYPES )
  120 
  121 // ReqFlags element is 0xa1
  122 #define  SPNEGO_NEGINIT_ELEMENT_REQFLAGS     ( IDENTIFIER_CONTEXT_SPECIFIC | CONSTRUCTED |  \
  123                                                 SPNEGO_NEGINIT_REQFLAGS )
  124 
  125 // MechToken element is 0xa2
  126 #define  SPNEGO_NEGINIT_ELEMENT_MECHTOKEN    ( IDENTIFIER_CONTEXT_SPECIFIC | CONSTRUCTED |  \
  127                                                 SPNEGO_NEGINIT_MECHTOKEN )
  128 
  129 // MechListMIC element is 0xa3
  130 #define  SPNEGO_NEGINIT_ELEMENT_MECHLISTMIC  ( IDENTIFIER_CONTEXT_SPECIFIC | CONSTRUCTED |  \
  131                                                 SPNEGO_NEGINIT_MECHLISTMIC )
  132 
  133 //
  134 // NegTokenTarg - Token Identifier and Elements
  135 //
  136 
  137 // NegTokenTarg - 0xa1
  138 #define  SPNEGO_NEGTARG_TOKEN_IDENTIFIER  ( IDENTIFIER_CONTEXT_SPECIFIC | CONSTRUCTED |  \
  139                                              SPNEGO_TOKEN_TARG )
  140 
  141 // Structure elements for NegTokenTarg
  142 #define  SPNEGO_NEGTARG_NEGRESULT         0x0   // NegResult is element 0
  143 #define  SPNEGO_NEGTARG_SUPPORTEDMECH     0x1   // SupportedMech is element 1
  144 #define  SPNEGO_NEGTARG_RESPONSETOKEN     0x2   // ResponseToken is element 2
  145 #define  SPNEGO_NEGTARG_MECHLISTMIC       0x3   // MechListMIC is element 3
  146 
  147 // NegResult element is 0xa0
  148 #define  SPNEGO_NEGTARG_ELEMENT_NEGRESULT          ( IDENTIFIER_CONTEXT_SPECIFIC | CONSTRUCTED |  \
  149                                                       SPNEGO_NEGTARG_NEGRESULT )
  150 
  151 // SupportedMech element is 0xa1
  152 #define  SPNEGO_NEGTARG_ELEMENT_SUPPORTEDMECH      ( IDENTIFIER_CONTEXT_SPECIFIC | CONSTRUCTED |  \
  153                                                       SPNEGO_NEGTARG_SUPPORTEDMECH )
  154 
  155 // ResponseToken element is 0xa2
  156 #define  SPNEGO_NEGTARG_ELEMENT_RESPONSETOKEN      ( IDENTIFIER_CONTEXT_SPECIFIC | CONSTRUCTED |  \
  157                                                       SPNEGO_NEGTARG_RESPONSETOKEN )
  158 
  159 // MechListMIC element is 0xa3
  160 #define  SPNEGO_NEGTARG_ELEMENT_MECHLISTMIC        ( IDENTIFIER_CONTEXT_SPECIFIC | CONSTRUCTED |  \
  161                                                       SPNEGO_NEGTARG_MECHLISTMIC )
  162 
  163 //
  164 // Defines a GSS Mechanism OID.  We keep a single static array
  165 // of these which we'll use for validation/searches/parsing.
  166 //
  167 
  168 typedef struct _mechOID
  169 {
  170    unsigned char*    ucOid;            // Byte representation of OID
  171    int               iLen;             // Length of the OID, length and identifier
  172    int               iActualDataLen;   // Length of the actual OID 
  173    SPNEGO_MECH_OID   eMechanismOID;     // Which OID is this?   
  174 } MECH_OID;
  175 
  176 
  177 //
  178 // ASN Der functions
  179 //
  180 
  181 int ASNDerGetLength( unsigned char* pbLengthData, long nBoundaryLength, long* pnLength,
  182                     long* pnNumLengthBytes );
  183 int ASNDerCheckToken( unsigned char* pbTokenData, unsigned char nToken,
  184                         long nCheckLength, long nBoundaryLength, long* pnLength,
  185                         long* pnTokenLength );
  186 int ASNDerCheckOID( unsigned char* pbTokenData, SPNEGO_MECH_OID nMechOID, long nBoundaryLength,
  187                      long* pnTokenLength );
  188 int ASNDerCalcNumLengthBytes( long nLength );
  189 long ASNDerCalcTokenLength( long nLength, long nDataLength );
  190 long ASNDerCalcElementLength( long nDataLength, long* pnInternalLength );
  191 long ASNDerCalcMechListLength( SPNEGO_MECH_OID mechoid, long* pnInternalLength );
  192 int ASNDerWriteLength( unsigned char* pbData, long nLength );
  193 int ASNDerWriteToken( unsigned char* pbData, unsigned char ucType,
  194                      unsigned char* pbTokenValue, long nLength );
  195 int ASNDerWriteOID( unsigned char* pbData, SPNEGO_MECH_OID eMechOID );
  196 long ASNDerWriteMechList( unsigned char* pbData, SPNEGO_MECH_OID mechoid );
  197 int ASNDerWriteElement( unsigned char* pbData, unsigned char ucElementSequence,
  198                         unsigned char ucType, unsigned char* pbTokenValue, long nLength );
  199 
  200 
  201    // C++ Specific
  202 #if defined(__cplusplus)
  203 }
  204 #endif
  205 
  206 #endif
  207