provider.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Kamailio osp module.
  3. *
  4. * This module enables Kamailio to communicate with an Open Settlement
  5. * Protocol (OSP) server. The Open Settlement Protocol is an ETSI
  6. * defined standard for Inter-Domain VoIP pricing, authorization
  7. * and usage exchange. The technical specifications for OSP
  8. * (ETSI TS 101 321 V4.1.1) are available at www.etsi.org.
  9. *
  10. * Uli Abend was the original contributor to this module.
  11. *
  12. * Copyright (C) 2001-2005 Fhg Fokus
  13. *
  14. * This file is part of Kamailio, a free SIP server.
  15. *
  16. * Kamailio is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2 of the License, or
  19. * (at your option) any later version
  20. *
  21. * Kamailio is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  29. */
  30. #include <osp/osp.h>
  31. #include <osp/osputils.h>
  32. #include "../../dprint.h"
  33. #include "provider.h"
  34. extern unsigned int _osp_sp_number;
  35. extern char* _osp_sp_uris[];
  36. extern unsigned long _osp_sp_weights[];
  37. extern unsigned char* _osp_private_key;
  38. extern unsigned char* _osp_local_certificate;
  39. extern unsigned char* _osp_ca_certificate;
  40. extern int _osp_ssl_lifetime;
  41. extern int _osp_persistence;
  42. extern int _osp_retry_delay;
  43. extern int _osp_retry_limit;
  44. extern int _osp_timeout;
  45. extern int _osp_crypto_hw;
  46. extern OSPTPROVHANDLE _osp_provider;
  47. /*
  48. * Create a new OSP provider object per process
  49. * return 0 success, others failure
  50. */
  51. int ospSetupProvider(void)
  52. {
  53. OSPTPRIVATEKEY privatekey;
  54. OSPTCERT localcert;
  55. OSPTCERT cacert;
  56. OSPTCERT* cacerts[1];
  57. int result;
  58. cacerts[0] = &cacert;
  59. if ((result = OSPPInit(_osp_crypto_hw)) != 0) {
  60. LM_ERR("failed to initalize OSP (%d)\n", result);
  61. } else if (OSPPUtilLoadPEMPrivateKey(_osp_private_key, &privatekey) != 0) {
  62. LM_ERR("failed to load private key from '%s'\n", _osp_private_key);
  63. } else if (OSPPUtilLoadPEMCert(_osp_local_certificate, &localcert) != 0) {
  64. LM_ERR("failed to load local certificate from '%s'\n",_osp_local_certificate);
  65. } else if (OSPPUtilLoadPEMCert(_osp_ca_certificate, &cacert) != 0) {
  66. LM_ERR("failed to load CA certificate from '%s'\n", _osp_ca_certificate);
  67. } else {
  68. result = OSPPProviderNew(
  69. _osp_sp_number,
  70. (const char**)_osp_sp_uris,
  71. _osp_sp_weights,
  72. "http://localhost:1234",
  73. &privatekey,
  74. &localcert,
  75. 1,
  76. (const OSPTCERT**)cacerts,
  77. 1,
  78. _osp_ssl_lifetime,
  79. _osp_sp_number,
  80. _osp_persistence,
  81. _osp_retry_delay,
  82. _osp_retry_limit,
  83. _osp_timeout,
  84. "",
  85. "",
  86. &_osp_provider);
  87. if (result != 0) {
  88. LM_ERR("failed to create provider (%d)\n", result);
  89. } else {
  90. LM_DBG("created new (per process) provider '%d'\n", _osp_provider);
  91. result = 0;
  92. }
  93. }
  94. /*
  95. * Free space allocated while loading crypto information from PEM-encoded files.
  96. * There are some problems to free the memory, do not free them
  97. */
  98. if (privatekey.PrivateKeyData != NULL) {
  99. //free(privatekey.PrivateKeyData);
  100. }
  101. if (localcert.CertData != NULL) {
  102. //free(localcert.CertData);
  103. }
  104. if (cacert.CertData != NULL) {
  105. //free(localcert.CertData);
  106. }
  107. return result;
  108. }
  109. /*
  110. * Erase OSP provider object
  111. * return 0 success, others failure
  112. */
  113. int ospDeleteProvider(void)
  114. {
  115. int result;
  116. if ((result = OSPPProviderDelete(_osp_provider, 0)) != 0) {
  117. LM_ERR("failed to erase provider '%d' (%d)\n", _osp_provider, result);
  118. }
  119. return result;
  120. }