コード例 #1
0
int export_key(gpgme_data_t *out, char *key_id, GPG_CTX *gpg_ctx)
{
	// validation
	if (key_id == NULL)
		error_ret("Key to connect with is required\n", ERROR_BAD_INPUT);

	gpgme_key_t key;
	int ret;
	bool confirm;
	gpgme_error_t err;

	// find key to register
	ret = GPG_get_key(gpg_ctx, key_id, &key);
	if (is_failure(ret))
		error_ret("Could not corresponding key\n", ERROR_GPGME);

	printf("Going to connect with %s (%s <%s>)\n", 
			key->subkeys->keyid,
			key->uids->name,
			key->uids->email
			);

	// ensure key is valid
	if (!key->can_encrypt || key->revoked || key->disabled || key->expired)
		error_ret("This key cannot be used\n", ERROR_GPGME);

	// confirm
	confirm = request_confirmation("OK to proceed?");
	if (!confirm)
	{
		puts("Aborting");
		return ERROR_USER_ABORT;
	}

	// get key
	err = gpgme_data_new(out);
	if (gpg_err_code(err) != GPG_ERR_NO_ERROR)
		error_ret("Failed to allocate key buffer\n", ERROR_GPGME);

	ret = GPG_export(gpg_ctx, key, *out);
	if (is_failure(ret))
		error_ret("Failed to export key\n", ERROR_GPGME);

	return ERROR_NO_ERROR;
}
コード例 #2
0
ファイル: ieee80211_amrr.c プロジェクト: mariuz/haiku
static int
amrr_update(struct ieee80211_amrr *amrr, struct ieee80211_amrr_node *amn,
    struct ieee80211_node *ni)
{
	int rix = amn->amn_rix;

	KASSERT(is_enough(amn), ("txcnt %d", amn->amn_txcnt));

	if (is_success(amn)) {
		amn->amn_success++;
		if (amn->amn_success >= amn->amn_success_threshold &&
		    rix + 1 < ni->ni_rates.rs_nrates) {
			amn->amn_recovery = 1;
			amn->amn_success = 0;
			rix++;
			IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni,
			    "AMRR increasing rate %d (txcnt=%d retrycnt=%d)",
			    ni->ni_rates.rs_rates[rix] & IEEE80211_RATE_VAL,
			    amn->amn_txcnt, amn->amn_retrycnt);
		} else {
			amn->amn_recovery = 0;
		}
	} else if (is_failure(amn)) {
		amn->amn_success = 0;
		if (rix > 0) {
			if (amn->amn_recovery) {
				amn->amn_success_threshold *= 2;
				if (amn->amn_success_threshold >
				    amrr->amrr_max_success_threshold)
					amn->amn_success_threshold =
					    amrr->amrr_max_success_threshold;
			} else {
				amn->amn_success_threshold =
				    amrr->amrr_min_success_threshold;
			}
			rix--;
			IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni,
			    "AMRR decreasing rate %d (txcnt=%d retrycnt=%d)",
			    ni->ni_rates.rs_rates[rix] & IEEE80211_RATE_VAL,
			    amn->amn_txcnt, amn->amn_retrycnt);
		}
		amn->amn_recovery = 0;
	}

	/* reset counters */
	amn->amn_txcnt = 0;
	amn->amn_retrycnt = 0;

	return rix;
}
コード例 #3
0
int do_action_connect(struct client_settings *settings, GPG_CTX *gpg_ctx)
{
	gpgme_data_t key;
	int ret;

	// get key
	ret = export_key(&key, settings->key, gpg_ctx);
	if (is_failure(ret))
		return ret;

	// send to server
	ret = send_to_server(key, settings->host, settings->host_port, gpg_ctx);
	if (ret != ERROR_NO_ERROR)
		return ret;

	return ERROR_NO_ERROR;
}
コード例 #4
0
ファイル: server.c プロジェクト: DomWilliams0/gpg-chat
void *client_handler(void *client_ctx)
{
	struct client *client;
	char op[OP_LENGTH + 1] = {0};
	int ret;

	client = (struct client *)client_ctx;

	// read op code and execute action
	SSL_read(client->ssl, op, OP_LENGTH);
	ret = handle_server_action(client->settings, client->ssl, op);

	if (is_failure(ret))
		error_print("Failed to handle server action\n");

	// close connection
	SSL_shutdown(client->ssl);
	SSL_free(client->ssl);
	puts("Closed connection");

	// TODO: return error code instead
	return NULL;
}
コード例 #5
0
ファイル: server.c プロジェクト: DomWilliams0/gpg-chat
int main(int argc, char **argv)
{
	int ret;
	struct server_settings settings;

	// load arguments
	ret = parse_server_settings(argc, (char **) argv, &settings);

	if (is_failure(ret))
	{
		print_usage;
		return ret;
	}

	int sock;
	SSL_CTX *ssl_ctx;
	SSL *ssl;
	pthread_t thread_id;
	struct client client = {&settings, NULL};

	// init ssl
	if (is_failure(init_ssl(&ssl_ctx, NULL, settings.cert_path, settings.key_path)))
		goto GENERAL_CLEAN_UP;

	sock = create_server_socket(settings.port);

	printf("Listening on port %d\n", settings.port);
	register_signal_handler();

	while (server_running)
	{
		struct sockaddr_in addr;
		uint len = sizeof addr;

		int client_sock = accept(sock, (struct sockaddr *) &addr, &len);
		if (client_sock < 0)
		{
			// not clean
			if (server_running)
			{
				error_print("Failed to accept client connection\n");
				ret = ERROR_SOCKET;
			}

			break;
		}

		puts("Client connected");
		if (is_failure(accept_ssl(ssl_ctx, &ssl, client_sock)))
			continue;

		// spawn thread
		client.ssl = ssl;
		if (pthread_create(&thread_id, NULL, client_handler, (void *) &client) < 0)
			error_print("Failed to spawn client thread\n");
	}


GENERAL_CLEAN_UP:
	puts("\nCleaning up");

	if (ssl_ctx != NULL)
		SSL_CTX_free(ssl_ctx);

	ERR_free_strings();
	EVP_cleanup();

	return ret;
}
コード例 #6
0
/*
 * Examine and potentially adjust the transmit rate.
 */
