int ASNDerWriteElement( unsigned char* pbData, unsigned char ucElementSequence, unsigned char ucType, unsigned char* pbTokenValue, long nLength ) { // First get the length long nInternalLength = 0L; long nElementLength = ASNDerCalcElementLength( nLength, &nInternalLength ); long nTempLength = 0L; // Write out the sequence byte and the length of the type and data nTempLength = ASNDerWriteToken( pbData, ucElementSequence, NULL, nInternalLength ); // Adjust the data pointer pbData += nTempLength; // Now write the type and the data. nTempLength = ASNDerWriteToken( pbData, ucType, pbTokenValue, nLength ); return nElementLength; }
int spnegoCreateNegTokenHint( SPNEGO_MECH_OID *pMechTypeList, int MechTypeCnt, unsigned char *pbPrincipal, SPNEGO_TOKEN_HANDLE* phSpnegoToken ) { int nReturn; long nTokenLength = 0L; long nInternalTokenLength = 0L; unsigned long ulPrincipalLen; unsigned char* pbMechListMIC; unsigned long ulMechListMICLen; unsigned char* pbTokenData = NULL; SPNEGO_TOKEN** ppSpnegoToken = (SPNEGO_TOKEN**) phSpnegoToken; if ( NULL == ppSpnegoToken || NULL == pbPrincipal ) return (SPNEGO_E_INVALID_PARAMETER); /* * Get the actual token size */ ulPrincipalLen = strlen((char *)pbPrincipal); ulMechListMICLen = ASNDerCalcElementLength( ulPrincipalLen, NULL ); nReturn = CalculateMinSpnegoInitTokenSize( 0, /* ulMechTokenLen */ ulMechListMICLen, pMechTypeList, MechTypeCnt, 0, /* nReqFlagsAvailable */ &nTokenLength, &nInternalTokenLength ); if ( nReturn != SPNEGO_E_SUCCESS ) return (nReturn); // Allocate a buffer to hold the data. pbTokenData = calloc( 1, nTokenLength ); if ( NULL == pbTokenData ) return ( SPNEGO_E_OUT_OF_MEMORY ); /* * Construct the MechListMIC */ pbMechListMIC = pbTokenData + (nTokenLength - ulMechListMICLen); (void) ASNDerWriteElement( pbMechListMIC, SPNEGO_NEGINIT_ELEMENT_MECHTYPES, GENERALSTR, pbPrincipal, ulPrincipalLen ); // Now write the token nReturn = CreateSpnegoInitToken( pMechTypeList, MechTypeCnt, 0, /* ContextFlags */ NULL, 0, /* MechToken, len */ pbMechListMIC, ulMechListMICLen, pbTokenData, nTokenLength, nInternalTokenLength ); if ( nReturn != SPNEGO_E_SUCCESS ) { free( pbTokenData ); return (nReturn); } // This will copy our allocated pointer, and ensure that the sructure cleans // up the data later nReturn = InitTokenFromBinary( SPNEGO_TOKEN_INTERNAL_COPYPTR, SPNEGO_TOKEN_INTERNAL_FLAGS_FREEDATA, pbTokenData, nTokenLength, ppSpnegoToken ); // Cleanup on failure if ( nReturn != SPNEGO_E_SUCCESS ) { free( pbTokenData ); return (nReturn); } return (SPNEGO_E_SUCCESS); }