bool clSSH::LoginPublicKey(bool throwExc) { if(!m_session) { THROW_OR_FALSE("NULL SSH session"); } int rc; rc = ssh_userauth_autopubkey(m_session, NULL); if(rc != SSH_AUTH_SUCCESS) { THROW_OR_FALSE(wxString() << _("Public Key error: ") << ssh_get_error(m_session)); } return true; }
bool clSSH::LoginPassword(bool throwExc) { if(!m_session) { THROW_OR_FALSE("NULL SSH session"); } int rc; // interactive keyboard method failed, try another method rc = ssh_userauth_password(m_session, NULL, GetPassword().mb_str().data()); if(rc == SSH_AUTH_SUCCESS) { return true; } else if(rc == SSH_AUTH_DENIED) { THROW_OR_FALSE("Login failed: invalid username/password"); } else { THROW_OR_FALSE(wxString() << _("Authentication error: ") << ssh_get_error(m_session)); } return false; }
bool clSSH::LoginInteractiveKBD(bool throwExc) throw(clException) { if(!m_session) { THROW_OR_FALSE("NULL SSH session"); } int rc; rc = ssh_userauth_kbdint(m_session, NULL, NULL); if(rc == SSH_AUTH_INFO) { while(rc == SSH_AUTH_INFO) { const char* name, *instruction; int nprompts, iprompt; name = ssh_userauth_kbdint_getname(m_session); instruction = ssh_userauth_kbdint_getinstruction(m_session); nprompts = ssh_userauth_kbdint_getnprompts(m_session); wxUnusedVar(name); wxUnusedVar(instruction); for(iprompt = 0; iprompt < nprompts; iprompt++) { const char* prompt; char echo; prompt = ssh_userauth_kbdint_getprompt(m_session, iprompt, &echo); if(echo) { wxString answer = ::wxGetTextFromUser(prompt, "SSH"); if(answer.IsEmpty()) { THROW_OR_FALSE(wxString() << "Login error: " << ssh_get_error(m_session)); } if(ssh_userauth_kbdint_setanswer(m_session, iprompt, answer.mb_str(wxConvUTF8).data()) < 0) { THROW_OR_FALSE(wxString() << "Login error: " << ssh_get_error(m_session)); } } else { if(ssh_userauth_kbdint_setanswer(m_session, iprompt, GetPassword().mb_str(wxConvUTF8).data()) < 0) { THROW_OR_FALSE(wxString() << "Login error: " << ssh_get_error(m_session)); } } } rc = ssh_userauth_kbdint(m_session, NULL, NULL); } return true; // success } THROW_OR_FALSE("Interactive Keyboard is not enabled for this server"); return false; }