Beispiel #1
0
static int get_cipher_list(void) {
    pj_status_t status;
    pj_ssl_cipher ciphers[100];
    unsigned cipher_num;
    unsigned i;

    cipher_num = PJ_ARRAY_SIZE(ciphers);
    status = pj_ssl_cipher_get_availables(ciphers, &cipher_num);
    if (status != PJ_SUCCESS) {
	app_perror("...FAILED to get available ciphers", status);
	return status;
    }

    PJ_LOG(3, ("", "...Found %u ciphers:", cipher_num));
    for (i = 0; i < cipher_num; ++i) {
	const char* st;
	st = pj_ssl_cipher_name(ciphers[i]);
	if (st == NULL)
	    st = "[Unknown]";

	PJ_LOG(3, ("", "...%3u: 0x%08x=%s", i+1, ciphers[i], st));
    }

    return PJ_SUCCESS;
}
Beispiel #2
0
static char *handle_pjsip_list_ciphers(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
	pj_ssl_cipher ciphers[100];
	unsigned int cipher_num = PJ_ARRAY_SIZE(ciphers);
	char *buf;

	switch (cmd) {
	case CLI_INIT:
		e->command = "pjsip list ciphers";
		e->usage = "Usage: pjsip list ciphers\n"
			"       List available OpenSSL cipher names.\n";
		return NULL;
	case CLI_GENERATE:
		return NULL;
	}

	if (pj_ssl_cipher_get_availables(ciphers, &cipher_num) || !cipher_num) {
		buf = NULL;
	} else {
		cipher_to_str(&buf, ciphers, cipher_num);
	}

	if (!ast_strlen_zero(buf)) {
		ast_cli(a->fd, "Available ciphers: '%s'\n", buf);
	} else {
		ast_cli(a->fd, "No available ciphers\n");
	}
	ast_free(buf);
	return CLI_SUCCESS;
}
/* Check if the specified cipher is supported by SSL/TLS backend. */
PJ_DEF(pj_bool_t) pj_ssl_cipher_is_supported(pj_ssl_cipher cipher)
{
    unsigned i;

    if (ciphers_num_ == 0) {
	pj_ssl_cipher c[1];
	i = 0;
	pj_ssl_cipher_get_availables(c, &i);
    }
	
    for (i = 0; i < ciphers_num_; ++i) {
	if (cipher == ciphers_[i].id)
	    return PJ_TRUE;
    }

    return PJ_FALSE;
}
/* Get cipher identifier */
PJ_DEF(pj_ssl_cipher) pj_ssl_cipher_id(const char *cipher_name)
{
    unsigned i;
    
    if (ciphers_num_ == 0) {
	pj_ssl_cipher c[1];
	i = 0;
	pj_ssl_cipher_get_availables(c, &i);
    }
    
    for (i = 0; i < ciphers_num_; ++i) {
        if (!pj_ansi_stricmp(ciphers_[i].name, cipher_name))
            return ciphers_[i].id;
    }

    return PJ_TLS_UNKNOWN_CIPHER;
}
/* Get cipher name string */
PJ_DEF(const char*) pj_ssl_cipher_name(pj_ssl_cipher cipher)
{
    unsigned i;

    if (ciphers_num_ == 0) {
	pj_ssl_cipher c[1];
	i = 0;
	pj_ssl_cipher_get_availables(c, &i);
    }
	
    for (i = 0; i < ciphers_num_; ++i) {
	if (cipher == ciphers_[i].id)
	    return ciphers_[i].name;
    }

    return NULL;
}
Beispiel #6
0
/*! \brief Helper function which turns a cipher name into an identifier */
static pj_ssl_cipher cipher_name_to_id(const char *name)
{
	pj_ssl_cipher ciphers[100];
	pj_ssl_cipher id = 0;
	unsigned int cipher_num = PJ_ARRAY_SIZE(ciphers);
	int pos;
	const char *pos_name;

	if (pj_ssl_cipher_get_availables(ciphers, &cipher_num)) {
		return 0;
	}

	for (pos = 0; pos < cipher_num; ++pos) {
		pos_name = pj_ssl_cipher_name(ciphers[pos]);
		if (!pos_name || strcmp(pos_name, name)) {
			continue;
		}

		id = ciphers[pos];
		break;
	}

	return id;
}