Skip to content

getHostKey returns an empty string #66

@Hjdskes

Description

@Hjdskes

Hello,

I am running into the case where getHostKey always returns an empty string. This happens on two very distinct SFTP servers, one of which is an AWS Transfer Family SFTP server; the other is an old mainframe-like SFTP server.

In both cases, the host key type returned is 1, which I assume to be TYPE_PLAIN as per

Below is the code I use to initialise my SFTP session:

withSftpUser :: forall m a
  .  MonadLog m
  => MonadMetrics m
  => MonadThrow m
  => MonadUnliftIO m
  => SftpConfigF Text
  -> (Sftp -> m a)
  -> m a
withSftpUser config action = withSession (host config) (port config) $ \session -> do
  checkHost session (host config) (port config) (knownHosts config) >>= \case
    MISMATCH -> logError "Host key mismatch" >> throwM ERROR_KNOWN_HOSTS
    FAILURE -> logError "Failed to verify host key" >> throwM ERROR_KNOWN_HOSTS
    NOTFOUND -> logError "Host key not found" >> throwM ERROR_KNOWN_HOSTS
    MATCH -> logInfo "Verified host key"
  case credentials config of
    MkUserPass (UserPass (Username username) password) ->
      liftIO $ usernamePasswordAuth session (Text.unpack username) (Text.unpack password)
  withSftpSession session action

withSftpSession :: forall m a
  .  MonadUnliftIO m
  => Session
  -> (Sftp -> m a)
  -> m a
withSftpSession session = bracket (liftIO $ sftpInit session) (liftIO . sftpShutdown)

withSession :: forall m a
  .  MonadUnliftIO m
  => Text
  -> Int
  -> (Session -> m a)
  -> m a
withSession hostname port = bracket
  (liftIO $ initialize True >> sessionInit (Text.unpack hostname) port)
  (liftIO . sessionClose)

As far as I can see, the FFI in libssh2-hs for getHostKey is correct. Am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions