#2091·coturn

OAuth (RFC 7635): MESSAGE-INTEGRITY uses only the first 16 bytes of the 20-byte mac_key

Author: SIPify-JHOCreated Sep 30, 2026Updated Sep 30, 2026

Related: #189 (2017) reported this truncation. A fix was written (32743e0b, "Fix OAuth HMAC key wrong size issue. #189", branch fix-oauth), but it is not in 4.18.0 nor on master, and #189 was closed in November 2022.

  • RFC 7635 §5: "the mac_key is used as the input key for the HMAC computation". §6.2: "The key length of 160 bits MUST be supported (i.e., only the 160-bit key is used by HMAC-SHA-1)."
  • With an ACCESS-TOKEN, coturn checks MESSAGE-INTEGRITY with stun_check_message_integrity_by_key_str() and SHATYPE_DEFAULT (src/apps/relay/userdb.c:503-505). The HMAC key length is then get_hmackey_size(SHATYPE_SHA1), which returns 16 (src/client/ns_turn_msg.c:1964-1975, used at 2120-2122). Responses are signed the same way (src/server/ns_turn_server.c:4374-4379 → src/client/ns_turn_msg.c:2012-2014).
  • Result: a client that follows RFC 7635 (HMAC-SHA1 over the 20-byte mac_key) gets 401 on every Allocate; and even if a request passed, the client would have to discard coturn's responses (RFC 7635 §8).
  • turnutils_uclient goes through the same code path, so the bundled client cannot see the mismatch.
  • Note: a mac_key whose last 4 bytes are zero yields the same HMAC on both sides (HMAC zero-pads short keys), which is a possible interim workaround on the authorization-server side, at 128 effective bits.
  • Suggested fix: use the full mac_key length (20 bytes for HMAC-SHA1) for OAuth sessions, both for checking requests and for signing responses.

Version: coturn 4.18.0 (tag, commit 23c6c1d3). Code references point to that tag; the same code is present on master (dd644d0a).