static int config_load(void) { struct cw_config *cfg; char *cat; struct osp_provider *osp, *prev = NULL, *next; cw_mutex_lock(&osplock); osp = providers; while(osp) { osp->dead = 1; osp = osp->next; } cw_mutex_unlock(&osplock); cfg = cw_config_load("osp.conf"); if (cfg) { if (!initialized) { cat = cw_variable_retrieve(cfg, "general", "accelerate"); if (cat && cw_true(cat)) if (OSPPInit(1)) { cw_log(LOG_WARNING, "Failed to enable hardware accelleration, falling back to software mode\n"); OSPPInit(0); } else hardware = 1; else OSPPInit(0); initialized = 1; } cat = cw_variable_retrieve(cfg, "general", "tokenformat"); if (cat) { if ((sscanf(cat, "%d", &tokenformat) != 1) || (tokenformat < TOKEN_ALGO_SIGNED) || (tokenformat > TOKEN_ALGO_BOTH)) { tokenformat = TOKEN_ALGO_SIGNED; cw_log(LOG_WARNING, "tokenformat should be an integer from 0 to 2, not '%s'\n", cat); } } cat = cw_category_browse(cfg, NULL); while(cat) { if (strcasecmp(cat, "general")) osp_build(cfg, cat); cat = cw_category_browse(cfg, cat); } cw_config_destroy(cfg); } else cw_log(LOG_NOTICE, "No OSP configuration found. OSP support disabled\n"); cw_mutex_lock(&osplock); osp = providers; while(osp) { next = osp->next; if (osp->dead) { if (prev) prev->next = next; else providers = next; /* XXX Cleanup OSP structure first XXX */ free(osp); } else prev = osp; osp = next; } cw_mutex_unlock(&osplock); return 0; }
/* * Create a new OSP provider object per process * return 0 success, others failure */ int ospSetupProvider(void) { OSPTPRIVATEKEY privatekey; OSPTCERT localcert; OSPTCERT cacert; OSPTCERT* cacerts[1]; int result; cacerts[0] = &cacert; if ((result = OSPPInit(_osp_crypto_hw)) != 0) { LM_ERR("failed to initalize OSP (%i)\n", result); } else if (OSPPUtilLoadPEMPrivateKey(_osp_private_key, &privatekey) != 0) { LM_ERR("failed to load private key from '%s'\n", _osp_private_key); } else if (OSPPUtilLoadPEMCert(_osp_local_certificate, &localcert) != 0) { LM_ERR("failed to load local certificate from '%s'\n",_osp_local_certificate); } else if (OSPPUtilLoadPEMCert(_osp_ca_certificate, &cacert) != 0) { LM_ERR("failed to load CA certificate from '%s'\n", _osp_ca_certificate); } else { result = OSPPProviderNew( _osp_sp_number, (const char**)_osp_sp_uris, _osp_sp_weights, "http://localhost:1234", &privatekey, &localcert, 1, (const OSPTCERT**)cacerts, 1, _osp_ssl_lifetime, _osp_sp_number, _osp_persistence, _osp_retry_delay, _osp_retry_limit, _osp_timeout, "", "", &_osp_provider); if (result != 0) { LM_ERR("failed to create provider (%i)\n", result); } else { LM_DBG("created new (per process) provider '%d'\n", _osp_provider); result = 0; } } /* * Free space allocated while loading crypto information from PEM-encoded files. * There are some problems to free the memory, do not free them */ if (privatekey.PrivateKeyData != NULL) { //free(privatekey.PrivateKeyData); } if (localcert.CertData != NULL) { //free(localcert.CertData); } if (cacert.CertData != NULL) { //free(localcert.CertData); } return result; }