rfc2617.c File Reference


Detailed Description

Serving-CSCF - RFC2617.

Note:
Taken from the auth_db SER module

Definition in file rfc2617.c.

#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "rfc2617.h"
#include "../../md5global.h"
#include "../../md5.h"

Go to the source code of this file.

Functions

void cvt_hex (HASH _b, HASHHEX _h)
void calc_HA1 (ha_alg_t _alg, str *_username, str *_realm, str *_password, str *_nonce, str *_cnonce, HASHHEX _sess_key)
void calc_H (str *ent, HASHHEX hash)
void calc_response (HASHHEX _ha1, str *_nonce, str *_nc, str *_cnonce, str *_qop, int _auth_int, str *_method, str *_uri, HASHHEX _hentity, HASHHEX _response)

Variables

static char hexa_chars [17] = "0123456789abcdef"


Function Documentation

void cvt_hex ( HASH  _b,
HASHHEX  _h 
) [inline]

Definition at line 52 of file rfc2617.c.

References HASHHEXLEN, HASHLEN, and hexa_chars.

Referenced by calc_H(), calc_HA1(), and calc_response().

00053 {
00054     unsigned short i;   
00055     for (i = 0; i < HASHLEN; i++) {
00056         _h[i * 2] = hexa_chars[(_b[i] >> 4) & 0xf];
00057         _h[i * 2 + 1] =  hexa_chars[_b[i] & 0xf];
00058     };
00059     _h[HASHHEXLEN] = '\0';
00060 }

void calc_HA1 ( ha_alg_t  _alg,
str *  _username,
str *  _realm,
str *  _password,
str *  _nonce,
str *  _cnonce,
HASHHEX  _sess_key 
)

Definition at line 66 of file rfc2617.c.

References cvt_hex(), HA_MD5_SESS, and HASHLEN.

Referenced by S_is_authorized().

00068 {
00069     MD5_CTX Md5Ctx;
00070     HASH HA1;
00071     MD5Init(&Md5Ctx);
00072     MD5Update(&Md5Ctx, _username->s, _username->len);
00073     MD5Update(&Md5Ctx, ":", 1);
00074     MD5Update(&Md5Ctx, _realm->s, _realm->len);
00075     MD5Update(&Md5Ctx, ":", 1);
00076     MD5Update(&Md5Ctx, _password->s, _password->len);
00077     MD5Final(HA1, &Md5Ctx);
00078 
00079     if (_alg == HA_MD5_SESS) {
00080         MD5Init(&Md5Ctx);
00081         MD5Update(&Md5Ctx, HA1, HASHLEN);
00082         MD5Update(&Md5Ctx, ":", 1);
00083         MD5Update(&Md5Ctx, _nonce->s, _nonce->len);
00084         MD5Update(&Md5Ctx, ":", 1);
00085         MD5Update(&Md5Ctx, _cnonce->s, _cnonce->len);
00086         MD5Final(HA1, &Md5Ctx);
00087     };
00088 
00089     cvt_hex(HA1, _sess_key);
00090 }

void calc_H ( str *  ent,
HASHHEX  hash 
)

Definition at line 92 of file rfc2617.c.

References cvt_hex().

Referenced by S_is_authorized().

00093 {
00094     MD5_CTX Md5Ctx;
00095     HASH HA1;
00096     MD5Init(&Md5Ctx);
00097     MD5Update(&Md5Ctx, ent->s, ent->len);
00098     MD5Final(HA1, &Md5Ctx);
00099     cvt_hex(HA1, hash);
00100 }

void calc_response ( HASHHEX  _ha1,
str *  _nonce,
str *  _nc,
str *  _cnonce,
str *  _qop,
int  _auth_int,
str *  _method,
str *  _uri,
HASHHEX  _hentity,
HASHHEX  _response 
)

Definition at line 105 of file rfc2617.c.

References cvt_hex(), and HASHHEXLEN.

Referenced by S_is_authorized(), and S_MAR().

00109                                           : "", "auth", "auth-int" */
00110            int _auth_int,     /* 1 if auth-int is used */
00111            str* _method,      /* method from the request */
00112            str* _uri,         /* requested URL */
00113            HASHHEX _hentity,  /* H(entity body) if qop="auth-int" */
00114            HASHHEX _response) /* request-digest or response-digest */
00115 {
00116     MD5_CTX Md5Ctx;
00117     HASH HA2;
00118     HASH RespHash;
00119     HASHHEX HA2Hex;
00120     
00121          /* calculate H(A2) */
00122     MD5Init(&Md5Ctx);
00123     MD5Update(&Md5Ctx, _method->s, _method->len);
00124     MD5Update(&Md5Ctx, ":", 1);
00125     MD5Update(&Md5Ctx, _uri->s, _uri->len);
00126 
00127     if (_auth_int) {
00128         MD5Update(&Md5Ctx, ":", 1);
00129         MD5Update(&Md5Ctx, _hentity, HASHHEXLEN);
00130     };
00131 
00132     MD5Final(HA2, &Md5Ctx);
00133     cvt_hex(HA2, HA2Hex);
00134     
00135          /* calculate response */
00136     MD5Init(&Md5Ctx);
00137     MD5Update(&Md5Ctx, _ha1, HASHHEXLEN);
00138     MD5Update(&Md5Ctx, ":", 1);
00139     MD5Update(&Md5Ctx, _nonce->s, _nonce->len);
00140     MD5Update(&Md5Ctx, ":", 1);
00141 
00142     if (_qop->len) {
00143         MD5Update(&Md5Ctx, _nc->s, _nc->len);
00144         MD5Update(&Md5Ctx, ":", 1);
00145         MD5Update(&Md5Ctx, _cnonce->s, _cnonce->len);
00146         MD5Update(&Md5Ctx, ":", 1);
00147         MD5Update(&Md5Ctx, _qop->s, _qop->len);
00148         MD5Update(&Md5Ctx, ":", 1);
00149     };
00150     MD5Update(&Md5Ctx, HA2Hex, HASHHEXLEN);
00151     MD5Final(RespHash, &Md5Ctx);
00152     cvt_hex(RespHash, _response);
00153 }


Variable Documentation

char hexa_chars[17] = "0123456789abcdef" [static]

Definition at line 50 of file rfc2617.c.

Referenced by cvt_hex().


Generated on Thu Oct 23 04:14:45 2008 for Open IMS Core CSCFs by  doxygen 1.5.2