17 #ifndef SAMPLE_STUN_AUTH_PROVIDER 18 #define SAMPLE_STUN_AUTH_PROVIDER 23 sampleauthprovider.h and sampleauthprovider.cpp
25 The stun library code knows how to generate and validate message integrity attributes
26 inside stun attributes. But it relies on an implemented
"auth provider" to actually
27 confirm a username and supply the password key.
29 It is out of the scope of
this release to implement an authentication provider that
30 will work
for everyone. One deployment may store usernames and passwords in a database.
31 Other deployments may rely on a ticketing service library.
33 RFC 5389 specifies two authentication mechanisms
for STUN. It is recommended
34 that you read it before deciding how timplement
36 "Short term credentials" is simply the
case where a stun binding request
37 sent from client to server contains a message integrity attribute. The message
38 integrity attribute is simply an attribute that contins an HMAC-SHA1 hash of
39 the stun msesage itself. The stun message should also contain a username attribute.
40 The
'key' field of the HMAC operation is a
private password associated with the
41 username in the binding request.
43 "Long term credentials" is similar to
short term credentials but involves a challenge
44 response phase to prevent replay attacks. This is the recommended mechanism
for 47 We can also support
"ticket based credentials". This is not a mechanism specified
48 by the STUN RFC, but has been known to work in various scenarios. The username
49 and/or realm fields are overloaded to represent a
"ticket" signed by an external
50 entity. The auth provider knows how to validate the ticket.
52 We can also implement
"legacy password" authentication. This is simply the password
53 (with or without a username and realm) embedded in the clear in the stun binding
54 request. Not recommended unless the transport type is TLS.
56 Implementing authentication is simply implementing a
class that
implements 58 is called for each incoming Stun Message. It takes one input parameter pointer
59 to a struct instance of type
AuthAttributes) and one "out" param which is a struct
60 for handing back authentication tokens back to the server.
62 HRESULT DoAuthCheck( AuthAttributes* pAuthAttributes, AuthResponse* pResponse);
64 The
AuthAttributes struct representes various attribute values received in a STUN
65 binding request. They are outlined as follows:
71 bool fMessageIntegrityPresent;
73 The implementation of DoAuthCheck needs to decide how to handle the
AuthAttributes 74 and then pass back a series of results and codes through the provided
AuthResponse 77 The
AuthResponse parameter is for indicating to the server how to authenticate a
78 message integrity attribute. The implementation needs to set the following fieds
82 responseType must be set to one of the following values
84 additional validation on the message integrity field is needed
87 as lone as the message integrity attribute in the stun request
88 is valid with respect to szPassword (and szUserName and szNonce if in long term cred mode)
89 If the message integrity attribute is deemed invalid, then
90 a 401 is sent back instead of a binding response.
96 cred mode, this will also send back the szNonce and szRealm fields
100 attribute valid has expired
103 Is either set to AuthShortTerm or AuthLongTerm to indicate to the server
104 how to generate and validate message integrity fields
108 server will not send this back as an attribute. Instead it is used
109 for validating and generating message integrity attributes in the
113 Ignored if using short term credentials. Otherwise, it should be
114 the realm field used for generating and validating message integrity fields.
115 It will almost always need to be sent back in error responses to
119 A new nonce for subsequent requests in the event this request can not
122 DoAuthCheck should return
S_OK unless a fatal error occurs. If DoAuthCheck returns
126 To have the server host an instance of an
IStunAuth implementation, modify
128 _spAuth as appropriate.
151 void HmacToString(uint8_t* hmacvalue,
char* pszResult);
152 HRESULT CreateNonce(
char* pszNonce);
153 HRESULT ValidateNonce(
char* pszNonce);
#define ADDREF_AND_RELEASE_IMPL()
HRESULT Initialize(const CStunServerConfig &config)
const uint32_t MAX_STUN_AUTH_STRING_SIZE
virtual HRESULT DoAuthCheck(AuthAttributes *pAuthAttributes, AuthResponse *pResponse)
HRESULT Initialize(const CStunServerConfig &config)