IPSecCtx.cxx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Copyright (C) 2010-2014 Mamadou DIOP
  2. * Copyright (C) 2011-2014 Doubango Telecom <http://www.doubango.org>
  3. *
  4. * This file is part of Open Source Doubango Framework.
  5. *
  6. * DOUBANGO is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * DOUBANGO is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with DOUBANGO.
  18. */
  19. #include "IPSecCtx.h"
  20. #include "tsk_debug.h"
  21. #include <assert.h>
  22. bool IPSecCtx::sInitialized = false;
  23. extern "C" const tipsec_plugin_def_t *plugin_win_ipsec_vista_plugin_def_t;
  24. IPSecCtx::IPSecCtx(tipsec_ipproto_t ipproto,
  25. bool use_ipv6,
  26. tipsec_mode_t mode,
  27. tipsec_ealg_t ealg,
  28. tipsec_alg_t alg,
  29. tipsec_proto_t protocol)
  30. : m_pCtx(NULL)
  31. {
  32. tipsec_ctx_t* pCtx = NULL;
  33. if (!IPSecCtx::sInitialized) {
  34. assert (tipsec_plugin_register_static(plugin_win_ipsec_vista_plugin_def_t) == 0);
  35. IPSecCtx::sInitialized = true;
  36. }
  37. assert (tipsec_ctx_create(ipproto, use_ipv6, mode, ealg, alg, protocol, &m_pCtx) == 0 && m_pCtx != NULL);
  38. }
  39. IPSecCtx::~IPSecCtx()
  40. {
  41. TSK_OBJECT_SAFE_FREE(m_pCtx);
  42. }
  43. tipsec_error_t IPSecCtx::start()
  44. {
  45. return tipsec_ctx_start(m_pCtx);
  46. }
  47. tipsec_error_t IPSecCtx::setLocal(const char* addr_local, const char* addr_remote, tipsec_port_t port_uc, tipsec_port_t port_us)
  48. {
  49. return tipsec_ctx_set_local(m_pCtx, addr_local, addr_remote, port_uc, port_us);
  50. }
  51. tipsec_error_t IPSecCtx::setKeys(const tipsec_key_t* ik, const tipsec_key_t* ck)
  52. {
  53. return tipsec_ctx_set_keys(m_pCtx, ik, ck);
  54. }
  55. tipsec_error_t IPSecCtx::setRemote(tipsec_spi_t spi_pc, tipsec_spi_t spi_ps, tipsec_port_t port_pc, tipsec_port_t port_ps, tipsec_lifetime_t lifetime)
  56. {
  57. return tipsec_ctx_set_remote(m_pCtx, spi_pc, spi_ps, port_pc, port_ps, lifetime);
  58. }
  59. tipsec_error_t IPSecCtx::stop()
  60. {
  61. return tipsec_ctx_stop(m_pCtx);
  62. }
  63. tipsec_spi_t IPSecCtx::getSpiUC()
  64. {
  65. return m_pCtx->spi_uc;
  66. }
  67. tipsec_spi_t IPSecCtx::getSpiUS()
  68. {
  69. return m_pCtx->spi_us;
  70. }
  71. tipsec_spi_t IPSecCtx::getSpiPC()
  72. {
  73. return m_pCtx->spi_pc;
  74. }
  75. tipsec_spi_t IPSecCtx::getSpiPS()
  76. {
  77. return m_pCtx->spi_ps;
  78. }