static void
ath_rate_ctl(void *arg, struct ieee80211_node *ni)
{
    struct ath_softc *sc = arg;
    struct amrr_node *amn = ATH_NODE_AMRR(ATH_NODE (ni));
    int rix;

#define is_success(amn) \
(amn->amn_tx_try1_cnt  < (amn->amn_tx_try0_cnt/10))
#define is_enough(amn) \
(amn->amn_tx_try0_cnt > 10)
#define is_failure(amn) \
(amn->amn_tx_try1_cnt > (amn->amn_tx_try0_cnt/3))

    rix = amn->amn_rix;

    IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni,
                   "cnt0: %d cnt1: %d cnt2: %d cnt3: %d -- threshold: %d",
                   amn->amn_tx_try0_cnt, amn->amn_tx_try1_cnt, amn->amn_tx_try2_cnt,
                   amn->amn_tx_try3_cnt, amn->amn_success_threshold);
    if (is_success (amn) && is_enough (amn)) {
        amn->amn_success++;
        if (amn->amn_success == amn->amn_success_threshold &&
                rix + 1 < ni->ni_rates.rs_nrates) {
            amn->amn_recovery = 1;
            amn->amn_success = 0;
            rix++;
            IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni,
                           "increase rate to %d", rix);
        } else {
            amn->amn_recovery = 0;
        }
    } else if (is_failure (amn)) {
        amn->amn_success = 0;
        if (rix > 0) {
            if (amn->amn_recovery) {
                /* recovery failure. */
                amn->amn_success_threshold *= 2;
                amn->amn_success_threshold = min (amn->amn_success_threshold,
                                                  (u_int)ath_rate_max_success_threshold);
                IEEE80211_NOTE(ni->ni_vap,
                               IEEE80211_MSG_RATECTL, ni,
                               "decrease rate recovery thr: %d",
                               amn->amn_success_threshold);
            } else {
                /* simple failure. */
                amn->amn_success_threshold = ath_rate_min_success_threshold;
                IEEE80211_NOTE(ni->ni_vap,
                               IEEE80211_MSG_RATECTL, ni,
                               "decrease rate normal thr: %d",
                               amn->amn_success_threshold);
            }
            amn->amn_recovery = 0;
            rix--;
        } else {
            amn->amn_recovery = 0;
        }

    }
    if (is_enough (amn) || rix != amn->amn_rix) {
        /* reset counters. */
        amn->amn_tx_try0_cnt = 0;
        amn->amn_tx_try1_cnt = 0;
        amn->amn_tx_try2_cnt = 0;
        amn->amn_tx_try3_cnt = 0;
        amn->amn_tx_failure_cnt = 0;
    }
    if (rix != amn->amn_rix) {
        ath_rate_update(sc, ni, rix);
    }
}
コード例 #7
0
/* 
 * Examine and potentially adjust the transmit rate.
 */
