sip_auth_aka.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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_AKA_H__
  20. #define __PJSIP_AUTH_SIP_AUTH_AKA_H__
  21. /**
  22. * @file sip_auth_aka.h
  23. * @brief SIP Digest AKA Authorization Module.
  24. */
  25. #include <pjsip/sip_auth.h>
  26. PJ_BEGIN_DECL
  27. /**
  28. * @defgroup PJSIP_AUTH_AKA_API Digest AKAv1 and AKAv2 Authentication API
  29. * @ingroup PJSIP_AUTH_API
  30. * @brief Digest AKAv1 and AKAv2 Authentication API
  31. * @{
  32. *
  33. * This module implements HTTP digest authentication using Authentication
  34. * and Key Agreement (AKA) version 1 and version 2 (AKAv1-MD5 and AKAv2-MD5),
  35. * as specified in RFC 3310 and RFC 4169. SIP AKA authentication is used
  36. * by 3GPP and IMS systems.
  37. *
  38. * @section pjsip_aka_using Using Digest AKA Authentication
  39. *
  40. * Support for digest AKA authentication is currently made optional, so
  41. * application needs to declare \a PJSIP_HAS_DIGEST_AKA_AUTH to non-zero
  42. * in <tt>config_site.h</tt> to enable AKA support:
  43. *
  44. @code
  45. #define PJSIP_HAS_DIGEST_AKA_AUTH 1
  46. @endcode
  47. *
  48. * In addition, application would need to link with <b>libmilenage</b>
  49. * library from \a third_party directory.
  50. *
  51. * Application then specifies digest AKA credential by initializing the
  52. * authentication credential as follows:
  53. *
  54. @code
  55. pjsip_cred_info cred;
  56. pj_bzero(&cred, sizeof(cred));
  57. cred.scheme = pj_str("Digest");
  58. cred.realm = pj_str("ims-domain.test");
  59. cred.username = pj_str("user@ims-domain.test");
  60. cred.data_type = PJSIP_CRED_DATA_PLAIN_PASSWD | PJSIP_CRED_DATA_EXT_AKA;
  61. cred.data = pj_str("password");
  62. // AKA extended info
  63. cred.ext.aka.k = pj_str("password");
  64. cred.ext.aka.cb = &pjsip_auth_create_aka_response
  65. @endcode
  66. *
  67. * Description:
  68. * - To support AKA, application adds \a PJSIP_CRED_DATA_EXT_AKA flag in the
  69. * \a data_type field. This indicates that extended information specific to
  70. * AKA authentication is available in the credential, and that response
  71. * digest computation will use the callback function instead of the usual MD5
  72. * digest computation.
  73. *
  74. * - The \a scheme for the credential is "Digest".
  75. *
  76. * - The \a realm is the expected realm in the challenge. Application may
  77. * also specify wildcard realm ("*") if it wishes to respond to any realms
  78. * in the challenge.
  79. *
  80. * - The \a data field is optional. Application may fill this with the password
  81. * if it wants to support both MD5 and AKA MD5 in a single credential. The
  82. * pjsip_auth_create_aka_response() function will use this field if the
  83. * challenge indicates "MD5" as the algorithm instead of "AKAv1-MD5" or
  84. * "AKAv2-MD5".
  85. *
  86. * - The \a ext.aka.k field specifies the permanent subscriber key to be used
  87. * for AKA authentication. Application may specify binary password containing
  88. * NULL character in this key, since the length of the key is indicated in
  89. * the \a slen field of the string.
  90. *
  91. * - The \a ext.aka.cb field specifies the callback function to calculate the
  92. * response digest. Application can specify pjsip_auth_create_aka_response()
  93. * in this field to use PJSIP's implementation, but it's free to provide
  94. * it's own function.
  95. *
  96. * - Optionally application may set \a ext.aka.op and \a ext.aka.amf in the
  97. * credential to specify AKA Operator variant key and AKA Authentication
  98. * Management Field information.
  99. */
  100. /**
  101. * Length of Authentication Key (AK) in bytes.
  102. */
  103. #define PJSIP_AKA_AKLEN 6
  104. /**
  105. * Length of Authentication Management Field (AMF) in bytes.
  106. */
  107. #define PJSIP_AKA_AMFLEN 2
  108. /**
  109. * Length of AUTN in bytes.
  110. */
  111. #define PJSIP_AKA_AUTNLEN 16
  112. /**
  113. * Length of Confidentiality Key (CK) in bytes.
  114. */
  115. #define PJSIP_AKA_CKLEN 16
  116. /**
  117. * Length of Integrity Key (AK) in bytes.
  118. */
  119. #define PJSIP_AKA_IKLEN 16
  120. /**
  121. * Length of permanent/subscriber Key (K) in bytes.
  122. */
  123. #define PJSIP_AKA_KLEN 16
  124. /**
  125. * Length of AKA authentication code in bytes.
  126. */
  127. #define PJSIP_AKA_MACLEN 8
  128. /**
  129. * Length of operator key in bytes.
  130. */
  131. #define PJSIP_AKA_OPLEN 16
  132. /**
  133. * Length of random challenge (RAND) in bytes.
  134. */
  135. #define PJSIP_AKA_RANDLEN 16
  136. /**
  137. * Length of response digest in bytes.
  138. */
  139. #define PJSIP_AKA_RESLEN 8
  140. /**
  141. * Length of sequence number (SQN) in bytes.
  142. */
  143. #define PJSIP_AKA_SQNLEN 6
  144. /**
  145. * This function creates MD5, AKAv1-MD5, or AKAv2-MD5 response for
  146. * the specified challenge in \a chal, according to the algorithm
  147. * specified in the challenge, and based on the information in the
  148. * credential \a cred.
  149. *
  150. * Application may register this function as \a ext.aka.cb field of
  151. * #pjsip_cred_info structure to make PJSIP automatically call this
  152. * function to calculate the response digest. To do so, it needs to
  153. * add \a PJSIP_CRED_DATA_EXT_AKA flag in the \a data_type field of
  154. * the credential, and fills up other AKA specific information in
  155. * the credential.
  156. *
  157. * @param pool Pool to allocate memory.
  158. * @param chal The authentication challenge sent by server in 401
  159. * or 401 response, as either Proxy-Authenticate or
  160. * WWW-Authenticate header.
  161. * @param cred The credential to be used.
  162. * @param method The request method.
  163. * @param auth The digest credential where the digest response
  164. * will be placed to. Upon calling this function, the
  165. * nonce, nc, cnonce, qop, uri, and realm fields of
  166. * this structure must have been set by caller. Upon
  167. * return, the \a response field will be initialized
  168. * by this function.
  169. *
  170. * @return PJ_SUCCESS if response has been created successfully.
  171. */
  172. PJ_DECL(pj_status_t) pjsip_auth_create_aka_response(
  173. pj_pool_t *pool,
  174. const pjsip_digest_challenge*chal,
  175. const pjsip_cred_info *cred,
  176. const pj_str_t *method,
  177. pjsip_digest_credential *auth);
  178. /**
  179. * @}
  180. */
  181. PJ_END_DECL
  182. #endif /* __PJSIP_AUTH_SIP_AUTH_AKA_H__ */