Commit db89c760 authored by Kai Vehmanen's avatar Kai Vehmanen

Updated constant definitions to match the latest ICE/STUN/TURN drafts, part 2....

Updated constant definitions to match the latest ICE/STUN/TURN drafts, part 2. Modified code to use the new definitions.

darcs-hash:20070717182227-77cd4-8bbe479ce6c2ed604b7fb6d5d32cfe8e66b2bf64.gz
parent 46e17a40
...@@ -102,17 +102,19 @@ stun_binding_reply (uint8_t *buf, size_t *restrict plen, const uint8_t *msg, ...@@ -102,17 +102,19 @@ stun_binding_reply (uint8_t *buf, size_t *restrict plen, const uint8_t *msg,
if (!stun_has_integrity (msg)) if (!stun_has_integrity (msg))
{ {
DBG (" Message Authentication Code missing.\n"); DBG (" Message Authentication Code missing.\n");
err (STUN_UNAUTHORIZED); err (STUN_BAD_REQUEST);
return EPERM; return EPERM;
} }
if (!stun_present (msg, STUN_USERNAME)) if (!stun_present (msg, STUN_USERNAME))
{ {
DBG (" Username missing.\n"); DBG (" Username missing.\n");
err (STUN_MISSING_USERNAME); err (STUN_BAD_REQUEST);
return EPERM; return EPERM;
} }
/* FIXME: verify USERNAME, return 401 if wrong */
/* NOTE: should check in that order: /* NOTE: should check in that order:
* - missing realm * - missing realm
* - missing nonce * - missing nonce
...@@ -167,7 +169,6 @@ stun_binding_reply (uint8_t *buf, size_t *restrict plen, const uint8_t *msg, ...@@ -167,7 +169,6 @@ stun_binding_reply (uint8_t *buf, size_t *restrict plen, const uint8_t *msg,
return 0; return 0;
failure: failure:
err (STUN_GLOBAL_FAILURE);
return val; return val;
} }
#undef err #undef err
......
...@@ -92,10 +92,18 @@ typedef enum ...@@ -92,10 +92,18 @@ typedef enum
{ {
STUN_BINDING=0x001, /* RFC3489bis-07 */ STUN_BINDING=0x001, /* RFC3489bis-07 */
STUN_OLD_SHARED_SECRET=0x002, /* old RFC3489 */ STUN_OLD_SHARED_SECRET=0x002, /* old RFC3489 */
STUN_ALLOCATE=0x003 /* ?? TURN */ STUN_ALLOCATE=0x003, /* TURN-04 */
STUN_SET_ACTIVE_DST=0x004, /* TURN-04 */
STUN_CONNECT=0x005, /* TURN-04 */
STUN_IND_SEND=0x006, /* TURN-04 */
STUN_IND_DATA=0x007, /* TURN-04 */
STUN_IND_CONNECT_STATUS=0x008 /* TURN-04 */
} stun_method_t; } stun_method_t;
/* Attribute types */ /**
* STUN attribute types
* Should be in sync with stun_is_unknown()
*/
typedef enum typedef enum
{ {
/* Mandatory attributes */ /* Mandatory attributes */
...@@ -110,15 +118,24 @@ typedef enum ...@@ -110,15 +118,24 @@ typedef enum
STUN_ERROR_CODE=0x0009, /* RFC3489bis-07 */ STUN_ERROR_CODE=0x0009, /* RFC3489bis-07 */
STUN_UNKNOWN_ATTRIBUTES=0x000A, /* RFC3489bis-07 */ STUN_UNKNOWN_ATTRIBUTES=0x000A, /* RFC3489bis-07 */
STUN_OLD_REFLECTED_FROM=0x000B, /* old RFC3489 */ STUN_OLD_REFLECTED_FROM=0x000B, /* old RFC3489 */
STUN_LIFETIME=0x000D, /* TURN-04 */
STUN_BANDWIDTH=0x0010, /* TURN-04 */
STUN_REMOTE_ADDRESS=0x0012, /* TURN-04 */
STUN_DATA=0x0013, /* TURN-04 */
STUN_REALM=0x0014, /* RFC3489bis-07 */ STUN_REALM=0x0014, /* RFC3489bis-07 */
STUN_NONCE=0x0015, /* RFC3489bis-07 */ STUN_NONCE=0x0015, /* RFC3489bis-07 */
STUN_RELAY_ADDRESS=0x0016, /* TURN-04 */
STUN_REQUESTED_ADDRESS_TYPE=0x0017, /* TURN-IPv6-03 */ STUN_REQUESTED_ADDRESS_TYPE=0x0017, /* TURN-IPv6-03 */
STUN_REQUESTED_PORT_PROPS=0x0018, /* TURN-04 */
STUN_REQUESTED_TRANSPORT=0x0019, /* TURN-04 */
STUN_XOR_MAPPED_ADDRESS=0x0020, /* RFC3489bis-07 */ STUN_XOR_MAPPED_ADDRESS=0x0020, /* RFC3489bis-07 */
STUN_TIMER_VAL=0x0021, /* TURN-04 */
STUN_PRIORITY=0x0024, /* ICE-15 */ STUN_REQUESTED_IP=0x0022, /* TURN-04 */
STUN_USE_CANDIDATE=0x0025, /* ICE-15 */ STUN_CONNECT_STAT=0x0023, /* TURN-04 */
STUN_PRIORITY=0x0024, /* ICE-17 */
STUN_USE_CANDIDATE=0x0025, /* ICE-17 */
/* Optional attributes */ /* Optional attributes */
STUN_SERVER=0x8022, /* RFC3489bis-07 */ STUN_SERVER=0x8022, /* RFC3489bis-07 */
...@@ -126,8 +143,8 @@ typedef enum ...@@ -126,8 +143,8 @@ typedef enum
STUN_REFRESH_INTERVAL=0x8024, /* RFC3489bis-07 */ STUN_REFRESH_INTERVAL=0x8024, /* RFC3489bis-07 */
STUN_FINGERPRINT=0x8028, /* RFC3489bis-07 */ STUN_FINGERPRINT=0x8028, /* RFC3489bis-07 */
STUN_ICE_CONTROLLED=0x8029, /* ICE-15 */ STUN_ICE_CONTROLLED=0x8029, /* ICE-17 */
STUN_ICE_CONTROLLING=0x802A /* ICE-15 */ STUN_ICE_CONTROLLING=0x802A /* ICE-17 */
} stun_attr_type_t; } stun_attr_type_t;
...@@ -138,24 +155,31 @@ static inline int stun_optional (stun_attr_type_t t) ...@@ -138,24 +155,31 @@ static inline int stun_optional (stun_attr_type_t t)
typedef uint8_t stun_transid_t[12]; typedef uint8_t stun_transid_t[12];
/* Error codes */ /**
* STUN error codes
* Should be in sync with stun_strerror()
*/
/* FIXME: consistent integrity check vs error handling ??? */
typedef enum typedef enum
{ {
STUN_TRY_ALTERNATE=300, STUN_TRY_ALTERNATE=300, /* RFC3489bis-07 */
STUN_BAD_REQUEST=400, STUN_BAD_REQUEST=400, /* RFC3489bis-07 */
STUN_UNAUTHORIZED=401, STUN_UNAUTHORIZED=401, /* RFC3489bis-07 */
STUN_UNKNOWN_ATTRIBUTE=420, STUN_UNKNOWN_ATTRIBUTE=420, /* RFC3489bis-07 */
STUN_STALE_CREDENTIALS=430, STUN_INTEGRITY_CHECK_FAILURE=431, /* FIXME: missing from RFC3489-07! */
STUN_INTEGRITY_CHECK_FAILURE=431, STUN_NO_BINDING=437, /* TURN-04 */
STUN_MISSING_USERNAME=432, STUN_STALE_NONCE=438, /* RFC3489bis-07 */
STUN_USE_TLS=433, STUN_ACT_DST_ALREADY=439, /* TURN-04 */
STUN_MISSING_REALM=434, STUN_UNSUPP_TRANSPORT=442, /* TURN-04 */
STUN_MISSING_NONCE=435, STUN_INVALID_IP=443, /* TURN-04 */
STUN_UNKNOWN_USERNAME=436, STUN_INVALID_PORT=444, /* TURN-04 */
STUN_STALE_NONCE=438, STUN_OP_TCP_ONLY=445, /* TURN-04 */
STUN_ROLE_CONFLICT=487, STUN_CONN_ALREADY=446, /* TURN-04 */
STUN_SERVER_ERROR=500, STUN_ALLOC_OVER_QUOTA=486, /* TURN-04 */
STUN_GLOBAL_FAILURE=600 STUN_ROLE_CONFLICT=487, /* ICE-17 */
STUN_SERVER_ERROR=500, /* RFC3489bis-07 */
STUN_SERVER_CAPACITY=507, /* TURN-04 */
STUN_GLOBAL_FAILURE=600 // FIXME
} stun_error_t; } stun_error_t;
......
...@@ -622,11 +622,22 @@ bool stun_is_unknown (uint16_t type) ...@@ -622,11 +622,22 @@ bool stun_is_unknown (uint16_t type)
case STUN_ERROR_CODE: case STUN_ERROR_CODE:
case STUN_UNKNOWN_ATTRIBUTES: case STUN_UNKNOWN_ATTRIBUTES:
case STUN_OLD_REFLECTED_FROM: case STUN_OLD_REFLECTED_FROM:
case STUN_LIFETIME:
case STUN_BANDWIDTH:
case STUN_REMOTE_ADDRESS:
case STUN_DATA:
case STUN_REALM: case STUN_REALM:
case STUN_NONCE: case STUN_NONCE:
case STUN_RELAY_ADDRESS:
case STUN_REQUESTED_ADDRESS_TYPE:
case STUN_REQUESTED_PORT_PROPS:
case STUN_REQUESTED_TRANSPORT:
case STUN_XOR_MAPPED_ADDRESS: case STUN_XOR_MAPPED_ADDRESS:
case STUN_TIMER_VAL:
case STUN_REQUESTED_IP:
case STUN_CONNECT_STAT:
case STUN_PRIORITY: case STUN_PRIORITY:
case STUN_USE_CANDIDATE: case STUN_USE_CANDIDATE:
......
...@@ -232,17 +232,29 @@ static const char *stun_strerror (stun_error_t code) ...@@ -232,17 +232,29 @@ static const char *stun_strerror (stun_error_t code)
{ STUN_BAD_REQUEST, "Bad request" }, { STUN_BAD_REQUEST, "Bad request" },
{ STUN_UNAUTHORIZED, "Authorization required" }, { STUN_UNAUTHORIZED, "Authorization required" },
{ STUN_UNKNOWN_ATTRIBUTE, "Unknown attribute" }, { STUN_UNKNOWN_ATTRIBUTE, "Unknown attribute" },
/*
{ STUN_STALE_CREDENTIALS, "Authentication expired" }, { STUN_STALE_CREDENTIALS, "Authentication expired" },
*/
{ STUN_INTEGRITY_CHECK_FAILURE, "Incorrect username/password" }, { STUN_INTEGRITY_CHECK_FAILURE, "Incorrect username/password" },
/*
{ STUN_MISSING_USERNAME, "Username required" }, { STUN_MISSING_USERNAME, "Username required" },
{ STUN_USE_TLS, "Secure connection required" }, { STUN_USE_TLS, "Secure connection required" },
{ STUN_MISSING_REALM, "Authentication domain required" }, { STUN_MISSING_REALM, "Authentication domain required" },
{ STUN_MISSING_NONCE, "Authentication token missing" }, { STUN_MISSING_NONCE, "Authentication token missing" },
{ STUN_UNKNOWN_USERNAME, "Unknown user name" }, { STUN_UNKNOWN_USERNAME, "Unknown user name" },
*/
{ STUN_NO_BINDING, "Session expired" },
{ STUN_STALE_NONCE, "Authentication token expired" }, { STUN_STALE_NONCE, "Authentication token expired" },
{ STUN_ACT_DST_ALREADY, "Changing remote peer forbidden" },
{ STUN_UNSUPP_TRANSPORT, "Unknown transport protocol" },
{ STUN_INVALID_IP, "Address unavailable" },
{ STUN_INVALID_PORT, "Port unavailable" },
{ STUN_OP_TCP_ONLY, "Invalid operation" },
{ STUN_CONN_ALREADY, "Connection already established" },
{ STUN_ALLOC_OVER_QUOTA, "Quota reached" },
{ STUN_ROLE_CONFLICT, "Role conflict" }, { STUN_ROLE_CONFLICT, "Role conflict" },
{ STUN_SERVER_ERROR, "Temporary server error" }, { STUN_SERVER_ERROR, "Temporary server error" },
{ STUN_GLOBAL_FAILURE, "Unrecoverable failure" }, { STUN_SERVER_CAPACITY, "Temporary server congestion" },
{ 0, "" } { 0, "" }
}; };
unsigned i; unsigned i;
......
...@@ -150,7 +150,6 @@ int main (void) ...@@ -150,7 +150,6 @@ int main (void)
val = stun_bind_reply (buf, &len, buf, val = stun_bind_reply (buf, &len, buf,
(struct sockaddr *)&ip4, sizeof (ip4), false); (struct sockaddr *)&ip4, sizeof (ip4), false);
assert (val == EAFNOSUPPORT); assert (val == EAFNOSUPPORT);
assert (len > 0);
return 0; return 0;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment