digest.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Digest credentials parser interface
  3. *
  4. * Copyright (C) 2001-2003 FhG Fokus
  5. *
  6. * This file is part of ser, a free SIP server.
  7. *
  8. * ser is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * For a license to use the ser software under conditions
  14. * other than those described here, or to purchase support for this
  15. * software, please contact iptel.org by e-mail at the following addresses:
  16. * [email protected]
  17. *
  18. * ser is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  26. */
  27. #ifndef DIGEST_H
  28. #define DIGEST_H
  29. #include "digest_parser.h"
  30. #include "../hf.h" /* struct hdr_field */
  31. #include "../msg_parser.h"
  32. typedef struct auth_body {
  33. /* This is pointer to header field containing
  34. * parsed authorized digest credentials. This
  35. * pointer is set in sip_msg->{authorization,proxy_auth}
  36. * hooks.
  37. *
  38. * This is necessary for functions called after
  39. * {www,proxy}_authorize, these functions need to know
  40. * which credentials are authorized and they will simply
  41. * look into
  42. * sip_msg->{authorization,proxy_auth}->parsed->authorized
  43. */
  44. struct hdr_field* authorized;
  45. dig_cred_t digest; /* Parsed digest credentials */
  46. unsigned char stale; /* Flag is set if nonce is stale */
  47. } auth_body_t;
  48. /*
  49. * Errors returned by check_dig_cred
  50. */
  51. typedef enum dig_err {
  52. E_DIG_OK = 0, /* Everything is OK */
  53. E_DIG_USERNAME = 1, /* Username missing */
  54. E_DIG_REALM = 2, /* Realm missing */
  55. E_DIG_NONCE = 4, /* Nonce value missing */
  56. E_DIG_URI = 8, /* URI missing */
  57. E_DIG_RESPONSE = 16, /* Response missing */
  58. E_DIG_CNONCE = 32, /* CNONCE missing */
  59. E_DIG_NC = 64, /* Nonce-count missing */
  60. E_DIG_DOMAIN = 128 /* Username domain != realm */
  61. } dig_err_t;
  62. /*
  63. * Parse digest credentials
  64. */
  65. int parse_credentials(struct hdr_field* _h);
  66. /*
  67. * Free all memory associated with parsed
  68. * structures
  69. */
  70. void free_credentials(auth_body_t** _b);
  71. /*
  72. * Print dig_cred structure to stdout
  73. */
  74. void print_cred(dig_cred_t* _c);
  75. /*
  76. * Mark credentials as authorized
  77. */
  78. int mark_authorized_cred(struct sip_msg* _m, struct hdr_field* _h);
  79. /*
  80. * Get pointer to authorized credentials
  81. */
  82. int get_authorized_cred(struct hdr_field* _f, struct hdr_field** _h);
  83. /*
  84. * Check if credentials are correct
  85. * (check of semantics)
  86. */
  87. dig_err_t check_dig_cred(dig_cred_t* _c);
  88. /*
  89. * Find credentials with given realm in a SIP message header
  90. */
  91. int find_credentials(struct sip_msg* msg, str* realm,
  92. hdr_types_t hftype, struct hdr_field** hdr);
  93. #endif /* DIGEST_H */