int main(void) { tls_client_t client = {0}; const char *gnutls_ver = NULL; time_t start = 0; time_t end = 0; int ret = 0; int i = 0; /* initialise signal handling */ set_signal(); coap_log_set_level(COAP_LOG_DEBUG); gnutls_ver = gnutls_check_version(NULL); if (gnutls_ver == NULL) { coap_log_error("Unable to determine GnuTLS version"); return EXIT_FAILURE; } coap_log_info("GnuTLS version: %s", gnutls_ver); ret = tls_init(); if (ret != SOCK_OK) { coap_log_error("%s", sock_strerror(ret)); return EXIT_FAILURE; } ret = tls_client_create(&client, TRUST_FILE_NAME, CERT_FILE_NAME, KEY_FILE_NAME); if (ret != SOCK_OK) { coap_log_error("%s", sock_strerror(ret)); tls_deinit(); return EXIT_FAILURE; } for (i = 0; i < NUM_ITER; i++) { start = time(NULL); ret = client_run(&client); end = time(NULL); if (ret != SOCK_OK) { coap_log_error("%s", sock_strerror(ret)); tls_client_destroy(&client); tls_deinit(); return EXIT_FAILURE; } coap_log_info("Result: %s", sock_strerror(ret)); coap_log_debug("Time: %d sec", (int)(end - start)); coap_log_debug("Sleeping for %d seconds...", DELAY); sleep(DELAY); } tls_client_destroy(&client); tls_deinit(); return EXIT_SUCCESS; }
void * tls_init(const struct tls_config *conf) { struct tls_global *global; #ifdef GNUTLS_INTERNAL_STRUCTURE_HACK /* Because of the horrible hack to get master_secret and client/server * random, we need to make sure that the gnutls version is something * that is expected to have same structure definition for the session * data.. */ const char *ver; const char *ok_ver[] = { "1.2.3", "1.2.4", "1.2.5", "1.2.6", "1.2.9", "1.3.2", NULL }; int i; #endif /* GNUTLS_INTERNAL_STRUCTURE_HACK */ global = os_zalloc(sizeof(*global)); if (global == NULL) return NULL; if (tls_gnutls_ref_count == 0 && gnutls_global_init() < 0) { os_free(global); return NULL; } tls_gnutls_ref_count++; #ifdef GNUTLS_INTERNAL_STRUCTURE_HACK ver = gnutls_check_version(NULL); if (ver == NULL) { tls_deinit(global); return NULL; } wpa_printf(MSG_DEBUG, "%s - gnutls version %s", __func__, ver); for (i = 0; ok_ver[i]; i++) { if (strcmp(ok_ver[i], ver) == 0) break; } if (ok_ver[i] == NULL) { wpa_printf(MSG_INFO, "Untested gnutls version %s - this needs " "to be tested and enabled in tls_gnutls.c", ver); tls_deinit(global); return NULL; } #endif /* GNUTLS_INTERNAL_STRUCTURE_HACK */ gnutls_global_set_log_function(tls_log_func); if (wpa_debug_show_keys) gnutls_global_set_log_level(11); return global; }
void eap_sm_deinit(struct eap_sm *sm) { if (sm == NULL) return; eap_deinit_prev_method(sm, "EAP deinit"); free(sm->lastRespData); free(sm->eapRespData); free(sm->eapKeyData); tls_deinit(sm->ssl_ctx); free(sm); }
/* * delete all the allocated space by eap module */ static int mod_detach(void *instance) { rlm_eap_t *inst; inst = (rlm_eap_t *)instance; rbtree_free(inst->session_tree); inst->session_tree = NULL; eaplist_free(inst); eap_server_unregister_methods(); tls_deinit(inst->tls_ctx); pthread_mutex_destroy(&(inst->session_mutex)); return 0; }
void authsrv_deinit(struct hostapd_data *hapd) { #ifdef RADIUS_SERVER radius_server_deinit(hapd->radius_srv); hapd->radius_srv = NULL; #endif /* RADIUS_SERVER */ #ifdef EAP_TLS_FUNCS if (hapd->ssl_ctx) { tls_deinit(hapd->ssl_ctx); hapd->ssl_ctx = NULL; } #endif /* EAP_TLS_FUNCS */ #ifdef EAP_SIM_DB if (hapd->eap_sim_db_priv) { eap_sim_db_deinit(hapd->eap_sim_db_priv); hapd->eap_sim_db_priv = NULL; } #endif /* EAP_SIM_DB */ }
static void hostapd_cleanup(struct hostapd_data *hapd) { hostapd_ctrl_iface_deinit(hapd); free(hapd->default_wep_key); hapd->default_wep_key = NULL; iapp_deinit(hapd->iapp); accounting_deinit(hapd); wpa_deinit(hapd); #ifdef SIMPLE_CONFIG wsc_ie_deinit(hapd); #endif ieee802_1x_deinit(hapd); hostapd_acl_deinit(hapd); radius_client_deinit(hapd->radius); hapd->radius = NULL; radius_server_deinit(hapd->radius_srv); hapd->radius_srv = NULL; hostapd_wireless_event_deinit(hapd); if (hapd->driver) hostapd_driver_deinit(hapd); hostapd_config_free(hapd->conf); hapd->conf = NULL; free(hapd->config_fname); #ifdef EAP_TLS_FUNCS if (hapd->ssl_ctx) { tls_deinit(hapd->ssl_ctx); hapd->ssl_ctx = NULL; } #endif /* EAP_TLS_FUNCS */ if (hapd->eap_sim_db_priv) eap_sim_db_deinit(hapd->eap_sim_db_priv); }
static hostapd * hostapd_init(const char *config_file) { hostapd *hapd; hapd = malloc(sizeof(*hapd)); if (hapd == NULL) { printf("Could not allocate memory for hostapd data\n"); goto fail; } memset(hapd, 0, sizeof(*hapd)); hapd->config_fname = strdup(config_file); if (hapd->config_fname == NULL) { printf("Could not allocate memory for config_fname\n"); goto fail; } hapd->conf = hostapd_config_read(hapd->config_fname); if (hapd->conf == NULL) { goto fail; } if (hapd->conf->individual_wep_key_len > 0) { /* use key0 in individual key and key1 in broadcast key */ hapd->default_wep_key_idx = 1; } #ifdef EAP_TLS_FUNCS if (hapd->conf->eap_server && (hapd->conf->ca_cert || hapd->conf->server_cert)) { hapd->ssl_ctx = tls_init(NULL); if (hapd->ssl_ctx == NULL) { printf("Failed to initialize TLS\n"); goto fail; } if (tls_global_ca_cert(hapd->ssl_ctx, hapd->conf->ca_cert)) { printf("Failed to load CA certificate (%s)\n", hapd->conf->ca_cert); goto fail; } if (tls_global_client_cert(hapd->ssl_ctx, hapd->conf->server_cert)) { printf("Failed to load server certificate (%s)\n", hapd->conf->server_cert); goto fail; } if (tls_global_private_key(hapd->ssl_ctx, hapd->conf->private_key, hapd->conf->private_key_passwd)) { printf("Failed to load private key (%s)\n", hapd->conf->private_key); goto fail; } if (tls_global_set_verify(hapd->ssl_ctx, hapd->conf->check_crl)) { printf("Failed to enable check_crl\n"); goto fail; } } #endif /* EAP_TLS_FUNCS */ if (hapd->conf->eap_sim_db) { hapd->eap_sim_db_priv = eap_sim_db_init(hapd->conf->eap_sim_db); if (hapd->eap_sim_db_priv == NULL) { printf("Failed to initialize EAP-SIM database " "interface\n"); goto fail; } } if (hapd->conf->assoc_ap) hapd->assoc_ap_state = WAIT_BEACON; /* FIX: need to fix this const vs. not */ hapd->driver = (struct driver_ops *) hapd->conf->driver; return hapd; fail: if (hapd) { if (hapd->ssl_ctx) tls_deinit(hapd->ssl_ctx); if (hapd->conf) hostapd_config_free(hapd->conf); free(hapd->config_fname); free(hapd); } return NULL; }