18 #include <openssl/hmac.h> 26 static const char*
c_szPrivateKey =
"Change this string if you are going to use this code";
30 static HRESULT LookupPassword(
bool fWithRealm,
const char* pszUserName,
const char* pszRealm,
char* pszPassword)
32 const char* users[] = {
"bruce",
"steve",
"nicko",
"dave",
"adrian"};
33 const char* passwords[] = {
"AcesHigh",
"2MinToMid",
"fearofthedark!",
"#ofthebeast",
"Run2TheHills" };
37 if ((pszRealm == NULL) || (strcmp(pszRealm,
c_szRealm)))
43 if (pszUserName == NULL)
48 for (
size_t index = 0; index <
ARRAYSIZE(users); index++)
50 if (strcmp(pszUserName, users[index]))
55 strcpy(pszPassword, passwords[index]);
107 CreateNonce(pResponse->
szNonce);
147 sprintf(pszResult,
"%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x",
148 hmacresult[0], hmacresult[1], hmacresult[2], hmacresult[3], hmacresult[4],
149 hmacresult[5], hmacresult[6], hmacresult[7], hmacresult[8], hmacresult[9],
150 hmacresult[10], hmacresult[11], hmacresult[12], hmacresult[13], hmacresult[14],
151 hmacresult[15], hmacresult[16], hmacresult[17], hmacresult[18], hmacresult[19]);
163 time_t thetime = time(NULL);
164 uint8_t hmacresult[20] = {};
166 char szTime[
sizeof(time_t)*4];
167 unsigned int len =
ARRAYSIZE(hmacresult);
169 sprintf(szTime,
"%u:", (
unsigned int)thetime);
173 HmacToString(hmacresult, szHMAC);
175 strcpy(pszNonce, szTime);
176 strcat(pszNonce, szHMAC);
183 time_t thecurrenttime = time(NULL);
185 uint8_t hmacresult[20] = {};
188 char *pRightHalf = NULL;
190 unsigned int len =
ARRAYSIZE(hmacresult);
192 strncpy(szNonce, pszNonce,
ARRAYSIZE(szNonce));
195 pRightHalf = strstr(szNonce,
":");
197 if (pRightHalf == NULL)
204 thetime = atoi(szNonce);
206 diff = thecurrenttime - thetime;
207 if (((thecurrenttime - thetime) > 120) || (diff < 0))
215 HmacToString(hmacresult, szHMAC);
216 if (strcmp(szHMAC, pRightHalf))
AuthResponseType responseType
virtual HRESULT DoAuthCheck(AuthAttributes *pAuthAttributes, AuthResponse *pResponse)
char szUser[MAX_STUN_AUTH_STRING_SIZE+1]
void HmacToString(uint8_t *hmacvalue, char *pszResult)
HRESULT CreateNonce(char *pszNonce)
char szNonce[MAX_STUN_AUTH_STRING_SIZE+1]
bool fMessageIntegrityPresent
AuthCredentialMechanism authCredMech
HRESULT ValidateNonce(char *pszNonce)
static const char * c_szPrivateKey
char szPassword[MAX_STUN_AUTH_STRING_SIZE+1]
char szNonce[MAX_STUN_AUTH_STRING_SIZE+1]
static const char * c_szRealm
static HRESULT LookupPassword(bool fWithRealm, const char *pszUserName, const char *pszRealm, char *pszPassword)
virtual HRESULT DoAuthCheck(AuthAttributes *pAuthAttributes, AuthResponse *pResponse)
char szRealm[MAX_STUN_AUTH_STRING_SIZE+1]