index.doxy 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. /**@page _Page_Main_Overview Overview
  2. This page is about the <b>open source 3GPP IMS-IPSec implementation</b> in <a target=_blank href="https://code.google.com/p/doubango/">Doubango VoIP framework</a> from <a target=_blank href="http://doubango.org/">Doubango Telecom</a>. <br />
  3. In this page we'll try to explain how security mechanisms are negotiated between an IMS Client and the Proxy-CSCF and how to setup SAs using <a href="http://ipsec-tools.sourceforge.net/"> Linux IPSec-Tools</a> and our demo clients (console app and <a href="https://code.google.com/p/boghe/">Boghe IMS Client</a>). <br />
  4. Our code have been fully tested against <a href="http://www.openimscore.org/">OpenIMSCore</a> and many other comercial IMS Cores. <br />
  5. - @ref _Anchor_TIPSec_Overview_Intro "1/ IPSec implementation in Doubango VoIP framework"
  6. - @ref _Anchor_TIPSec_Overview_SecAgree "2/ Security agreement"
  7. - @ref _Anchor_TIPSec_Overview_SecAgree_CallFlow "2.1/ Call flow"
  8. - @ref _Anchor_TIPSec_Overview_SecAgree_SipMessages "2.3/ SIP messages"
  9. - @ref _Anchor_TIPSec_Overview_IPSecTools "3/ Setting up SAs using Linux Tools"
  10. - @ref _Anchor_TIPSec_Overview_IPSecAPI "4/ Using tinyIPSec API"
  11. - @ref _Anchor_TIPSec_Overview_IPSecAPI_LoadPlugin "4.1/ Loading the Plugin"
  12. - @ref _Anchor_TIPSec_Overview_IPSecAPI_Client "4.2/ Client-side API"
  13. <h2>@anchor _Anchor_TIPSec_Overview_Intro 1/ IPSec implementation in Doubango VoIP framework</h2>
  14. The IPSec implementation in Doubango VoIP framework is distributed as standalone plugins (<b>pluginWinIPSecVista.DLL</b>, <b>pluginWinIPSecXP.DLL</b> and <b>pluginWinIPSecLinux.SO</b>).
  15. This allows having a single installer for all platforms as the right implementation is loaded at runtime (versus at link-time). Right now only <b>pluginWinIPSecVista.DLL</b> is open sourced. <br />
  16. <b>pluginWinIPSecVista.DLL</b> as it's name says, requires Windows Vista or later and uses <a href="http://msdn.microsoft.com/en-us/windows/hardware/gg463267.aspx">Windows Filtering Platform</a> to manually setup the IPSec SAs. <br />
  17. <b>pluginWinIPSecVista.DLL</b> supports:
  18. <ul>
  19. <li>IPProto: "udp", "tcp" and "icmp"</li>
  20. <li>Modes: "tun" (tunnel) and "trans" (transport)</li>
  21. <li>Encryption algorithm: "des-ede3-cbc", "aes-cbc" and "null"</li>
  22. <li>Authentication algorithm: "hmac-sha-1-96" and "hmac-md5-96"</li>
  23. <li>IPsecProto:"esp", "ah" and "ah/esp"</li>
  24. </ul>
  25. The utility functions used to load/unload the plugins and the wrappers for the high level APIs are in <b>tinyIPSec</b> project. <b>tinyIPSec</b> depends on <b>tinySAK </b>. <br />
  26. The framework implements: 3GPP TS 24.229, 3GPP TS 35.205, 3GPP TS 35.206, 3GPP TS 35.207, 3GPP TS 35.208, 3GPP TS 35.909, RFC 3329.
  27. <h2>@anchor _Anchor_TIPSec_Overview_SecAgree 2/ Security agreement</h2>
  28. The main purpose of Security agreement (<a href="http://www.ietf.org/rfc/rfc3329.txt">RFC 3329</a>) is to agree on which mechanisms, algorithms or security parameters to use.
  29. There are five main mechanisms used in VoIP networks: <br />
  30. <ul>
  31. <li>digest</li>
  32. <li>tls</li>
  33. <li>ipsec-ike</li>
  34. <li>ipsec-man</li>
  35. <li><b>ipsec-3gpp</b></li>
  36. </ul>
  37. We will focus on <b>ipsec-3gpp</b> because it's <b>mandatory</b> for IMS. This requires SIP <b>AKAv1/v2</b> authentication. <br />
  38. The security mechanism to use is known after the negotiation between the IMS Client and the Proxy-CSCF succeeds. This negotiation is performed during the IMS registration and authentication procedures.
  39. Three new SIP header fields have been defined, namely <b>Security-Client</b>, <b>Security-Server</b> and <b>Security-Verify</b>.
  40. <h3>@anchor _Anchor_TIPSec_Overview_SecAgree_CallFlow 2.1/ Call flow</h3>
  41. @code
  42. IMS Client P-CSCF S-CSCF
  43. | | |
  44. |----(1)REGISTER---->| |
  45. | | |
  46. | |---(2)REGISTER--->|
  47. | | |
  48. | |<-----(3) 401 ----|
  49. | | |
  50. |<----(4) 494/401----| |
  51. | | |
  52. |<==IPSec in place==>| |
  53. | | |
  54. |----(5)REGISTER---->| |
  55. | |----(6)REGISTER-->|
  56. | | |
  57. | |<---(7) 200 OK----|
  58. |<---(8) 200 OK------| |
  59. | | |
  60. @endcode
  61. - In step <b>(1)</b> the IMS Client sends an unprotected registration request including the security-client header. The Client must indicate that it is able to negotiate security mechanism by adding "Require" and "Proxy-Require" headers. The security-client header includes two ports (client and server ports) that the client wants to negotiate with the proxy CSCF.
  62. - In step <b>(2)</b> the Proxy CSCF forwards the request to the Serving CSCF.
  63. - In step <b>(3)</b> the Serving CSCF (registrar) challenges the Proxy CSCF. The 401 response is sent to the Proxy CSCF (challenge parameters are under WWW-Authenticated header). The Serving CSCF must include the "Security-Server" header.
  64. - In step <b>(4)</b> the Proxy CSCF forwards the 401/494 response to the IMS Client. At this stage the Proxy CSCF opens the IPsec security association (SA) for the IMS Client. The IMS Client also setup a SA (this is a temporary SA).
  65. - The lifetime of the created SA (between the IMS Client and the Proxy CSCF) is equal to the value of reg-await-auth timer.
  66. - In step <b>(5)</b> the IMS Client sends a new registration (to the Proxy CSCF) request including its credentials and copies the content of security-server header to the security-verify header. Before forwarding the request to the Serving CSCF, the Proxy CSCF will check that the previous security-server header and the security-verify headers (added by the IMS Client) are the same. If these values are different, the Proxy CSCF sends an error message to the IMS Client and terminates the created SAs.
  67. - In step <b>(6)</b> the Proxy CSCF forwards the request to the Serving CSCF.
  68. - In step <b>(7)</b> the Serving CSCF authenticates the IMS Client, and responds with 200 OK.
  69. - In step <b>(8)</b> the Proxy CSCF forwards the response to the IMS Client. At this step new SAs will be created. The temporary SAs will be destroyed (or not) by the Proxy CSCF.
  70. <h3>@anchor _Anchor_TIPSec_Overview_SecAgree_SipMessages 2.3/ SIP messages</h3>
  71. <b>(1)</b><br />
  72. @code
  73. REGISTER sip:pcscf.open-ims.test SIP/2.0
  74. Security-Client: ipsec-3gpp; alg=hmac-md5-96; ealg=des-ede3-cbc; prot=ah; mod=trans; spi-c=1111; spi-s=2222; port-c=5062; port-s=5064
  75. Require: sec-agree
  76. Proxy-Require: sec-agree
  77. @endcode
  78. <b>(4)</b>
  79. @code
  80. SIP/2.0 [494 Security Agreement Required / 401 Unauthorized]
  81. Security-Server: ipsec-3gpp; q=0.1; alg=hmac-md5-96; ealg=des-ede3-cbc; prot=ah; mod=trans; spi-c=3333; spi-s=4444; port-c=5066; port-s=5068
  82. @endcode
  83. <b>(5)</b><br />
  84. @code
  85. REGISTER sip:pcscf.open-ims.test SIP/2.0
  86. Security-Client: ipsec-3gpp; alg=hmac-md5-96; ealg=des-ede3-cbc; prot=ah; mod=trans; spi-c=1111; spi-s=2222; port-c=5062; port-s=5064
  87. Security-Verify: ipsec-3gpp; q=0.1; alg=hmac-md5-96; ealg=des-ede3-cbc; prot=ah; mod=trans; spi-c=3333; spi-s=4444; port-c=5066; port-s=5068
  88. Require: sec-agree
  89. Proxy-Require: sec-agree
  90. @endcode
  91. <h2>@anchor _Anchor_TIPSec_Overview_IPSecTools 3/ Setting up SAs using Linux Tools</h2>
  92. Here we suppose that: <br />
  93. - We are using Ubuntu (Linux Kernel 2.6 + KAME-tools)
  94. - the Proxy-CSCF address is '192.168.0.10' and Mercuro IMS Client address is '192.168.0.11'
  95. - for secure ports see above SIP capture
  96. - protocol is esp
  97. - algorithm is 'hmac-md5'
  98. - encrypt-algorithm is 'des-ede3-cbc'
  99. - mode is 'transport'
  100. - confidentiality key is '123456789012123456789012' (see function f2345 in 3GPP milenage algorithms)
  101. - integrity key is '1234567890123456' (see function f2345 in 3GPP milenage algorithms)
  102. <b>1. Install the tools</b>
  103. @code
  104. sudo apt-get install ipsec-tools
  105. @endcode
  106. <b>2. Edit /etc/ipsec-tools file and add the following script</b>
  107. @code
  108. #Incoming Requests [US <- PC]
  109. spdadd 192.168.0.10/32[5066] 192.168.0.11/32[5064] udp -P in ipsec esp/transport//require;
  110. add 192.168.0.10 192.168.0.11 esp 2222 -m transport -E des-ede3-cbc "123456789012123456789012" -A hmac-md5 "1234567890123456";
  111. #Incoming Replies [UC <- PS]
  112. spdadd 192.168.0.10/32[5068] 192.168.0.11/32[5062] udp -P in ipsec esp/transport//require;
  113. add 192.168.0.10 192.168.0.11 esp 1111 -m transport -E des-ede3-cbc "123456789012123456789012" -A hmac-md5 "1234567890123456";
  114. #Outgoing Requests [UC -> PS]
  115. spdadd 192.168.0.11/32[5062] 192.168.0.10/32[5068] udp -P out ipsec esp/transport//unique:1;
  116. add 192.168.0.11 192.168.0.10 esp 4444 -m transport -u 1 -E des-ede3-cbc "123456789012123456789012" -A hmac-md5 "1234567890123456";
  117. #Outgoing Replies [US -> PC]
  118. spdadd 192.168.0.11/32[5064] 192.168.0.10/32[5066] udp -P out ipsec esp/transport//unique:2;
  119. add 192.168.0.11 192.168.0.10 esp 3333 -m transport -u 2 -E des-ede3-cbc "123456789012123456789012" -A hmac-md5 "1234567890123456";
  120. @endcode
  121. <b>3. Run the script</b>
  122. @code
  123. sudo /etc/init.d/setkey start
  124. @endcode
  125. <h2>@anchor _Anchor_TIPSec_Overview_IPSecAPI 4/ Using tinyIPSec API</h2>
  126. This section explain how to setup the IPSec SAs using our API for a client (for the server it's obvisious). The values (SPIs, Ports, IP addresses...) are from previous sections. <br />
  127. In this section:
  128. - <b>UC</b> means UE acting as client (i.e sending a SIP request)
  129. - <b>US</b> means UE acting as server (i.e receiving a SIP request)
  130. - <b>PC</b> means P-CSCF acting as client (i.e sending a SIP request)
  131. - <b>PS</b> means P-CSCF acting as server (i.e receiving a SIP request)
  132. - <b>PORT-C</b> means port used by UC or PC
  133. - <b>PORT-S</b> means port used by US or PS
  134. - <a href="http://en.wikipedia.org/wiki/Security_Parameter_Index">SPI</a> means <b>S</b>ecurity <b>P</b>arameter <b>I</b>ndex (more info: <a href="http://en.wikipedia.org/wiki/Security_Parameter_Index">http://en.wikipedia.org/wiki/Security_Parameter_Index</a>)
  135. - <b>SPI-C</b> means SPI for PORT-C
  136. - <b>SPI-S</b> means SPI for PORT-S
  137. <b>/!\\VERY IMPORTANT:</b> On Windows the application (or Visual Studio if you're debugging the code) must be started as "Administrator" (Right click then <b>Run as administrator</b>) to be autorized to setup IPSec SAs (otherwise <b>error code 5</b>).
  138. <h3>@anchor _Anchor_TIPSec_Overview_IPSecAPI_LoadPlugin 4.1/ Loading the Plugin</h3>
  139. Before calling any API function from <b>tinyIPSec</b> it's required to load the standalone plugin like this:
  140. @code
  141. #include "tipsec.h"
  142. static tsk_bool_t __b_ipsec_supported = tsk_false;
  143. static struct tsk_plugin_s* __dll_plugin_ipsec_wfp = tsk_null;
  144. if(tdav_win32_is_winvista_or_later()){
  145. char* full_path = tsk_null;
  146. tsk_sprintf(&full_path, "%s/pluginWinIPSecVista.dll", tdav_get_current_directory_const());
  147. if (tsk_plugin_file_exist(full_path) && (tipsec_plugin_register_file(full_path, &__dll_plugin_ipsec_wfp) == 0)){
  148. __b_ipsec_supported = tsk_true;
  149. }
  150. TSK_FREE(full_path);
  151. }
  152. @endcode
  153. To unload the plugin:
  154. @code
  155. if (__dll_plugin_ipsec_wfp) {
  156. tipsec_plugin_unregister_file(__dll_plugin_ipsec_wfp);
  157. TSK_OBJECT_SAFE_FREE(__dll_plugin_ipsec_wfp); // free and set the pointer to NULL
  158. }
  159. @endcode
  160. <h3>@anchor _Anchor_TIPSec_Overview_IPSecAPI_Client 4.2/ Client-side API</h3>
  161. <b>1) Create a context</b>
  162. @code
  163. tipsec_error_t err;
  164. tipsec_ctx_t* p_ctx = tsk_null;
  165. err = tipsec_ctx_create(
  166. tipsec_ipproto_udp, // IPProto
  167. tsk_false, // Whether to use IPv6
  168. tipsec_mode_trans, // Mode
  169. tipsec_ealg_des_ede3_cbc, // Encryption algo
  170. tipsec_alg_hmac_md5_96, // Authentication algo
  171. tipsec_proto_ah, // IPSec proto
  172. &p_ctx);
  173. if (err) {
  174. exit(-1);
  175. }
  176. @endcode
  177. Because <a href="http://msdn.microsoft.com/en-us/windows/hardware/gg463267.aspx">Windows Filtering Platform</a> doesn't allow setting arbitrary SPIs we must create temporary SAs in order to have client SPIs for the initial REGISTER request.
  178. Temporary SAs requires information about the local address and ports. Remote port is not required but expected for better filtering to avoid IPSec restrictions for <b>any</b> in/out data towards the local ports. <br />
  179. <b>2) Create temporary SAs and request local SPIs</b>
  180. @code
  181. err = tipsec_ctx_set_local(
  182. p_ctx,
  183. "192.168.0.11", // Local IPv4 address (UE)
  184. "192.168.0.10", // Remote IPv4 address (P-CSCF)
  185. 5062, // Port used for outgoing data (UE, PORT-C, SPI-C)
  186. 5064 // Port used for incoming data (UE, PORT-S, SPI-S)
  187. );
  188. if (err) {
  189. exit(-1);
  190. }
  191. @endcode
  192. To create the <b>Security-Client</b> header for the initial REGISTER request:
  193. @code
  194. char* str_sec_client = tsk_null;
  195. // Security-Client: ipsec-3gpp; alg=hmac-md5-96; ealg=des-ede3-cbc; prot=ah; mod=trans; spi-c=1111; spi-s=2222; port-c=5062; port-s=5064
  196. tsk_sprintf(&str_sec_client, "Security-Client: ipsec-3gpp; alg=%s; ealg=%s; prot=%s; mod=%s; spi-c=%u; spi-s=%u; port-c=%u; port-s=%u",
  197. TIPSEC_ALG_TO_STR(p_ctx->alg),
  198. TIPSEC_EALG_TO_STR(p_ctx->ealg),
  199. TIPSEC_PROTOCOL_TO_STR(p_ctx->protocol),
  200. TIPSEC_MODE_TO_STR(p_ctx->mode),
  201. p_ctx->spi_uc,
  202. p_ctx->spi_us,
  203. p_ctx->port_uc,
  204. p_ctx->port_us);
  205. @endcode
  206. Now you can send the initial REGISTER (unprotected).
  207. <b>3) Setting remote information</b>
  208. Once the initial REGISTER is sent the server will send back a 494 response with one or several <b>Security-Server</b> headers. Select the best one and extract the information (SPIs, Ports, alogs,...) from it:
  209. @code
  210. err = tipsec_ctx_set_remote(
  211. p_ctx,
  212. 3333, // SPI-C for the P-CSCF
  213. 4444, // SPI-S for the P-CSCF
  214. 5066, // PORT-C for the P-CSCF
  215. 5068, // PORT-S for the P-CSCF
  216. 1800 // lifetime (in seconds) (at least the registration timeout)
  217. );
  218. if (err) {
  219. exit(-1);
  220. }
  221. @endcode
  222. <b>At this step, any data sent using PORT-C or receieved using PORT-S is (and must be) encrypted.</b>
  223. <b>4) Setting the CK and IK keys</b>
  224. The CK (Confidentiality) and IK (Integrity) keys are computed using the 3GPP milenage functions like this: <a href="https://code.google.com/p/doubango/source/browse/branches/2.0/doubango/tinySIP/src/authentication/tsip_challenge.c?r=765#85">https://code.google.com/p/doubango/source/browse/branches/2.0/doubango/tinySIP/src/authentication/tsip_challenge.c?r=765#85</a>. <br />
  225. To set the keys:
  226. @code
  227. err = tipsec_ctx_set_keys(
  228. p_ctx,
  229. "1234567890123456", // IK
  230. "123456789012123456789012" // CK
  231. );
  232. if (err) {
  233. exit(-1);
  234. }
  235. @endcode
  236. <b>5) Ensure the IPSec SAs</b>
  237. Ensure (promote) the temporary SAs:
  238. @code
  239. err = tipsec_ctx_start(p_ctx);
  240. if (err) {
  241. exit(-1);
  242. }
  243. @endcode
  244. to destroy IPSec SAs:
  245. @code
  246. TSK_OBJECT_SAFE_FREE(p_ctx); // call "stop(p_ctx)" then "free(p_ctx)"
  247. @endcode
  248. Et voilà, you're ready to send (port-c) and receive (port-s) IPSec data. <br />
  249. If you have any issue please check the @ref _Page_Main_FAQ "FAQ".
  250. */
  251. /**@page _Page_Main_FAQ (FAQ)
  252. - @ref _Anchor_TIPSec_FAQ_Client "Is there any IMS-Client implementing the new API?"
  253. - @ref _Anchor_TIPSec_FAQ_Samples "Is there any sample code showing how to use the new API?"
  254. - @ref _Anchor_TIPSec_FAQ_Stable "Is IPSec implementation in Doubango stable?"
  255. - @ref _Anchor_TIPSec_FAQ_Systems "Which operating systems are supported?"
  256. - @ref _Anchor_TIPSec_FAQ_Logs "Where are Boghe logs?"
  257. - @ref _Anchor_TIPSec_FAQ_ReportIssues "I'm using Boghe IMS Client to test IPSec but it's not working. How to report issues?"
  258. - @ref _Anchor_TIPSec_FAQ_CheckSAs "How to check SAs are up?"
  259. - @ref _Anchor_TIPSec_FAQ_Error5 "I see \"Error code 5\" when I try to setup a SA. How can I fix this?"
  260. <h2>@anchor _Anchor_TIPSec_FAQ_Client Is there any IMS-Client implementing the new API?</h2>
  261. Yes. <br />
  262. Try Boghe IMS Client: <a href="https://code.google.com/p/boghe/">https://code.google.com/p/boghe/</a>.
  263. <h2>@anchor _Anchor_TIPSec_FAQ_Samples Is there any sample code showing how to use the new API?</h2>
  264. Yes. <br />
  265. <b>ANSI-C:</b> $DOUBANGO_HOME/branches/2.0/doubango/tinyIPSec/tinyIPSec.sln <br />
  266. <b>C#:</b> $DOUBANGO_HOME/branches/2.0/doubango/Samples/C#/IPSec/ipsec.sln <br />
  267. <h2>@anchor _Anchor_TIPSec_FAQ_Stable Is IPSec implementation in Doubango stable?</h2>
  268. Our IPSec implementation is <b>3 years old</b> and have been tested against OpenIMSCore and many other IMS Cores. <br />
  269. By default, IPSec was desabled and it was up to the developer to rebuild the code to enable it. The new code is also clean and use standalone plugins.
  270. <h2>@anchor _Anchor_TIPSec_FAQ_Systems Which operating systems are supported?</h2>
  271. For now only <b>Windows Vista and later</b>. We've code for <b>Windows XP</b> and <b>Linux</b> but it's not published yet. <br />
  272. Ask on our <a href="https://groups.google.com/forum/#!forum/doubango">dev-group</a> to get the complete source code.
  273. <h2>@anchor _Anchor_TIPSec_FAQ_Logs Where are Boghe logs?</h2>
  274. On vista: C:\\Users\\your identity here\\AppData\\Roaming\\Doubango\\Boghe IMS Client\\Boghe.log.
  275. <h2>@anchor _Anchor_TIPSec_FAQ_ReportIssues I'm using Boghe IMS Client to test IPSec but it's not working. How to report issues?</h2>
  276. Make sure that you're:
  277. - using the latest <a href="https://code.google.com/p/boghe/downloads/list">Boghe</a> version (December 2013)
  278. - using Windows Vista or later
  279. - started the app as administrator (right click then, "Run as administrator") or disabled UAC
  280. If you still have problems then, share them on our <a href="https://groups.google.com/forum/#!forum/doubango">dev-group</a>. You <b>must</b> share your @ref _Anchor_TIPSec_FAQ_Logs "logs".
  281. <h2>@anchor _Anchor_TIPSec_FAQ_CheckSAs How to check SAs are up?</h2>
  282. Go to "Control Panel" -> "Administrative Tools" -> "Windows Firewall with Advanced Security" -> "Security Associations" -> "Quick Mode" and check that your SAs are listed there.
  283. <h2>@anchor _Anchor_TIPSec_FAQ_Error5 I see "Error code 5" when I try to setup a SA. How can I fix this?</h2>
  284. On Windows, error code 5 means "Access denied". You must start your app (or Visual Studio) as administrator or disable the UAC.
  285. */
  286. /**@page _Page_Main_Medium_Level_API_Overview Medium level API (C++)
  287. bla bla bla
  288. */