\see: https://api.libssh.org/stable/libssh_tutor_authentication.html
| 372 | |
| 373 | //! \see: https://api.libssh.org/stable/libssh_tutor_authentication.html |
| 374 | int CChannelSSH::authentication( |
| 375 | ssh_session session, |
| 376 | const QString szUser, |
| 377 | const QString szPassword, |
| 378 | const QString szPassphrase, |
| 379 | const int nMethod) |
| 380 | { |
| 381 | int nRet = 0; |
| 382 | int nServerMethod = nMethod; |
| 383 | |
| 384 | qDebug(log) << "Authentication method:" << nMethod; |
| 385 | //* Get authentication list from ssh server |
| 386 | nRet = ssh_userauth_none(session, |
| 387 | szUser.toStdString().c_str()); |
| 388 | qDebug(log) << "ssh_userauth_none:" << nRet; |
| 389 | if(SSH_AUTH_SUCCESS == nRet) |
| 390 | return 0; |
| 391 | |
| 392 | char *banner = nullptr; |
| 393 | banner = ssh_get_issue_banner(session); |
| 394 | if (banner) |
| 395 | { |
| 396 | qInfo(log) << "banner:" << banner; |
| 397 | free(banner); |
| 398 | } |
| 399 | |
| 400 | nServerMethod = ssh_userauth_list(session, |
| 401 | szUser.toStdString().c_str()); |
| 402 | qDebug(log) << "ssh_userauth_list:" << nServerMethod; |
| 403 | //*/ |
| 404 | |
| 405 | if(nServerMethod & nMethod & SSH_AUTH_METHOD_PUBLICKEY) { |
| 406 | auto &user = m_pParameter->m_Net.m_User; |
| 407 | if(user.GetUseSystemFile()) { |
| 408 | qDebug(log) << "User authentication with ssh_userauth_publickey_auto"; |
| 409 | nRet = ssh_userauth_publickey_auto(session, |
| 410 | szUser.toStdString().c_str(), |
| 411 | szPassphrase.toStdString().c_str()); |
| 412 | if(SSH_AUTH_SUCCESS == nRet) |
| 413 | return 0; |
| 414 | QString szErr = tr("SSH failed: Failed authenticating with publickey:") |
| 415 | + ssh_get_error(m_Session); |
| 416 | qCritical(log) << szErr; |
| 417 | setErrorString(szErr); |
| 418 | } else { |
| 419 | qDebug(log) << "User authentication with publickey"; |
| 420 | nRet = authenticationPublicKey( |
| 421 | m_Session, |
| 422 | user.GetUser(), |
| 423 | user.GetPublicKeyFile(), |
| 424 | user.GetPrivateKeyFile(), |
| 425 | user.GetPassphrase()); |
| 426 | if(SSH_AUTH_SUCCESS == nRet) |
| 427 | return 0; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | if(nServerMethod & nMethod & SSH_AUTH_METHOD_PASSWORD) { |
nothing calls this directly
no test coverage detected