sip_auth_msg.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef __PJSIP_AUTH_SIP_AUTH_MSG_H__
  20. #define __PJSIP_AUTH_SIP_AUTH_MSG_H__
  21. #include <pjsip/sip_msg.h>
  22. PJ_BEGIN_DECL
  23. /**
  24. * @addtogroup PJSIP_MSG_HDR
  25. * @{
  26. */
  27. /**
  28. * Common credential structure represents common credential fields
  29. * present in Authorization/Proxy-Authorization header.
  30. */
  31. struct pjsip_common_credential
  32. {
  33. pj_str_t realm; /**< Credential's realm. */
  34. pjsip_param other_param; /**< Other parameters. */
  35. };
  36. /**
  37. * @see pjsip_common_credential
  38. */
  39. typedef struct pjsip_common_credential pjsip_common_credential;
  40. /**
  41. * This structure describe credential used in Authorization and
  42. * Proxy-Authorization header for digest authentication scheme.
  43. */
  44. struct pjsip_digest_credential
  45. {
  46. pj_str_t realm; /**< Realm of the credential */
  47. pjsip_param other_param; /**< Other parameters. */
  48. pj_str_t username; /**< Username parameter. */
  49. pj_str_t nonce; /**< Nonce parameter. */
  50. pj_str_t uri; /**< URI parameter. */
  51. pj_str_t response; /**< Response digest. */
  52. pj_str_t algorithm; /**< Algorithm. */
  53. pj_str_t cnonce; /**< Cnonce. */
  54. pj_str_t opaque; /**< Opaque value. */
  55. pj_str_t qop; /**< Quality of protection. */
  56. pj_str_t nc; /**< Nonce count. */
  57. };
  58. /**
  59. * @see pjsip_digest_credential
  60. */
  61. typedef struct pjsip_digest_credential pjsip_digest_credential;
  62. /**
  63. * This structure describe credential used in Authorization and
  64. * Proxy-Authorization header for PGP authentication scheme.
  65. */
  66. struct pjsip_pgp_credential
  67. {
  68. pj_str_t realm; /**< Realm. */
  69. pjsip_param other_param; /**< Other parameters. */
  70. pj_str_t version; /**< Version parameter. */
  71. pj_str_t signature; /**< Signature parameter. */
  72. pj_str_t signed_by; /**< Signed by parameter. */
  73. pj_str_t nonce; /**< Nonce parameter. */
  74. };
  75. /**
  76. * @see pjsip_pgp_credential
  77. */
  78. typedef struct pjsip_pgp_credential pjsip_pgp_credential;
  79. /**
  80. * This structure describe credential used in Authorization and
  81. * Proxy-Authorization header for OAuth authentication scheme.
  82. */
  83. struct pjsip_oauth_credential
  84. {
  85. pj_str_t realm; /**< Realm of the credential */
  86. pjsip_param other_param; /**< Other parameters. */
  87. pj_str_t username; /**< Username parameter. */
  88. pj_str_t token; /**< Token parameter. */
  89. };
  90. /**
  91. * @see pjsip_oauth_credential
  92. */
  93. typedef struct pjsip_oauth_credential pjsip_oauth_credential;
  94. /**
  95. * This structure describes SIP Authorization header (and also SIP
  96. * Proxy-Authorization header).
  97. */
  98. struct pjsip_authorization_hdr
  99. {
  100. /** Standard header fiends. */
  101. PJSIP_DECL_HDR_MEMBER(struct pjsip_authorization_hdr);
  102. /** Authorization scheme. */
  103. pj_str_t scheme;
  104. /** Type of credentials, depending on the scheme. */
  105. union
  106. {
  107. pjsip_common_credential common; /**< Common fields. */
  108. pjsip_digest_credential digest; /**< Digest credentials. */
  109. pjsip_pgp_credential pgp; /**< PGP credentials. */
  110. pjsip_oauth_credential oauth; /**< OAuth credentials. */
  111. } credential;
  112. };
  113. /**
  114. * @see pjsip_authorization_hdr.
  115. */
  116. typedef struct pjsip_authorization_hdr pjsip_authorization_hdr;
  117. /** SIP Proxy-Authorization header shares the same structure as SIP
  118. Authorization header.
  119. */
  120. typedef struct pjsip_authorization_hdr pjsip_proxy_authorization_hdr;
  121. /**
  122. * Create SIP Authorization header.
  123. * @param pool Pool where memory will be allocated from.
  124. * @return SIP Authorization header.
  125. */
  126. PJ_DECL(pjsip_authorization_hdr*)
  127. pjsip_authorization_hdr_create(pj_pool_t *pool);
  128. /**
  129. * Create SIP Proxy-Authorization header.
  130. * @param pool Pool where memory will be allocated from.
  131. * @return SIP Proxy-Authorization header.
  132. */
  133. PJ_DECL(pjsip_proxy_authorization_hdr*)
  134. pjsip_proxy_authorization_hdr_create(pj_pool_t *pool);
  135. /**
  136. * This structure describes common fields in authentication challenge
  137. * headers (WWW-Authenticate and Proxy-Authenticate).
  138. */
  139. struct pjsip_common_challenge
  140. {
  141. pj_str_t realm; /**< Realm for the challenge. */
  142. pjsip_param other_param; /**< Other parameters. */
  143. };
  144. /**
  145. * @see pjsip_common_challenge
  146. */
  147. typedef struct pjsip_common_challenge pjsip_common_challenge;
  148. /**
  149. * This structure describes authentication challenge used in Proxy-Authenticate
  150. * or WWW-Authenticate for digest authentication scheme.
  151. */
  152. struct pjsip_digest_challenge
  153. {
  154. pj_str_t realm; /**< Realm for the challenge. */
  155. pjsip_param other_param; /**< Other parameters. */
  156. pj_str_t domain; /**< Domain. */
  157. pj_str_t nonce; /**< Nonce challenge. */
  158. pj_str_t opaque; /**< Opaque value. */
  159. int stale; /**< Stale parameter. */
  160. pj_str_t algorithm; /**< Algorithm parameter. */
  161. pj_str_t qop; /**< Quality of protection. */
  162. };
  163. /**
  164. * @see pjsip_digest_challenge
  165. */
  166. typedef struct pjsip_digest_challenge pjsip_digest_challenge;
  167. /**
  168. * This structure describes authentication challenge used in Proxy-Authenticate
  169. * or WWW-Authenticate for PGP authentication scheme.
  170. */
  171. struct pjsip_pgp_challenge
  172. {
  173. pj_str_t realm; /**< Realm for the challenge. */
  174. pjsip_param other_param; /**< Other parameters. */
  175. pj_str_t version; /**< PGP version. */
  176. pj_str_t micalgorithm; /**< micalgorithm parameter. */
  177. pj_str_t pubalgorithm; /**< pubalgorithm parameter. */
  178. pj_str_t nonce; /**< Nonce challenge. */
  179. };
  180. /**
  181. * @see pjsip_pgp_challenge
  182. */
  183. typedef struct pjsip_pgp_challenge pjsip_pgp_challenge;
  184. /**
  185. * This structure describe SIP WWW-Authenticate header (Proxy-Authenticate
  186. * header also uses the same structure).
  187. */
  188. struct pjsip_www_authenticate_hdr
  189. {
  190. /** Standard header fields. */
  191. PJSIP_DECL_HDR_MEMBER(struct pjsip_www_authenticate_hdr);
  192. /** Authentication scheme */
  193. pj_str_t scheme;
  194. /** This union contains structures that are only relevant
  195. depending on the value of the scheme being used.
  196. */
  197. union
  198. {
  199. pjsip_common_challenge common; /**< Common fields. */
  200. pjsip_digest_challenge digest; /**< Digest challenge. */
  201. pjsip_pgp_challenge pgp; /**< PGP challenge. */
  202. } challenge;
  203. };
  204. /**
  205. * WWW-Authenticate header.
  206. */
  207. typedef struct pjsip_www_authenticate_hdr pjsip_www_authenticate_hdr;
  208. /**
  209. * Proxy-Authenticate header.
  210. */
  211. typedef struct pjsip_www_authenticate_hdr pjsip_proxy_authenticate_hdr;
  212. /**
  213. * Create SIP WWW-Authenticate header.
  214. *
  215. * @param pool Pool where memory will be allocated from.
  216. * @return SIP WWW-Authenticate header.
  217. */
  218. PJ_DECL(pjsip_www_authenticate_hdr*)
  219. pjsip_www_authenticate_hdr_create(pj_pool_t *pool);
  220. /**
  221. * Create SIP Proxy-Authenticate header.
  222. *
  223. * @param pool Pool where memory will be allocated from.
  224. * @return SIP Proxy-Authenticate header.
  225. */
  226. PJ_DECL(pjsip_proxy_authenticate_hdr*)
  227. pjsip_proxy_authenticate_hdr_create(pj_pool_t *pool);
  228. /**
  229. * @}
  230. */
  231. PJ_END_DECL
  232. #endif /* __PJSIP_AUTH_SIP_AUTH_MSG_H__ */