⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jauth.c

📁 mediastreamer2是开源的网络传输媒体流的库
💻 C
📖 第 1 页 / 共 3 页
字号:
                           pszCNonce, HA1);            pha1 = HA1;          }        version = 0;        DigestCalcResponse ((char *) pha1, pszNonce, szNonceCount, pszCNonce,                            pszQop, version, pszMethod, pszURI, HA2, Response);    } else      {        if (0 == osip_strcasecmp (Alg, "AKAv1-MD5"))          version = 1;        else          version = 2;        DigestCalcResponseAka (pszPass, pszNonce, pszCNonce,                               pszQop, pszMethod, pszURI, version, Response2);        if (ha1 && ha1[0])          {            /* Depending on algorithm=md5 */            pha1 = ha1;        } else          {            DigestCalcHA1 ("MD5", pszUser, pszRealm, Response2, pszNonce,                           pszCNonce, HA1);            pha1 = HA1;          }        DigestCalcResponse ((char *) pha1, pszNonce, szNonceCount, pszCNonce,                            pszQop, version, pszMethod, pszURI, HA2, Response);      }    OSIP_TRACE (osip_trace                (__FILE__, __LINE__, OSIP_INFO4, NULL,                 "Response in authorization |%s|\n", Response));    {      char *resp = osip_malloc (35);      if (resp == NULL)        {          osip_authorization_free (aut);          osip_free (pszNonce);          osip_free (pszCNonce);          osip_free (pszRealm);          osip_free (pszQop);          osip_free (szNonceCount);          return OSIP_NOMEM;        }      sprintf (resp, "\"%s\"", Response);      osip_authorization_set_response (aut, resp);    }    osip_free (pszNonce);    osip_free (pszCNonce);    osip_free (pszRealm);    osip_free (pszQop);    osip_free (szNonceCount);  }  *auth = aut;  return OSIP_SUCCESS;}int__eXosip_create_proxy_authorization_header (osip_proxy_authenticate_t * wa,                                            const char *rquri,                                            const char *username,                                            const char *passwd,                                            const char *ha1,                                            osip_proxy_authorization_t **                                            auth, const char *method,                                            const char *pCNonce, int iNonceCount){  osip_proxy_authorization_t *aut;  char *qop = NULL;  char *Alg = "MD5";  int version = 0;  int i;  /* make some test */  if (passwd == NULL)    return OSIP_BADPARAMETER;  if (wa == NULL)    return OSIP_BADPARAMETER;  if (wa->auth_type == NULL || (wa->nonce == NULL))    {      OSIP_TRACE (osip_trace                  (__FILE__, __LINE__, OSIP_ERROR, NULL,                   "www_authenticate header is not acceptable.\n"));      return OSIP_SYNTAXERROR;    }  if (wa->realm == NULL)    {      OSIP_TRACE (osip_trace                  (__FILE__, __LINE__, OSIP_ERROR, NULL,                   "www_authenticate header contains an empty realm: contact your admin!\n"));    }  if (0 != osip_strcasecmp ("Digest", wa->auth_type))    {      OSIP_TRACE (osip_trace                  (__FILE__, __LINE__, OSIP_ERROR, NULL,                   "Authentication method not supported. (Digest only).\n"));      return OSIP_UNDEFINED_ERROR;    }  /* "MD5" is invalid, but some servers use it. */  if (wa->algorithm != NULL)    {      if (0 == osip_strcasecmp ("MD5", wa->algorithm)          || 0 == osip_strcasecmp ("\"MD5\"", wa->algorithm))        {      } else if (0 == osip_strcasecmp ("AKAv1-MD5", wa->algorithm)                 || 0 == osip_strcasecmp ("\"AKAv1-MD5\"", wa->algorithm))        {          Alg = "AKAv1-MD5";      } else if (0 == osip_strcasecmp ("AKAv2-MD5", wa->algorithm)                 || 0 == osip_strcasecmp ("\"AKAv2-MD5\"", wa->algorithm))        {          Alg = "AKAv2-MD5";      } else        {          OSIP_TRACE (osip_trace                      (__FILE__, __LINE__, OSIP_ERROR, NULL,                       "Authentication method not supported. (MD5, AKAv1-MD5, AKAv2-MD5)\n"));          return OSIP_UNDEFINED_ERROR;        }    }  i = osip_proxy_authorization_init (&aut);  if (i != 0)    {      OSIP_TRACE (osip_trace                  (__FILE__, __LINE__, OSIP_ERROR, NULL,                   "allocation with authorization_init failed.\n"));      return i;    }  /* just copy some feilds from response to new request */  osip_proxy_authorization_set_auth_type (aut, osip_strdup ("Digest"));  osip_proxy_authorization_set_realm (aut,                                      osip_strdup                                      (osip_proxy_authenticate_get_realm (wa)));  osip_proxy_authorization_set_nonce (aut,                                      osip_strdup                                      (osip_proxy_authenticate_get_nonce (wa)));  if (osip_proxy_authenticate_get_opaque (wa) != NULL)    osip_proxy_authorization_set_opaque (aut,                                         osip_strdup                                         (osip_proxy_authenticate_get_opaque                                          (wa)));  /* copy the username field in new request */  aut->username = osip_malloc (strlen (username) + 3);  if (aut->username == NULL)    {      osip_authorization_free (aut);      return OSIP_NOMEM;    }  sprintf (aut->username, "\"%s\"", username);  {    char *tmp = osip_malloc (strlen (rquri) + 3);    if (tmp == NULL)      {        osip_authorization_free (aut);        return OSIP_NOMEM;      }    sprintf (tmp, "\"%s\"", rquri);    osip_proxy_authorization_set_uri (aut, tmp);  }  osip_proxy_authorization_set_algorithm (aut, osip_strdup (Alg));  qop = osip_www_authenticate_get_qop_options (wa);  if (qop == NULL || qop[0] == '\0' || strlen (qop) < 4)    qop = NULL;  {    char *pszNonce = NULL;    char *pszCNonce = NULL;    const char *pszUser = username;    char *pszRealm = NULL;    const char *pszPass = NULL;    char *szNonceCount = NULL;    char *pszMethod = (char *) method;  /* previous_answer->cseq->method; */    char *pszQop = NULL;    const char *pszURI = rquri;    HASHHEX HA1;    HASHHEX HA2 = "";    HASHHEX Response;    RESHEXAKA2 Response2;    const char *pha1 = NULL;    if (osip_proxy_authorization_get_realm (aut) == NULL)      {        pszRealm = osip_strdup ("");    } else      {        pszRealm =          osip_strdup_without_quote (osip_proxy_authorization_get_realm (aut));      }    pszPass = passwd;    if (osip_www_authenticate_get_nonce (wa) == NULL)      return OSIP_SYNTAXERROR;    pszNonce = osip_strdup_without_quote (osip_www_authenticate_get_nonce (wa));    if (qop != NULL)      {        /* only accept qop="auth" */        pszQop = osip_strdup ("auth");        if (pszQop == NULL)          {            osip_authorization_free (aut);            osip_free (pszNonce);            osip_free (pszRealm);            return OSIP_NOMEM;          }        szNonceCount = osip_malloc (10);        if (szNonceCount == NULL)          {            osip_authorization_free (aut);            osip_free (pszNonce);            osip_free (pszRealm);            osip_free (pszQop);            return OSIP_NOMEM;          }        snprintf (szNonceCount, 9, "%.8i", iNonceCount);        pszCNonce = osip_strdup (pCNonce);        if (pszCNonce == NULL)          {            osip_authorization_free (aut);            osip_free (pszNonce);            osip_free (pszRealm);            osip_free (pszQop);            osip_free (szNonceCount);            return OSIP_NOMEM;          }        osip_proxy_authorization_set_message_qop (aut, osip_strdup ("auth"));        osip_proxy_authorization_set_nonce_count (aut, osip_strdup (szNonceCount));        {          char *tmp = osip_malloc (strlen (pszCNonce) + 3);          if (tmp == NULL)            {              osip_authorization_free (aut);              osip_free (pszNonce);              osip_free (pszCNonce);              osip_free (pszRealm);              osip_free (pszQop);              osip_free (szNonceCount);              return OSIP_NOMEM;            }          sprintf (tmp, "\"%s\"", pszCNonce);          osip_proxy_authorization_set_cnonce (aut, tmp);        }      }    if (0 == osip_strcasecmp (Alg, "MD5"))      {        if (ha1 && ha1[0])          {            /* Depending on algorithm=md5 */            pha1 = ha1;        } else          {            DigestCalcHA1 ("MD5", pszUser, pszRealm, pszPass, pszNonce,                           pszCNonce, HA1);            pha1 = HA1;          }        version = 0;        DigestCalcResponse ((char *) pha1, pszNonce, szNonceCount, pszCNonce,                            pszQop, version, pszMethod, pszURI, HA2, Response);    } else      {        if (0 == osip_strcasecmp (Alg, "AKAv1-MD5"))          version = 1;        else          version = 2;        DigestCalcResponseAka (pszPass, pszNonce, pszCNonce, pszQop, pszMethod,                               pszURI, version, Response2);        if (ha1 && ha1[0])          {            /* Depending on algorithm=md5 */            pha1 = ha1;        } else          {            DigestCalcHA1 ("MD5", pszUser, pszRealm, Response2, pszNonce,                           pszCNonce, HA1);            pha1 = HA1;          }        DigestCalcResponse ((char *) pha1, pszNonce, szNonceCount, pszCNonce,                            pszQop, version, pszMethod, pszURI, HA2, Response);      }    OSIP_TRACE (osip_trace                (__FILE__, __LINE__, OSIP_INFO4, NULL,                 "Response in proxy_authorization |%s|\n", Response));    {      char *resp = osip_malloc (35);      if (resp == NULL)        {          osip_authorization_free (aut);          osip_free (pszNonce);          osip_free (pszCNonce);          osip_free (pszRealm);          osip_free (pszQop);          osip_free (szNonceCount);          return OSIP_NOMEM;        }      sprintf (resp, "\"%s\"", Response);      osip_proxy_authorization_set_response (aut, resp);    }    osip_free (pszNonce);    osip_free (pszCNonce);    osip_free (pszRealm);    osip_free (pszQop);    osip_free (szNonceCount);  }  *auth = aut;  return OSIP_SUCCESS;}int_eXosip_store_nonce (const char *call_id, osip_proxy_authenticate_t * wa,                     int answer_code){  struct eXosip_http_auth *http_auth;  int pos;  /* update entries with same call_id */  for (pos = 0; pos < MAX_EXOSIP_HTTP_AUTH; pos++)    {      http_auth = &eXosip.http_auths[pos];      if (http_auth->pszCallId[0] == '\0')        continue;      if (osip_strcasecmp (http_auth->pszCallId, call_id) == 0          && ((http_auth->wa->realm == NULL && wa->realm == NULL)              || (http_auth->wa->realm != NULL                  && wa->realm != NULL                  && osip_strcasecmp (http_auth->wa->realm, wa->realm) == 0)))        {          osip_proxy_authenticate_free (http_auth->wa);          http_auth->wa = NULL;          osip_proxy_authenticate_clone (wa, &(http_auth->wa));          http_auth->iNonceCount = 1;          if (http_auth->wa == NULL)            memset (http_auth, 0, sizeof (struct eXosip_http_auth));          return OSIP_SUCCESS;        }    }  /* not found */  for (pos = 0; pos < MAX_EXOSIP_HTTP_AUTH; pos++)    {      http_auth = &eXosip.http_auths[pos];      if (http_auth->pszCallId[0] == '\0')        {          snprintf (http_auth->pszCallId, sizeof (http_auth->pszCallId), call_id);          snprintf (http_auth->pszCNonce, sizeof (http_auth->pszCNonce),                    "0a4f113b");          http_auth->iNonceCount = 1;          osip_proxy_authenticate_clone (wa, &(http_auth->wa));          http_auth->answer_code = answer_code;          if (http_auth->wa == NULL)            memset (http_auth, 0, sizeof (struct eXosip_http_auth));          return OSIP_SUCCESS;        }    }  OSIP_TRACE (osip_trace              (__FILE__, __LINE__, OSIP_ERROR, NULL,               "Compile with higher MAX_EXOSIP_HTTP_AUTH value (current=%i)\n",               MAX_EXOSIP_HTTP_AUTH));  return OSIP_UNDEFINED_ERROR;}int_eXosip_delete_nonce (const char *call_id){  struct eXosip_http_auth *http_auth;  int pos;  /* update entries with same call_id */  for (pos = 0; pos < MAX_EXOSIP_HTTP_AUTH; pos++)    {      http_auth = &eXosip.http_auths[pos];      if (http_auth->pszCallId[0] == '\0')        continue;      if (osip_strcasecmp (http_auth->pszCallId, call_id) == 0)        {          osip_proxy_authenticate_free (http_auth->wa);          memset (http_auth, 0, sizeof (struct eXosip_http_auth));          return OSIP_SUCCESS;        }    }  return OSIP_NOTFOUND;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -