| 494 | } |
| 495 | |
| 496 | int FTPClientWrapperSSH::authenticate(ssh_session session) { |
| 497 | int methods = 0; |
| 498 | int authres = 0; |
| 499 | int retries = 0; |
| 500 | const int maxRetries = 5; |
| 501 | |
| 502 | authres = ssh_userauth_none(session, NULL); |
| 503 | if (authres == SSH_AUTH_AGAIN) |
| 504 | authres = ssh_userauth_none(session, NULL); |
| 505 | if (authres == SSH_AUTH_ERROR) { |
| 506 | OutErr("[SFTP] Error during authentication: %s", ssh_get_error(session)); |
| 507 | return -1; |
| 508 | } else if (authres == SSH_AUTH_SUCCESS) { |
| 509 | OutMsg("[SFTP] Authenticated without credentials."); |
| 510 | return 0; |
| 511 | } |
| 512 | |
| 513 | char * banner = ssh_get_issue_banner(session); |
| 514 | if (banner) { |
| 515 | OutMsg("[SFTP] Banner: %s\n", banner); |
| 516 | ssh_string_free_char(banner); |
| 517 | } |
| 518 | |
| 519 | do { |
| 520 | methods = ssh_auth_list(session); |
| 521 | if (methods == -1) { |
| 522 | OutErr("[SFTP] No authentication methods provided."); |
| 523 | return -1; |
| 524 | } |
| 525 | |
| 526 | if (methods == SSH_AUTH_METHOD_UNKNOWN) { |
| 527 | OutErr("[SFTP] Unknown authentication method."); |
| 528 | return -1; |
| 529 | } |
| 530 | |
| 531 | //Filter out methods client does not wish to use |
| 532 | methods &= m_acceptedMethods; |
| 533 | |
| 534 | if ((authres == SSH_AUTH_DENIED || authres == SSH_AUTH_PARTIAL) && (methods & SSH_AUTH_METHOD_PUBLICKEY)) { |
| 535 | authres = authenticate_key(session); |
| 536 | } |
| 537 | |
| 538 | if ((authres == SSH_AUTH_DENIED || authres == SSH_AUTH_PARTIAL) && (methods & SSH_AUTH_METHOD_INTERACTIVE)) { |
| 539 | authres = authenticate_kbinteractive(session); |
| 540 | } |
| 541 | |
| 542 | if ((authres == SSH_AUTH_DENIED || authres == SSH_AUTH_PARTIAL) && (methods & SSH_AUTH_METHOD_PASSWORD)) { |
| 543 | authres = authenticate_password(session); |
| 544 | } |
| 545 | |
| 546 | if (methods == 0) { |
| 547 | OutErr("[SFTP] None of the server's authentication methods were accepted. Please check the options under the authentication tab."); |
| 548 | return -1; |
| 549 | } |
| 550 | |
| 551 | if (authres == SSH_AUTH_ERROR) { |
| 552 | OutErr("[SFTP] Error during authentication: %s", ssh_get_error(session)); |
| 553 | return -1; |
nothing calls this directly
no outgoing calls
no test coverage detected