digest_parser.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Digest credentials parser
  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. * History:
  28. * -------
  29. *
  30. * 2003-03-15: Duplicate algorithm in dig_cred_t removed (janakj)
  31. */
  32. #ifndef DIGEST_PARSER_H
  33. #define DIGEST_PARSER_H
  34. #include "../../str.h"
  35. /* Type of algorithm used */
  36. typedef enum alg {
  37. ALG_UNSPEC = 0, /* Algorithm parameter not specified */
  38. ALG_MD5 = 1, /* MD5 - default value*/
  39. ALG_MD5SESS = 2, /* MD5-Session */
  40. ALG_OTHER = 4 /* Unknown */
  41. } alg_t;
  42. /* Quality Of Protection used */
  43. typedef enum qop_type {
  44. QOP_UNSPEC = 0, /* QOP parameter not present in response */
  45. QOP_AUTH = 1, /* Authentication only */
  46. QOP_AUTHINT = 2, /* Authentication with integrity checks */
  47. QOP_OTHER = 4 /* Unknown */
  48. } qop_type_t;
  49. /* Algorithm structure */
  50. struct algorithm {
  51. str alg_str; /* The original string representation */
  52. alg_t alg_parsed; /* Parsed value */
  53. };
  54. /* QOP structure */
  55. struct qp {
  56. str qop_str; /* The original string representation */
  57. qop_type_t qop_parsed; /* Parsed value */
  58. };
  59. /* Username structure */
  60. struct username {
  61. str whole; /* The whole username parameter value */
  62. str user; /* username part only */
  63. str domain; /* Domain part only */
  64. };
  65. /*
  66. * Parsed digest credentials
  67. */
  68. typedef struct dig_cred {
  69. struct username username; /* Username */
  70. str realm; /* Realm */
  71. str nonce; /* Nonce value */
  72. str uri; /* digest-uri, duplicated Request-URI of the Request-Line */
  73. str response; /* Response string */
  74. struct algorithm alg; /* Type of algorithm used */
  75. str cnonce; /* Cnonce value */
  76. str opaque; /* Opaque data string */
  77. struct qp qop; /* Quality Of Protection */
  78. str nc; /* Nonce count parameter */
  79. } dig_cred_t;
  80. /*
  81. * Macro to obtain the value of realm. The macro would first
  82. * check if there is any @domain part in the username and if
  83. * so, it will be returned as the value of realm. This hack is
  84. * ofter used to protect realm using the digest (username parameter
  85. * is protected by the response hash) and also to allow subscribers
  86. * to specify a different domain part than the one in realm parameter
  87. */
  88. #define GET_REALM(cred) \
  89. (((cred)->username.domain.len && (cred)->username.domain.s) ? \
  90. &(cred)->username.domain : \
  91. &(cred)->realm)
  92. /*
  93. * Initialize a digest credentials structure
  94. */
  95. void init_dig_cred(dig_cred_t* _c);
  96. /*
  97. * We support Digest authentication only
  98. *
  99. * Returns:
  100. * 0 - if everything is OK
  101. * -1 - Error while parsing
  102. * 1 - Unknown scheme
  103. */
  104. int parse_digest_cred(str* _s, dig_cred_t* _c);
  105. /*
  106. * Parse qop string
  107. */
  108. void parse_qop(struct qp* _q);
  109. #endif /* DIGEST_PARSER_H */