static void
ath_rate_ctl(void *arg, struct ieee80211_node *ni)
{
	struct ath_softc *sc = arg;
	struct amrr_node *amn = ATH_NODE_AMRR(ATH_NODE (ni));
	int old_rate;

#define is_success(amn) \
(amn->amn_tx_try1_cnt  < (amn->amn_tx_try0_cnt/10))
#define is_enough(amn) \
(amn->amn_tx_try0_cnt > 10)
#define is_failure(amn) \
(amn->amn_tx_try1_cnt > (amn->amn_tx_try0_cnt/3))
#define is_max_rate(ni) \
((ni->ni_txrate + 1) >= ni->ni_rates.rs_nrates)
#define is_min_rate(ni) \
(ni->ni_txrate == 0)

	old_rate = ni->ni_txrate;
  
  	DPRINTF (sc, "cnt0: %d cnt1: %d cnt2: %d cnt3: %d -- threshold: %d\n",
		 amn->amn_tx_try0_cnt,
		 amn->amn_tx_try1_cnt,
		 amn->amn_tx_try2_cnt,
		 amn->amn_tx_try3_cnt,
		 amn->amn_success_threshold);
  	if (is_success (amn) && is_enough (amn)) {
		amn->amn_success++;
		if (amn->amn_success == amn->amn_success_threshold &&
  		    !is_max_rate (ni)) {
  			amn->amn_recovery = 1;
  			amn->amn_success = 0;
  			ni->ni_txrate++;
			DPRINTF (sc, "increase rate to %d\n", ni->ni_txrate);
  		} else {
			amn->amn_recovery = 0;
		}
  	} else if (is_failure (amn)) {
  		amn->amn_success = 0;
  		if (!is_min_rate (ni)) {
  			if (amn->amn_recovery) {
  				/* recovery failure. */
  				amn->amn_success_threshold *= 2;
  				amn->amn_success_threshold = min (amn->amn_success_threshold,
								  (u_int)ath_rate_max_success_threshold);
 				DPRINTF (sc, "decrease rate recovery thr: %d\n", amn->amn_success_threshold);
  			} else {
  				/* simple failure. */
 				amn->amn_success_threshold = ath_rate_min_success_threshold;
 				DPRINTF (sc, "decrease rate normal thr: %d\n", amn->amn_success_threshold);
  			}
			amn->amn_recovery = 0;
  			ni->ni_txrate--;
   		} else {
			amn->amn_recovery = 0;
		}

   	}
	if (is_enough (amn) || old_rate != ni->ni_txrate) {
		/* reset counters. */
		amn->amn_tx_try0_cnt = 0;
		amn->amn_tx_try1_cnt = 0;
		amn->amn_tx_try2_cnt = 0;
		amn->amn_tx_try3_cnt = 0;
		amn->amn_tx_failure_cnt = 0;
	}
	if (old_rate != ni->ni_txrate) {
		ath_rate_update(sc, ni, ni->ni_txrate);
	}
}
コード例 #8
0
static int
amrr_update(struct ieee80211_amrr *amrr, struct ieee80211_amrr_node *amn,
    struct ieee80211_node *ni)
{
	int rix = amn->amn_rix;
	const struct ieee80211_rateset *rs = NULL;

	KASSERT(is_enough(amn), ("txcnt %d", amn->amn_txcnt));

	rs = ieee80211_ratectl_get_rateset(ni);


	IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni,
	    "%s: AMRR: current rate %d, txcnt=%d, retrycnt=%d",
	    __func__, rs->rs_rates[rix] & IEEE80211_RATE_VAL,
	    amn->amn_txcnt,
	    amn->amn_retrycnt);

	/*
	 * XXX This is totally bogus for 11n, as although high MCS
	 * rates for each stream may be failing, the next stream
	 * should be checked.
	 *
	 * Eg, if MCS5 is ok but MCS6/7 isn't, and we can go up to
	 * MCS23, we should skip 6/7 and try 8 onwards.
	 */
	if (is_success(amn)) {
		amn->amn_success++;
		if (amn->amn_success >= amn->amn_success_threshold &&
		    rix + 1 < rs->rs_nrates) {
			amn->amn_recovery = 1;
			amn->amn_success = 0;
			rix++;
			IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni,
			    "%s: AMRR increasing rate %d (txcnt=%d retrycnt=%d)",
			    __func__, rs->rs_rates[rix] & IEEE80211_RATE_VAL,
			    amn->amn_txcnt, amn->amn_retrycnt);
		} else {
			amn->amn_recovery = 0;
		}
	} else if (is_failure(amn)) {
		amn->amn_success = 0;
		if (rix > 0) {
			if (amn->amn_recovery) {
				amn->amn_success_threshold *= 2;
				if (amn->amn_success_threshold >
				    amrr->amrr_max_success_threshold)
					amn->amn_success_threshold =
					    amrr->amrr_max_success_threshold;
			} else {
				amn->amn_success_threshold =
				    amrr->amrr_min_success_threshold;
			}
			rix--;
			IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni,
			    "%s: AMRR decreasing rate %d (txcnt=%d retrycnt=%d)",
			    __func__, rs->rs_rates[rix] & IEEE80211_RATE_VAL,
			    amn->amn_txcnt, amn->amn_retrycnt);
		}
		amn->amn_recovery = 0;
	}

	/* reset counters */
	amn->amn_txcnt = 0;
	amn->amn_retrycnt = 0;

	return rix;
}