digest_parser.h

Go to the documentation of this file.
00001 /*
00002  * $Id: digest_parser.h 4518 2008-07-28 15:39:28Z henningw $
00003  *
00004  * Digest credentials parser
00005  *
00006  * Copyright (C) 2001-2003 FhG Fokus
00007  *
00008  * This file is part of Kamailio, a free SIP server.
00009  *
00010  * Kamailio is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version
00014  *
00015  * Kamailio is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License 
00021  * along with this program; if not, write to the Free Software 
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  * History:
00025  * -------
00026  * 2003-03-15: Duplicate algorithm in dig_cred_t removed (janakj)
00027  */
00028 
00029 
00030 
00031 #ifndef DIGEST_PARSER_H
00032 #define DIGEST_PARSER_H
00033 
00034 #include "../../str.h"
00035 
00036 
00037 /* Type of algorithm used */
00038 typedef enum alg {
00039    ALG_UNSPEC = 0,   /* Algorithm parameter not specified */
00040    ALG_MD5 = 1,      /* MD5 - default value*/
00041    ALG_MD5SESS = 2,  /* MD5-Session */
00042    ALG_OTHER = 4     /* Unknown */
00043 } alg_t;
00044 
00045 
00046 /* Quality Of Protection used */
00047 typedef enum qop_type { 
00048    QOP_UNSPEC = 0,   /* QOP parameter not present in response */
00049    QOP_AUTH = 1,     /* Authentication only */
00050    QOP_AUTHINT = 2,  /* Authentication with integrity checks */
00051    QOP_OTHER = 4     /* Unknown */
00052 } qop_type_t;
00053 
00054 
00055 /* Algorithm structure */
00056 struct algorithm {
00057    str alg_str;       /* The original string representation */
00058    alg_t alg_parsed;  /* Parsed value */
00059 };
00060 
00061 
00062 /* QOP structure */
00063 struct qp {
00064    str qop_str;           /* The original string representation */
00065    qop_type_t qop_parsed; /* Parsed value */
00066 };
00067 
00068 
00069 /* Username structure */
00070 struct username {
00071    str whole;        /* The whole username parameter value */
00072    str user;         /* username part only */
00073    str domain;       /* Domain part only */
00074 };
00075 
00076 
00077 /*
00078  * Parsed digest credentials
00079  */
00080 typedef struct dig_cred {
00081    struct username username;   /* Username */
00082    str realm;                  /* Realm */
00083    str nonce;                  /* Nonce value */
00084    str uri;                    /* URI */
00085    str response;               /* Response string */
00086    struct algorithm alg;       /* Type of algorithm used */
00087    str cnonce;                 /* Cnonce value */
00088    str opaque;                 /* Opaque data string */
00089    struct qp qop;              /* Quality Of Protection */
00090    str nc;                     /* Nonce count parameter */
00091 } dig_cred_t;
00092 
00093 
00094  /*
00095  * Macro to obtain the value of realm. The macro would first
00096  * check if there is any @domain part in the username and if
00097  * so, it will be returned as the value of realm. This hack is
00098  * ofter used to protect realm using the digest (username parameter
00099  * is protected by the response hash) and also to allow subscribers
00100  * to specify a different domain part than the one in realm parameter
00101  */
00102 #define GET_REALM(cred)                                           \
00103     (((cred)->username.domain.len && (cred)->username.domain.s) ? \
00104      &(cred)->username.domain :                                   \
00105      &(cred)->realm)
00106 
00107 
00108 /*
00109  * Initialize a digest credentials structure
00110  */
00111 void init_dig_cred(dig_cred_t* _c);
00112 
00113 
00114 /*
00115  * We support Digest authentication only
00116  *
00117  * Returns:
00118  *  0 - if everything is OK
00119  * -1 - Error while parsing
00120  *  1 - Unknown scheme
00121  */
00122 int parse_digest_cred(str* _s, dig_cred_t* _c);
00123 
00124 
00125 #endif /* DIGEST_PARSER_H */

Generated on Tue May 22 16:00:26 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6