| 174 | } |
| 175 | |
| 176 | bool SFTPClient::setHostKeyFile(const std::string& host_key_file_path, bool strict_host_checking) { |
| 177 | if (ssh_known_hosts_ != nullptr) { |
| 178 | return false; |
| 179 | } |
| 180 | ssh_known_hosts_ = libssh2_knownhost_init(ssh_session_); |
| 181 | if (ssh_known_hosts_ == nullptr) { |
| 182 | char *err_msg = nullptr; |
| 183 | libssh2_session_last_error(ssh_session_, &err_msg, nullptr, 0); |
| 184 | logger_->log_error("Failed to init knownhost structure, error: %s", err_msg); |
| 185 | return false; |
| 186 | } |
| 187 | if (libssh2_knownhost_readfile(ssh_known_hosts_, host_key_file_path.c_str(), LIBSSH2_KNOWNHOST_FILE_OPENSSH) <= 0) { |
| 188 | char *err_msg = nullptr; |
| 189 | libssh2_session_last_error(ssh_session_, &err_msg, nullptr, 0); |
| 190 | logger_->log_error("Failed to read host file %s, error: %s", host_key_file_path.c_str(), err_msg); |
| 191 | return false; |
| 192 | } |
| 193 | strict_host_checking_ = strict_host_checking; |
| 194 | return true; |
| 195 | } |
| 196 | |
| 197 | void SFTPClient::setPasswordAuthenticationCredentials(const std::string& password) { |
| 198 | password_authentication_enabled_ = true; |
no test coverage detected