00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef NONCE_H
00032 #define NONCE_H
00033
00034 #include "../../parser/msg_parser.h"
00035 #include "../../parser/digest/digest.h"
00036 #include "../../str.h"
00037 #include "../../basex.h"
00038 #include <time.h>
00039
00040
00041
00042
00043 #define AUTH_CHECK_FULL_URI (1 << 0)
00044 #define AUTH_CHECK_CALLID (1 << 1)
00045 #define AUTH_CHECK_FROMTAG (1 << 2)
00046 #define AUTH_CHECK_SRC_IP (1 << 3)
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 #if defined USE_NC || defined USE_OT_NONCE
00062 #define NF_VALID_NC_ID 128
00063 #define NF_VALID_OT_ID 64
00064
00065 #define NF_POOL_NO_MASK 63
00066 #endif
00067
00068 #if defined USE_NC || defined USE_OT_NONCE
00069 #define nonce_nid_extra_size (sizeof(unsigned int)+sizeof(unsigned char))
00070
00071 #else
00072
00073 #define nonce_nid_extra_size 0
00074 #endif
00075
00076
00077 struct bin_nonce_str{
00078 int expire;
00079 int since;
00080 char md5_1[16];
00081 char md5_2[16];
00082 #if defined USE_NC || defined USE_OT_NONCE
00083 unsigned int nid_i;
00084 unsigned char nid_pf;
00085
00086 #endif
00087 };
00088
00089
00090 struct bin_nonce_small_str{
00091 int expire;
00092 int since;
00093 char md5_1[16];
00094 #if defined USE_NC || defined USE_OT_NONCE
00095 unsigned int nid_i;
00096 unsigned char nid_pf;
00097
00098 #endif
00099 };
00100
00101
00102 union bin_nonce{
00103 struct bin_nonce_str n;
00104 struct bin_nonce_small_str n_small;
00105 unsigned char raw[sizeof(struct bin_nonce_str)];
00106 };
00107
00108
00109
00110 #define BIN_NONCE_PREPARE_COMMON(bn, expire_val, since_val) \
00111 do{\
00112 (bn)->n.expire=htonl(expire_val); \
00113 (bn)->n.since=htonl(since_val); \
00114 }while(0)
00115
00116 #if defined USE_NC || defined USE_OT_NONCE
00117 #define BIN_NONCE_PREPARE(bn, expire_v, since_v, id_v, pf_v, cfg, msg) \
00118 do{ \
00119 BIN_NONCE_PREPARE_COMMON(bn, expire_v, since_v); \
00120 if (cfg && msg){ \
00121 (bn)->n.nid_i=htonl(id_v); \
00122 (bn)->n.nid_pf=(pf_v); \
00123 }else{ \
00124 (bn)->n_small.nid_i=htonl(id_v); \
00125 (bn)->n_small.nid_pf=(pf_v); \
00126 } \
00127 }while(0)
00128 #else
00129 #define BIN_NONCE_PREPARE(bn, expire, since, id, pf, cfg, msg) \
00130 BIN_NONCE_PREPARE_COMMON(bn, expire, since)
00131 #endif
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 #if defined USE_NC || defined USE_OT_NONCE
00145 #define MAX_BIN_NONCE_LEN (4 + 4 + 16 + 16 + 4 +1)
00146 #define MAX_NOCFG_BIN_NONCE_LEN (4 + 4 + 16 + 4 + 1)
00147
00148 #define get_bin_nonce_len(cfg, nid_enabled) \
00149 ( ( (cfg)?MAX_BIN_NONCE_LEN:MAX_NOCFG_BIN_NONCE_LEN ) - \
00150 (!(nid_enabled))*nonce_nid_extra_size )
00151
00152 #else
00153 #define MAX_BIN_NONCE_LEN (4 + 4 + 16 + 16)
00154 #define MAX_NOCFG_BIN_NONCE_LEN (4 + 4 + 16)
00155
00156 #define get_bin_nonce_len(cfg, nid_enabled) \
00157 ( (cfg)?MAX_BIN_NONCE_LEN:MAX_NOCFG_BIN_NONCE_LEN )
00158
00159 #endif
00160
00161
00162
00163
00164
00165
00166 #define MIN_BIN_NONCE_LEN (4 + 4 + 16)
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176 #define MAX_NONCE_LEN base64_enc_len(MAX_BIN_NONCE_LEN)
00177
00178
00179
00180
00181
00182 #define MIN_NONCE_LEN base64_enc_len(MIN_BIN_NONCE_LEN)
00183
00184
00185
00186
00187 #define MAX_NOCFG_NONCE_LEN base64_enc_len(MAX_NOCFG_BIN_NONCE_LEN)
00188
00189
00190
00191 extern int auth_checks_reg;
00192
00193 extern int auth_checks_ood;
00194
00195 extern int auth_checks_ind;
00196
00197
00198
00199
00200
00201 extern unsigned int nonce_auth_max_drift;
00202
00203
00204 int get_auth_checks(struct sip_msg* msg);
00205
00206
00207
00208
00209
00210 #define get_nonce_len(cfg, nid_enabled) \
00211 base64_enc_len(get_bin_nonce_len(cfg, nid_enabled))
00212
00213
00214
00215
00216
00217 int calc_nonce(char* nonce, int* nonce_len, int cfg, int since, int expires,
00218 #if defined USE_NC || defined USE_OT_NONCE
00219 unsigned int n_id, unsigned char pf,
00220 #endif
00221 str* secret1, str* secret2, struct sip_msg* msg);
00222
00223
00224
00225
00226
00227 int check_nonce(auth_body_t* auth, str* secret1, str* secret2,
00228 struct sip_msg* msg);
00229
00230
00231
00232 #endif