Thanks to visit codestin.com
Credit goes to github.com

Skip to content

SSH_AUTH_METHOD_PASSWORD does not seem to be working #61

@bschulth

Description

@bschulth
/* authenticate client */
static void auth_or_disconnect(ssh_session ssh, ssh_key privkey, SEXP rpass, const char *user){
  if(ssh_userauth_none(ssh, NULL) == SSH_AUTH_SUCCESS)
    return;
  int method = ssh_userauth_list(ssh, NULL);
  if (method & SSH_AUTH_METHOD_PUBLICKEY){
    if(privkey != NULL && ssh_userauth_publickey(ssh, NULL, privkey) == SSH_AUTH_SUCCESS)
      return;
    // ssh_userauth_publickey_auto() tries both ssh-agent and standard keys in ~/.ssh
    // it also automatically picks up SSH_ASKPASS env var set by 'askpass' package
    if(privkey == NULL && ssh_userauth_publickey_auto(ssh, NULL, NULL) == SSH_AUTH_SUCCESS)
      return;
  }
  if (method & SSH_AUTH_METHOD_INTERACTIVE && auth_interactive(ssh, rpass, user) == SSH_AUTH_SUCCESS)
    return;
  if (method & SSH_AUTH_METHOD_PASSWORD && auth_password(ssh, rpass, user) == SSH_AUTH_SUCCESS)
    return;
  ssh_disconnect(ssh);
  Rf_errorcall(R_NilValue, "Authentication with ssh server failed");
}
  • To have a retry loop, it works on second attempt. Not sure if this is a timeout issue or not waiting for a socket response.
/* authenticate client */
static void auth_or_disconnect(ssh_session ssh, ssh_key privkey, SEXP rpass, const char *user){
  if(ssh_userauth_none(ssh, NULL) == SSH_AUTH_SUCCESS)
    return;
  int method = ssh_userauth_list(ssh, NULL);
  if (method & SSH_AUTH_METHOD_PUBLICKEY){
    if(privkey != NULL && ssh_userauth_publickey(ssh, NULL, privkey) == SSH_AUTH_SUCCESS)
      return;
    // ssh_userauth_publickey_auto() tries both ssh-agent and standard keys in ~/.ssh
    // it also automatically picks up SSH_ASKPASS env var set by 'askpass' package
    if(privkey == NULL && ssh_userauth_publickey_auto(ssh, NULL, NULL) == SSH_AUTH_SUCCESS)
      return;
  }
  if (method & SSH_AUTH_METHOD_INTERACTIVE && auth_interactive(ssh, rpass, user) == SSH_AUTH_SUCCESS)
    return;
  // CHANGE START+++++++++++++++++++++++++++++++++++++
  if (method & SSH_AUTH_METHOD_PASSWORD) {
    int tries;
    int rc;
    rc = SSH_AUTH_AGAIN;
    while (rc != SSH_AUTH_SUCCESS) {
      tries += 1;
      REprintf("\nTrying password...via auth_password...attempt %i\n", tries);
      rc = auth_password(ssh, rpass, user);
      REprintf("   rc = %i\n", rc);
      if (rc == SSH_AUTH_SUCCESS) {
        return;
      }
      if (tries > 5) {
        break;
      }
    }
  }
  // CHANGE END+++++++++++++++++++++++++++++++++++++
  ssh_disconnect(ssh);
  Rf_errorcall(R_NilValue, "Authentication with ssh server failed");
}
  • Example output from my tweaked code:
ssh_userauth_publickey_auto: Private key /home/bschulth/.ssh/identity doesn't exist.
ssh_userauth_publickey_auto: Tried every public key, none matched

Trying password...via auth_password...attempt 1
ssh_socket_unbuffered_write: Enabling POLLOUT for socket
packet_send2: packet: wrote [len=76,padding=19,comp=56,payload=56]
ssh_socket_pollcallback: Poll callback on socket 29 (POLLOUT ), out buffer 0
ssh_socket_pollcallback: sending control flow event
ssh_packet_socket_controlflow_callback: sending channel_write_wontblock callback
   rc = 1

Trying password...via auth_password...attempt 2
ssh_socket_pollcallback: Poll callback on socket 29 (POLLIN ), out buffer 0
ssh_packet_socket_callback: packet: read type 52 [len=12,padding=10,comp=1,payload=1]
ssh_packet_process: Dispatching handler for packet type 52
ssh_packet_userauth_success: Authentication successful
ssh_packet_userauth_success: Received SSH_USERAUTH_SUCCESS
   rc = 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions