added error handling for key authentication
This commit is contained in:
parent
b3456ee96c
commit
ccfc9f2ad2
3 changed files with 14 additions and 8 deletions
|
|
@ -35,7 +35,7 @@ enum ErrorCode
|
||||||
|
|
||||||
// Ssh connection errors
|
// Ssh connection errors
|
||||||
SshRequsetDeniedError, SshInterruptedError, SshInternalError,
|
SshRequsetDeniedError, SshInterruptedError, SshInternalError,
|
||||||
SshPrivateKeyError,
|
SshPrivateKeyError, SshPrivateKeyFormatError,
|
||||||
|
|
||||||
// Ssh sftp errors
|
// Ssh sftp errors
|
||||||
SshSftpEofError, SshSftpNoSuchFileError, SshSftpPermissionDeniedError,
|
SshSftpEofError, SshSftpNoSuchFileError, SshSftpPermissionDeniedError,
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ QString errorString(ErrorCode code){
|
||||||
case(SshInterruptedError): return QObject::tr("Ssh request was interrupted");
|
case(SshInterruptedError): return QObject::tr("Ssh request was interrupted");
|
||||||
case(SshInternalError): return QObject::tr("Ssh internal error");
|
case(SshInternalError): return QObject::tr("Ssh internal error");
|
||||||
case(SshPrivateKeyError): return QObject::tr("Invalid private key or invalid passphrase entered");
|
case(SshPrivateKeyError): return QObject::tr("Invalid private key or invalid passphrase entered");
|
||||||
|
case(SshPrivateKeyFormatError): return QObject::tr("The selected private key format is not supported, use openssh ED25519 key types or PEM key types");
|
||||||
|
|
||||||
// Libssh sftp errors
|
// Libssh sftp errors
|
||||||
case(SshSftpEofError): return QObject::tr("Sftp error: End-of-file encountered");
|
case(SshSftpEofError): return QObject::tr("Sftp error: End-of-file encountered");
|
||||||
|
|
|
||||||
|
|
@ -77,16 +77,21 @@ namespace libssh {
|
||||||
if (privateKey) {
|
if (privateKey) {
|
||||||
ssh_key_free(privateKey);
|
ssh_key_free(privateKey);
|
||||||
}
|
}
|
||||||
|
if (authResult != SSH_OK) {
|
||||||
|
qDebug() << ssh_get_error(m_session);
|
||||||
|
ErrorCode errorCode = fromLibsshErrorCode(ssh_get_error_code(m_session));
|
||||||
|
if (errorCode == ErrorCode::NoError) {
|
||||||
|
errorCode = ErrorCode::SshPrivateKeyFormatError;
|
||||||
|
}
|
||||||
|
return errorCode;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
authResult = ssh_userauth_password(m_session, authUsername.c_str(), credentials.password.toStdString().c_str());
|
authResult = ssh_userauth_password(m_session, authUsername.c_str(), credentials.password.toStdString().c_str());
|
||||||
|
if (authResult != SSH_OK) {
|
||||||
|
qDebug() << ssh_get_error(m_session);
|
||||||
|
return fromLibsshErrorCode(ssh_get_error_code(m_session));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (authResult != SSH_OK) {
|
|
||||||
qDebug() << ssh_get_error(m_session);
|
|
||||||
return fromLibsshErrorCode(ssh_get_error_code(m_session));
|
|
||||||
}
|
|
||||||
|
|
||||||
return fromLibsshErrorCode(ssh_get_error_code(m_session));
|
|
||||||
}
|
}
|
||||||
return ErrorCode::NoError;
|
return ErrorCode::NoError;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue