/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Actually checks for ASCII only unlike isdigit() on Windows. // Also avoids UB issues with isdigit() sign extension when // char is signed. int sdp_is_ascii_digit(constchar c) { return'0' <= c && c <= '9';
}
/* * next_token * * copy token param with chars from str until null, cr, lf, or one of the delimiters is found. * delimiters at the beginning will be skipped. * The pointer *string_of_tokens is moved forward to the next token on sucess. *
*/ static sdp_result_e next_token(constchar **string_of_tokens, char *token, unsigned token_max_len, constchar *delim)
{ int flag2moveon = 0; constchar *str; constchar *token_end; constchar *next_delim;
/* set the string of tokens to the next token */
*string_of_tokens = str;
return SDP_SUCCESS;
}
/* * verify_sdescriptions_mki * * Verifies the syntax of the MKI parameter. * * mki = mki-value ":" mki-length * mki-value = 1*DIGIT * mki-length = 1*3DIGIT ; range 1..128 * * Inputs: * buf - ptr to start of MKI string assumes NULL * terminated string * mkiValue - buffer to store the MKI value, assumes calling * function has provided memory for this. * mkiLen - integer to store the MKI length * * Outputs: * Returns TRUE if syntax is correct and stores the * MKI value in mkiVal and stores the length in mkiLen. * Returns FALSE otherwise.
*/
while (*ptr) { if (*ptr == '^') { if (tokenFound) { /* make sure we don't have multiple ^ */ returnFALSE;
} else {
tokenFound = TRUE; /* Lifetime is in power of 2 format, make sure first and second * chars are 2^
*/
/* Make sure if the format is 2^ that there is a number after the ^. */ if (tokenFound) { if (strlen(buf) <= 2) { returnFALSE;
}
}
returnTRUE;
}
/* * sdp_validate_maxprate * * This function validates that the string passed in is of the form: * packet-rate = 1*DIGIT ["." 1*DIGIT]
*/
tinybool
sdp_validate_maxprate(constchar *string_parm)
{
tinybool retval = FALSE;
if (string_parm && (*string_parm)) { while (sdp_is_ascii_digit(*string_parm)) {
string_parm++;
}
if (*string_parm == '.') {
string_parm++; while (sdp_is_ascii_digit(*string_parm)) {
string_parm++;
}
}
char *sdp_findchar (constchar *ptr, char *char_list)
{ int i;
for (;*ptr != '\0'; ptr++) { for (i=0; char_list[i] != '\0'; i++) { if (*ptr == char_list[i]) { return ((char *)ptr);
}
}
} return ((char *)ptr);
}
/* Locate the next token in a line. The delim characters are passed in * as a param. The token also will not go past a new line char or the * end of the string. Skip any delimiters before the token.
*/ constchar *sdp_getnextstrtok (constchar *str, char *tokenstr, unsigned tokenstr_len, constchar *delim, sdp_result_e *result)
{ constchar *token_list = str;
if (!str || !tokenstr || !delim || !result) { if (result) {
*result = SDP_FAILURE;
} return str;
}
/* Locate the next null ("-") or numeric token in a string. The delim * characters are passed in as a param. The token also will not go past * a new line char or the end of the string. Skip any delimiters before * the token.
*/
uint32_t sdp_getnextnumtok_or_null (constchar *str, constchar **str_end, constchar *delim, tinybool *null_ind,
sdp_result_e *result)
{ constchar *token_list = str; char temp_token[SDP_MAX_STRING_LEN]; char *strtoul_end; unsignedlong numval;
/* Locate the next numeric token in a string. The delim characters are * passed in as a param. The token also will not go past a new line char * or the end of the string. Skip any delimiters before the token.
*/
uint32_t sdp_getnextnumtok (constchar *str, constchar **str_end, constchar *delim, sdp_result_e *result)
{ constchar *token_list = str; char temp_token[SDP_MAX_STRING_LEN]; char *strtoul_end; unsignedlong numval;
if (!str || !str_end || !delim || !result) { if (result) {
*result = SDP_FAILURE;
} return 0;
}
/* * SDP Crypto Utility Functions. * * First a few common definitions.
*/
/* * Constants * * crypto_string = The string used to identify the start of sensative * crypto data. * * inline_string = The string used to identify the start of key/salt * crypto data. * * star_string = The string used to overwrite sensative data. * * '*_strlen' = The length of '*_string' in bytes (not including '\0')
*/ staticconstchar crypto_string[] = "X-crypto:"; staticconstint crypto_strlen = sizeof(crypto_string) - 1; staticconstchar inline_string[] = "inline:"; staticconstint inline_strlen = sizeof(inline_string) - 1; /* 40 characters is the current maximum for a Base64 encoded key/salt */ staticconstchar star_string[] = "****************************************"; staticconstint star_strlen = sizeof(star_string) - 1;
/* * MIN_CRYPTO_STRING_SIZE_BYTES = This value defines the minimum * size of a string that could contain a key/salt. This value * is used to skip out of parsing when there is no reasonable * assumption that sensative data will be found. The general * format of a SRTP Key Salt in SDP looks like: * * X-crypto:<crypto_suite_name> inline:<master_key_salt>|| * * if <crypto_suite_name> and <master_key_salt> is at least * one character and one space is used before the "inline:", * then this translates to a size of (aligned by collumn from * the format shown above): * * 9+ 1+ 1+7+ 1+ 2 = 21 *
*/ #define MIN_CRYPTO_STRING_SIZE_BYTES 21
/* * Utility macros * * CHAR_IS_WHITESPACE = macro to determine if the passed _test_char * is whitespace. * * SKIP_WHITESPACE = Macro to advance _cptr to the next non-whitespace * character. _cptr will not be advanced past _max_cptr. * * FIND_WHITESPACE = Macro to advance _cptr until whitespace is found. * _cptr will not be advanced past _max_cptr.
*/ #define CHAR_IS_WHITESPACE(_test_char) \
((((_test_char)==' ')||((_test_char)=='\t'))?1:0)
#define SKIP_WHITESPACE(_cptr, _max_cptr) \ while ((_cptr)<=(_max_cptr)) { \ if (!CHAR_IS_WHITESPACE(*(_cptr))) break; \
(_cptr)++; \
}
#define FIND_WHITESPACE(_cptr, _max_cptr) \ while ((_cptr)<=(_max_cptr)) { \ if (CHAR_IS_WHITESPACE(*(_cptr))) break; \
(_cptr)++; \
}
/* Function: sdp_crypto_debug * Description: Check the passed buffer for sensitive data that should * not be output (such as SRTP Master Key/Salt) and output * the buffer as debug. Sensitive data will be replaced * with the '*' character(s). This function may be used * to display very large buffers so this function ensures * that buginf is not overloaded. * Parameters: buffer pointer to the message buffer to filter. * length_bytes size of message buffer in bytes. * Returns: Nothing.
*/ void sdp_crypto_debug (char *buffer, ulong length_bytes)
{ char *current, *start; char *last = buffer + length_bytes; int result;
/* * For SRTP Master Key/Salt has the form: * X-crypto:<crypto_suite_name> inline:<master_key_salt>|| * Where <master_key_salt> is the data to elide (filter).
*/ for (start=current=buffer;
current<=last-MIN_CRYPTO_STRING_SIZE_BYTES;
current++) { if ((*current == 'x') || (*current == 'X')) {
result = cpr_strncasecmp(current, crypto_string, crypto_strlen); if (!result) {
current += crypto_strlen; if (current > last) break;
/* Skip over crypto suite name */
FIND_WHITESPACE(current, last);
/* Skip over whitespace */
SKIP_WHITESPACE(current, last);
/* identify inline keyword */
result = cpr_strncasecmp(current, inline_string, inline_strlen); if (!result) { int star_count = 0;
current += inline_strlen; if (current > last) break;
sdp_dump_buffer(start, current - start);
/* Hide sensitive key/salt data */ while (current<=last) { if (*current == '|' || *current == '\n') { /* Done, print the stars */ while (star_count > star_strlen) { /* * This code is only for the case where * too much base64 data was supplied
*/
sdp_dump_buffer((char*)star_string, star_strlen);
star_count -= star_strlen;
}
sdp_dump_buffer((char*)star_string, star_count); break;
} else {
star_count++;
current++;
}
} /* Update start pointer */
start=current;
}
}
}
}
if (last > start) { /* Display remainder of buffer */
sdp_dump_buffer(start, last - start);
}
}
/* * sdp_debug_msg_filter * * DESCRIPTION * Check the passed message buffer for sensitive data that should * not be output (such as SRTP Master Key/Salt). Sensitive data * will be replaced with the '*' character(s). * * PARAMETERS * buffer: pointer to the message buffer to filter. * * length_bytes: size of message buffer in bytes. * * RETURN VALUE * The buffer modified.
*/ char * sdp_debug_msg_filter (char *buffer, ulong length_bytes)
{ char *current; char *last = buffer + length_bytes; int result;
SDP_PRINT("\n%s:%d: Eliding sensitive data from debug output",
__FILE__, __LINE__); /* * For SRTP Master Key/Salt has the form: * X-crypto:<crypto_suite_name> inline:<master_key_salt>|| * Where <master_key_salt> is the data to elide (filter).
*/ for (current=buffer;
current<=last-MIN_CRYPTO_STRING_SIZE_BYTES;
current++) { if ((*current == 'x') || (*current == 'X')) {
result = cpr_strncasecmp(current, crypto_string, crypto_strlen); if (!result) {
current += crypto_strlen; if (current > last) break;
/* Skip over crypto suite name */
FIND_WHITESPACE(current, last);
/* Skip over whitespace */
SKIP_WHITESPACE(current, last);
/* identify inline keyword */
result = cpr_strncasecmp(current, inline_string, inline_strlen); if (!result) {
current += inline_strlen; if (current > last) break;
/* Function: sdp_checkrange * Description: This checks the range of a ulong value to make sure its * within the range of 0 and 4Gig. stroul cannot be used since * for values greater greater than 4G, stroul will either wrap * around or return ULONG_MAX. * Parameters: sdp_p Pointer to the sdp structure * num The number to check the range for * u_val This variable get populated with the ulong value * if the number is within the range. * Returns: tinybool - returns TRUE if the number passed is within the * range, FALSE otherwise
*/
tinybool sdp_checkrange (sdp_t *sdp_p, char *num, ulong *u_val)
{
ulong l_val; char *endP = NULL;
*u_val = 0;
if (!num || !*num) { returnFALSE;
}
if (*num == '-') { if (sdp_p->debug_flag[SDP_DEBUG_ERRORS]) {
SDPLogError(logTag, "%s ERROR: Parameter value is a negative number: %s",
sdp_p->debug_str, num);
} returnFALSE;
}
l_val = strtoul(num, &endP, 10); if (*endP == '\0') {
if (l_val > 4294967295UL) { if (sdp_p->debug_flag[SDP_DEBUG_ERRORS]) {
SDPLogError(logTag, "%s ERROR: Parameter value: %s is greater than 4294967295",
sdp_p->debug_str, num);
} returnFALSE;
}
if (l_val == 4294967295UL) { /* * On certain platforms where ULONG_MAX is equivalent to * 4294967295, strtoul will return ULONG_MAX even if the the * value of the string is greater than 4294967295. To detect * that scenario we make an explicit check here.
*/ if (strcmp("4294967295", num)) { if (sdp_p->debug_flag[SDP_DEBUG_ERRORS]) {
SDPLogError(logTag, "%s ERROR: Parameter value: %s is greater than 4294967295",
sdp_p->debug_str, num);
} returnFALSE;
}
}
}
*u_val = l_val; returnTRUE;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.