digest.h

00001 /*
00002  * $Id$
00003  *
00004  * Digest credentials parser interface
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 
00030 
00031 #ifndef DIGEST_H
00032 #define DIGEST_H
00033 
00034 #include "digest_parser.h"
00035 #include "../hf.h"         /* struct hdr_field */
00036 #include "../msg_parser.h"
00037 
00038 
00039 typedef struct auth_body {
00040              /* This is pointer to header field containing
00041               * parsed authorized digest credentials. This
00042               * pointer is set in sip_msg->{authorization,proxy_auth}
00043               * hooks.
00044               *
00045               * This is necessary for functions called after
00046               * {www,proxy}_authorize, these functions need to know
00047               * which credentials are authorized and they will simply
00048               * look into 
00049               * sip_msg->{authorization,proxy_auth}->parsed->authorized
00050               */
00051         struct hdr_field* authorized;
00052         dig_cred_t digest;           /* Parsed digest credentials */
00053         unsigned char stale;         /* Flag is set if nonce is stale */
00054 } auth_body_t;
00055 
00056 
00057 /*
00058  * Errors returned by check_dig_cred
00059  */
00060 typedef enum dig_err {
00061         E_DIG_OK = 0,        /* Everything is OK */
00062         E_DIG_USERNAME  = 1, /* Username missing */
00063         E_DIG_REALM = 2,     /* Realm missing */
00064         E_DIG_NONCE = 4,     /* Nonce value missing */
00065         E_DIG_URI = 8,       /* URI missing */
00066         E_DIG_RESPONSE = 16, /* Response missing */
00067         E_DIG_CNONCE = 32,   /* CNONCE missing */
00068         E_DIG_NC = 64,       /* Nonce-count missing */
00069         E_DIG_DOMAIN = 128   /* Username domain != realm */
00070 } dig_err_t;
00071 
00072 
00073 /*
00074  * Parse digest credentials
00075  */
00076 int parse_credentials(struct hdr_field* _h);
00077 
00078 
00079 /*
00080  * Free all memory associated with parsed
00081  * structures
00082  */
00083 void free_credentials(auth_body_t** _b);
00084 
00085 
00086 /*
00087  * Print dig_cred structure to stdout
00088  */
00089 void print_cred(dig_cred_t* _c);
00090 
00091 
00092 /*
00093  * Mark credentials as authorized
00094  */
00095 int mark_authorized_cred(struct sip_msg* _m, struct hdr_field* _h);
00096 
00097 
00098 /*
00099  * Get pointer to authorized credentials
00100  */
00101 int get_authorized_cred(struct hdr_field* _f, struct hdr_field** _h);
00102 
00103 
00104 /*
00105  * Check if credentials are correct
00106  * (check of semantics)
00107  */
00108 dig_err_t check_dig_cred(dig_cred_t* _c);
00109 
00110 
00111 /*
00112  * Find credentials with given realm in a SIP message header
00113  */
00114 int find_credentials(struct sip_msg* msg, str* realm,
00115                      hdr_types_t hftype, struct hdr_field** hdr);
00116 
00117 #endif /* DIGEST_H */