Преглед на файлове

fixes:
- error text mesagges
- checking of optional attributes
- added some other debug messages

Vladimir Marek преди 18 години
родител
ревизия
b286c89e8e
променени са 2 файла, в които са добавени 32 реда и са изтрити 19 реда
  1. 18 5
      ser_stun.c
  2. 14 14
      ser_stun.h

+ 18 - 5
ser_stun.c

@@ -133,8 +133,6 @@ int stun_process_msg(char* buf, unsigned len, struct receive_info* ri)
 #ifdef EXTRA_DEBUG	
 	struct ip_addr ip;
 	su2ip_addr(&ip, &dst.to);
-	char *ipp = ip_addr2a(&ip);
-	int porttt = su_getport(&dst.to);
 	LOG(L_DBG, "DEBUG: stun_process_msg: decoded request from (%s:%d)\n", ip_addr2a(&ip), 
 		su_getport(&dst.to));
 #endif
@@ -276,7 +274,7 @@ int stun_parse_body(
 		}
 		
 		/* check if the attribute is known to the server */
-		switch (htons(attr.type)) {			
+		switch (ntohs(attr.type)) {			
 			case REALM_ATTR:
 			case NONCE_ATTR:
 			case MAPPED_ADDRESS_ATTR:
@@ -289,6 +287,9 @@ int stun_parse_body(
 			case CHANGE_REQUEST_ATTR:
 			case CHANGED_ADDRESS_ATTR:
 				padded_len = ntohs(attr.len);
+#ifdef EXTRA_DEBUG
+				LOG(L_DBG, "DEBUG: stun_parse_body: known attributes\n");
+#endif
 				break;
 			
 			/* following attributes must be padded to 4 bytes */
@@ -298,6 +299,9 @@ int stun_parse_body(
 			case UNKNOWN_ATTRIBUTES_ATTR:
 			case SERVER_ATTR:
 				padded_len = PADDED_TO_FOUR(ntohs(attr.len));
+#ifdef EXTRA_DEBUG
+				LOG(L_DBG, "DEBUG: stun_parse_body: padded to four\n");
+#endif
 				break;
 
 			/* MESSAGE_INTEGRITY must be padded to sixty four bytes*/
@@ -347,9 +351,13 @@ int stun_parse_body(
 				 * let see if it's necessary to generate error response 
 				 */
 #ifdef EXTRA_DEBUG
-				LOG(L_DBG, "DEBUG: stun_parse_body: unknown attribute found\n");
+				LOG(L_DBG, "DEBUG: low endian: attr - 0x%x   const - 0x%x\n", ntohs(attr.type), MANDATORY_ATTR);
+		    LOG(L_DBG, "DEBUG: big endian: attr - 0x%x   const - 0x%x\n", attr.type, htons(MANDATORY_ATTR));
 #endif
-				if (attr.type <= htons(MANDATORY_ATTR)) {
+				if (ntohs(attr.type) <= MANDATORY_ATTR) {
+#ifdef EXTRA_DEBUG
+				LOG(L_DBG, "DEBUG: stun_parse_body: mandatory unknown attribute found - 0x%x\n", ntohs(attr.type));
+#endif		
 					tmp_unknown = stun_alloc_unknown_attr(attr.type);
 					if (tmp_unknown == NULL) {
 						return FATAL_ERROR;
@@ -362,6 +370,11 @@ int stun_parse_body(
 						body = body->next;
 					}
 				}
+#ifdef EXTRA_DEBUG
+        else {
+				  LOG(L_DBG, "DEBUG: stun_parse_body: optional unknown attribute found - 0x%x\n", ntohs(attr.type));
+        }
+#endif
 				padded_len = ntohs(attr.len);
 				break;
 		}

+ 14 - 14
ser_stun.h

@@ -94,20 +94,20 @@ typedef unsigned long	ULONG_T;
 #define SERVER_ERROR_ERR		500
 #define GLOBAL_FAILURE_ERR		600
 
-#define TRY_ALTERNATE_TXT 		"The client should contact an alternate server for this request."
-#define BAD_REQUEST_TXT			"The request was malformed. The client should not retry the request without modification from the previous attempt."
-#define UNAUTHORIZED_TXT		"The request did not contain a MESSAGE-INTEGRITY attribute."
-#define UNKNOWN_ATTRIBUTE_TXT	"The server did not understand a mandatory attribute in the request."
-#define STALE_CREDENTIALS_TXT	"The request did contain a MESSAGE-INTEGRITY attribute, but it used a shared secret that has expired. The client should obtain a new shared secret and try again."
-#define INTEGRITY_CHECK_TXT		"The request contained a MESSAGE-INTEGRITY attribute, but the HMAC failed verification. This could be a sign of a potential attack, or client implementation error."
-#define MISSING_USERNAME_TXT	"The request contained a MESSAGE-INTEGRITY attribute, but not a USERNAME attribute.  Both USERNAME and MESSAGE-INTEGRITY must be present for integrity checks."
-#define USE_TLS_TXT				"The Shared Secret request has to be sent over TLS, but was not received over TLS."
-#define MISSING_REALM_TXT		"The REALM attribute was not present in the request."
-#define MISSING_NONCE_TXT		"The NONCE attribute was not present in the request."
-#define UNKNOWN_USERNAME_TXT	"The USERNAME supplied in the request is not known or is not known to the server."
-#define STALE_NONCE_TXT			"The NONCE attribute was present in the request but wasn't valid."
-#define SERVER_ERROR_TXT		"The server has suffered a temporary error. The client should try again."
-#define GLOBAL_FAILURE_TXT		"The server is refusing to fulfill the request. The client should not retry."
+#define TRY_ALTERNATE_TXT      "Try Alternate"
+#define BAD_REQUEST_TXT        "Bad Request"
+#define UNAUTHORIZED_TXT       "Unauthorized"
+#define UNKNOWN_ATTRIBUTE_TXT  "Unknown Attribute"
+#define STALE_CREDENTIALS_TXT  "Stale Credentials"
+#define INTEGRITY_CHECK_TXT    "Integrity Check Failure"
+#define MISSING_USERNAME_TXT   "Missing Username"
+#define USE_TLS_TXT            "Use TLS"
+#define MISSING_REALM_TXT      "Missing Realm"
+#define MISSING_NONCE_TXT      "Missing Nonce"
+#define UNKNOWN_USERNAME_TXT   "Unknown Username"
+#define STALE_NONCE_TXT        "Stale Nonce"
+#define SERVER_ERROR_TXT       "Server Error"
+#define GLOBAL_FAILURE_TXT     "Global Failure"
 
 
 /* other stuff */