digest_parser.h

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