MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / build_auth_hf

Function build_auth_hf

modules/auth/challenge.c:72–156  ·  view source on GitHub ↗

* Create {WWW,Proxy}-Authenticate header field */

Source from the content-addressed store, hash-verified

70 * Create {WWW,Proxy}-Authenticate header field
71 */
72char *build_auth_hf(struct nonce_context *ncp, struct nonce_params *calc_np,
73 int _stale, const str_const *_realm, int* _len,
74 const str_const *alg_val, const str_const* _hf_name, const str_const *opaque)
75{
76 char *hf, *p;
77 str_const alg_param;
78 str_const qop_param = get_qop_param(calc_np->qop);
79 str_const stale_param = STR_NULL_const;
80 const str_const digest_realm = str_const_init(DIGEST_REALM);
81 const str_const nonce_param = str_const_init(DIGEST_NONCE);
82 str_const opaque_param;
83
84 if (_stale)
85 stale_param = str_const_init(STALE_PARAM);
86
87 /* length calculation */
88 *_len=_hf_name->len;
89 *_len+=digest_realm.len
90 +_realm->len
91 +nonce_param.len
92 +ncp->nonce_len
93 +1 /* '"' */
94 +stale_param.len
95 +qop_param.len
96 +CRLF_LEN ;
97
98 if (alg_val != NULL) {
99 alg_param = str_const_init(DIGEST_ALGORITHM);
100 *_len += alg_param.len + alg_val->len;
101 }
102
103 if (opaque != NULL) {
104 opaque_param = str_const_init(DIGEST_OPAQUE);
105 *_len += opaque_param.len + opaque->len + 1 /* '"' */;
106 }
107
108 p=hf=pkg_malloc(*_len+1);
109 if (!hf) {
110 LM_ERR("no pkg memory left\n");
111 goto e1;
112 }
113
114 memcpy(p, _hf_name->s, _hf_name->len); p+=_hf_name->len;
115 memcpy(p, digest_realm.s, digest_realm.len);p+=digest_realm.len;
116 memcpy(p, _realm->s, _realm->len);p+=_realm->len;
117 memcpy(p, nonce_param.s, nonce_param.len);p+=nonce_param.len;
118 if (calc_nonce(ncp, p, calc_np) != 0) {
119 LM_ERR("calc_nonce failed\n");
120 goto e2;
121 }
122 p+=ncp->nonce_len;
123 *p='"';p++;
124 if (calc_np->qop) {
125 memcpy(p, qop_param.s, qop_param.len);
126 p+=qop_param.len;
127 }
128 if (_stale) {
129 memcpy(p, stale_param.s, stale_param.len);

Callers 1

challengeFunction · 0.85

Calls 2

get_qop_paramFunction · 0.85
calc_nonceFunction · 0.85

Tested by

no test coverage detected