static PyObject * session_userauth_publickey_fromfile(SSH2_SessionObj *self, PyObject *args) { char *username; char *publickey; char *privatekey; char *passphrase = ""; Py_ssize_t username_len; int ret; if (!PyArg_ParseTuple(args, "s#ss|s:userauth_publickey_fromfile", &username, &username_len, &publickey, &privatekey, &passphrase)) return NULL; Py_BEGIN_ALLOW_THREADS ret = libssh2_userauth_publickey_fromfile_ex(self->session, username, username_len, publickey, privatekey, passphrase); Py_END_ALLOW_THREADS CHECK_RETURN_CODE(ret, self) Py_RETURN_NONE; }
int test(LIBSSH2_SESSION *session) { int rc; const char *userauth_list = libssh2_userauth_list(session, USERNAME, strlen(USERNAME)); if(userauth_list == NULL) { print_last_session_error("libssh2_userauth_list"); return 1; } if(strstr(userauth_list, "publickey") == NULL) { fprintf(stderr, "'publickey' was expected in userauth list: %s\n", userauth_list); return 1; } rc = libssh2_userauth_publickey_fromfile_ex( session, USERNAME, strlen(USERNAME), KEY_FILE_PUBLIC, KEY_FILE_PRIVATE, NULL); if(rc == 0) { fprintf(stderr, "Public-key auth succeeded with wrong key\n"); return 1; } return 0; }