Example #1
0
static PyObject *
session_method_pref(SSH2_SessionObj *self, PyObject *args)
{
	int ret;
	int method;
	char *pref;

	if (!PyArg_ParseTuple(args, "is:method_pref", &method, &pref))
		return NULL;

	ret = libssh2_session_method_pref(self->session, method, pref);

	CHECK_RETURN_CODE(ret, self)

	Py_RETURN_NONE;
}
Example #2
0
/* {{{ php_ssh2_set_method
 * Try to set a method if it's passed in with the hash table
 */
static int php_ssh2_set_method(LIBSSH2_SESSION *session, HashTable *ht, char *method, int method_len, int method_type)
{
	zval *value;
	zend_string *method_zstring;


	method_zstring = zend_string_init(method, method_len, 0);
	if ((value = zend_hash_find(ht, method_zstring)) == NULL) {
		zend_string_release(method_zstring);
		return 0;
	}
	zend_string_release(method_zstring);

	if ((Z_TYPE_P(value) != IS_STRING)) {
		return -1;
	}

	return libssh2_session_method_pref(session, method_type, Z_STRVAL_P(value));
}
static int
ssh_client_profile_set(obfsproxyssh_client_session_t *session)
{
	obfsproxyssh_t *state = session->client->state;
	const obfsproxyssh_client_profile_t *profile = ssh_client_profile_current;
	int i, rval;

	assert(NULL != profile);

	rval = libssh2_banner_set(session->ssh_session, profile->banner);
	if (0 != rval) {
		log_f(state, "SSH: Error: %s Failed to set banner %d",
				bdata(session->ssh_addr), rval);
	}

	libssh2_session_flag(session->ssh_session, LIBSSH2_FLAG_COMPRESS,
			profile->enable_compression);

	/*
	 * Failure to set things to exactly what I specify should be a
	 * immediate and fatal error as the lists in the profiles are chosen
	 * carefully to match existing client(s) in the wild, but see the
	 * comments in ssh_client_profile_init().
	 */

	for (i = 0; i <= LIBSSH2_METHOD_LANG_SC; i++) {
		/* Trying to force a value to NULL, causes libssh2 to SIGSEGV */
		if (NULL == profile->kex_methods[i])
			continue;

		rval = libssh2_session_method_pref(session->ssh_session, i,
				profile->kex_methods[i]);
		if (0 != rval) {
			log_f(state, "SSH: Error: %s Failed to set prefered methods %d (%d)",
					bdata(session->ssh_addr), i, rval);
			return -1;
		}
	}

	return 0;
}