libssh 0.4.8
Functions

SSH Authentication functions

functions to authenticate to servers More...

Functions

void privatekey_free (ssh_private_key prv)
 deallocate a private key
ssh_private_key privatekey_from_file (ssh_session session, const char *filename, int type, const char *passphrase)
 Reads a SSH private key from a file.
ssh_string publickey_from_file (ssh_session session, const char *filename, int *type)
 Retrieve a public key from a file.
ssh_public_key publickey_from_privatekey (ssh_private_key prv)
 Makes a PUBLIC_KEY object out of a PRIVATE_KEY object.
ssh_string publickey_to_string (ssh_public_key key)
 makes a SSH String out of a PUBLIC_KEY object
int ssh_auth_list (ssh_session session)
 retrieves available authentication methods for this session
int ssh_publickey_to_file (ssh_session session, const char *file, ssh_string pubkey, int type)
 Write a public key to a file.
int ssh_try_publickey_from_file (ssh_session session, const char *keyfile, ssh_string *publickey, int *type)
 Try to read the public key from a given file.
int ssh_userauth_agent_pubkey (ssh_session session, const char *username, ssh_public_key publickey)
 Try to authenticate through public key with an ssh agent.
int ssh_userauth_autopubkey (ssh_session session, const char *passphrase)
 Tries to automaticaly authenticate with public key and "none".
int ssh_userauth_kbdint (ssh_session session, const char *user, const char *submethods)
 Try to authenticate through the "keyboard-interactive" method.
const char * ssh_userauth_kbdint_getinstruction (ssh_session session)
 Get the "instruction" of the message block.
const char * ssh_userauth_kbdint_getname (ssh_session session)
 Get the "name" of the message block.
int ssh_userauth_kbdint_getnprompts (ssh_session session)
 Get the number of prompts (questions) the server has given.
const char * ssh_userauth_kbdint_getprompt (ssh_session session, unsigned int i, char *echo)
 Get a prompt from a message block.
int ssh_userauth_kbdint_setanswer (ssh_session session, unsigned int i, const char *answer)
 You have called ssh_userauth_kbdint() and got SSH_AUTH_INFO.
int ssh_userauth_list (ssh_session session, const char *username)
 retrieves available authentication methods for this session
int ssh_userauth_none (ssh_session session, const char *username)
 Try to authenticate through the "none" method.
int ssh_userauth_offer_pubkey (ssh_session session, const char *username, int type, ssh_string publickey)
 Try to authenticate through public key.
int ssh_userauth_password (ssh_session session, const char *username, const char *password)
 Try to authenticate by password.
int ssh_userauth_pubkey (ssh_session session, const char *username, ssh_string publickey, ssh_private_key privatekey)
 Try to authenticate through public key.

Detailed Description

functions to authenticate to servers


Function Documentation

void privatekey_free ( ssh_private_key  prv)

deallocate a private key

Parameters:
prva PRIVATE_KEY object

Referenced by ssh_bind_accept(), ssh_free(), and ssh_userauth_autopubkey().

ssh_private_key privatekey_from_file ( ssh_session  session,
const char *  filename,
int  type,
const char *  passphrase 
)

Reads a SSH private key from a file.

Parameters:
sessionSSH Session
filenameFilename containing the private key
typeType of the private key. One of TYPE_DSS or TYPE_RSA. Pass 0 to automatically detect the type.
passphrasePassphrase to decrypt the private key. Set to null if none is needed or it is unknown.
Returns:
a PRIVATE_KEY object containing the private key, or NULL if it failed.
See also:
privatekey_free()
publickey_from_privatekey()

returns the type of a private key

Parameters:
privatekey[in]the private key handle
Returns:
one of TYPE_RSA,TYPE_DSS,TYPE_RSA1
0 if the type is unknown
See also:
privatekey_from_file
ssh_userauth_offer_pubkey

References ssh_log(), and SSH_LOG_RARE.

Referenced by ssh_userauth_autopubkey().

ssh_string publickey_from_file ( ssh_session  session,
const char *  filename,
int *  type 
)

Retrieve a public key from a file.

Parameters:
sessionthe SSH session
filenameFilename of the key
typePointer to a integer. If it is not null, it contains the type of the key after execution.
Returns:
a SSH String containing the public key, or NULL if it failed.
See also:
string_free()
publickey_from_privatekey()

References buffer_free(), buffer_get(), buffer_get_len(), string_fill(), and string_new().

Referenced by ssh_try_publickey_from_file().

ssh_public_key publickey_from_privatekey ( ssh_private_key  prv)

Makes a PUBLIC_KEY object out of a PRIVATE_KEY object.

Parameters:
prvthe Private key
Returns:
the public key
See also:
publickey_to_string()

References string_burn(), string_data(), string_fill(), string_free(), string_len(), and string_new().

Referenced by ssh_userauth_autopubkey().

ssh_string publickey_to_string ( ssh_public_key  key)

makes a SSH String out of a PUBLIC_KEY object

Parameters:
keythe public key
Returns:
a SSH String containing the public key
See also:
string_free()

References buffer_free(), buffer_get(), buffer_get_len(), buffer_new(), string_fill(), string_free(), string_from_char(), and string_new().

Referenced by ssh_userauth_agent_pubkey(), and ssh_userauth_autopubkey().

int ssh_auth_list ( ssh_session  session)

retrieves available authentication methods for this session

Deprecated:
See also:
ssh_userauth_list

References ssh_userauth_list().

int ssh_publickey_to_file ( ssh_session  session,
const char *  file,
ssh_string  pubkey,
int  type 
)

Write a public key to a file.

Parameters:
[in]sessionThe ssh session to use.
[in]fileThe filename to write the key into.
[in]pubkeyThe public key to write.
[in]typeThe type of the public key.
Returns:
0 on success, -1 on error.

References ssh_log(), SSH_LOG_PACKET, SSH_LOG_RARE, and string_len().

Referenced by ssh_userauth_autopubkey().

int ssh_try_publickey_from_file ( ssh_session  session,
const char *  keyfile,
ssh_string *  publickey,
int *  type 
)

Try to read the public key from a given file.

Parameters:
[in]sessionThe ssh session to use.
[in]keyfileThe name of the private keyfile.
[out]publickeyA ssh_string to store the public key.
[out]typeA pointer to an integer to store the type.
Returns:
0 on success, -1 on error or the private key doesn't exist, 1 if the public key doesn't exist.

References publickey_from_file(), ssh_get_error(), ssh_log(), and SSH_LOG_PACKET.

Referenced by ssh_userauth_autopubkey().

int ssh_userauth_agent_pubkey ( ssh_session  session,
const char *  username,
ssh_public_key  publickey 
)

Try to authenticate through public key with an ssh agent.

Parameters:
sessionThe ssh session to use.
usernameThe username to authenticate. You can specify NULL if ssh_option_set_username() has been used. You cannot try two different logins in a row.
publickeyThe public key provided by the agent.
Returns:
SSH_AUTH_ERROR: A serious error happened.
SSH_AUTH_DENIED: Authentication failed: use another method.
SSH_AUTH_PARTIAL: You've been partially authenticated, you still have to use another method.
SSH_AUTH_SUCCESS: Authentication successful.
See also:
publickey_from_file()
privatekey_from_file()
privatekey_free()
ssh_userauth_offer_pubkey()

References publickey_to_string(), string_free(), and string_from_char().

Referenced by ssh_userauth_autopubkey().

int ssh_userauth_autopubkey ( ssh_session  session,
const char *  passphrase 
)

Tries to automaticaly authenticate with public key and "none".

It may fail, for instance it doesn't ask for a password and uses a default asker for passphrases (in case the private key is encrypted).

Parameters:
sessionThe ssh session to authenticate with.
passphraseUse this passphrase to unlock the privatekey. Use NULL if you don't want to use a passphrase or the user should be asked.
Returns:
SSH_AUTH_ERROR: A serious error happened
SSH_AUTH_DENIED: Authentication failed: use another method
SSH_AUTH_PARTIAL: You've been partially authenticated, you still have to use another method
SSH_AUTH_SUCCESS: Authentication success
See also:
ssh_userauth_kbdint()
ssh_userauth_password()

References privatekey_free(), privatekey_from_file(), publickey_from_privatekey(), publickey_to_string(), ssh_log(), SSH_LOG_FUNCTIONS, SSH_LOG_PACKET, SSH_LOG_PROTOCOL, SSH_LOG_RARE, ssh_publickey_to_file(), ssh_try_publickey_from_file(), ssh_userauth_agent_pubkey(), ssh_userauth_none(), ssh_userauth_offer_pubkey(), ssh_userauth_pubkey(), and string_free().

int ssh_userauth_kbdint ( ssh_session  session,
const char *  user,
const char *  submethods 
)

Try to authenticate through the "keyboard-interactive" method.

Parameters:
sessionThe ssh session to use.
userThe username to authenticate. You can specify NULL if ssh_option_set_username() has been used. You cannot try two different logins in a row.
submethodsUndocumented. Set it to NULL.
Returns:
SSH_AUTH_ERROR: A serious error happened
SSH_AUTH_DENIED: Authentication failed : use another method
SSH_AUTH_PARTIAL: You've been partially authenticated, you still have to use another method
SSH_AUTH_SUCCESS: Authentication success
SSH_AUTH_INFO: The server asked some questions. Use ssh_userauth_kbdint_getnprompts() and such.
See also:
ssh_userauth_kbdint_getnprompts()
ssh_userauth_kbdint_getname()
ssh_userauth_kbdint_getinstruction()
ssh_userauth_kbdint_getprompt()
ssh_userauth_kbdint_setanswer()
const char* ssh_userauth_kbdint_getinstruction ( ssh_session  session)

Get the "instruction" of the message block.

You have called ssh_userauth_kbdint() and got SSH_AUTH_INFO. This function returns the questions from the server.

Parameters:
sessionThe ssh session to use.
Returns:
The instruction of the message block.
const char* ssh_userauth_kbdint_getname ( ssh_session  session)

Get the "name" of the message block.

You have called ssh_userauth_kbdint() and got SSH_AUTH_INFO. This function returns the questions from the server.

Parameters:
sessionThe ssh session to use.
Returns:
The name of the message block. Do not free it.
int ssh_userauth_kbdint_getnprompts ( ssh_session  session)

Get the number of prompts (questions) the server has given.

You have called ssh_userauth_kbdint() and got SSH_AUTH_INFO. This function returns the questions from the server.

Parameters:
sessionThe ssh session to use.
Returns:
The number of prompts.
const char* ssh_userauth_kbdint_getprompt ( ssh_session  session,
unsigned int  i,
char *  echo 
)

Get a prompt from a message block.

You have called ssh_userauth_kbdint() and got SSH_AUTH_INFO. This function returns the questions from the server.

Parameters:
sessionThe ssh session to use.
iThe inndex number of the i'th prompt.
echoWhen different of NULL, it will obtain a boolean meaning that the resulting user input should be echoed or not (like passwords).
Returns:
A pointer to the prompt. Do not free it.
int ssh_userauth_kbdint_setanswer ( ssh_session  session,
unsigned int  i,
const char *  answer 
)

You have called ssh_userauth_kbdint() and got SSH_AUTH_INFO.

this function returns the questions from the server set the answer for a question from a message block.

Parameters:
sessionssh session
iindex number of the ith prompt
answeranswer to give to server
Returns:
0 on success, < 0 on error.
int ssh_userauth_list ( ssh_session  session,
const char *  username 
)

retrieves available authentication methods for this session

Parameters:
[in]sessionthe SSH session
[in]usernameset to NULL
Returns:
A bitfield of values SSH_AUTH_METHOD_NONE, SSH_AUTH_METHOD_PASSWORD, SSH_AUTH_METHOD_PUBLICKEY, SSH_AUTH_METHOD_HOSTBASED, SSH_AUTH_METHOD_INTERACTIVE.
Warning:
Other reserved flags may appear in future versions.

References ssh_userauth_none().

Referenced by ssh_auth_list().

int ssh_userauth_none ( ssh_session  session,
const char *  username 
)

Try to authenticate through the "none" method.

Parameters:
sessionThe ssh session to use.
usernameThe username to authenticate. You can specify NULL if ssh_option_set_username() has been used. You cannot try two different logins in a row.
Returns:
SSH_AUTH_ERROR: A serious error happened.
SSH_AUTH_DENIED: Authentication failed: use another method
SSH_AUTH_PARTIAL: You've been partially authenticated, you still have to use another method
SSH_AUTH_SUCCESS: Authentication success

References string_free(), and string_from_char().

Referenced by ssh_userauth_autopubkey(), and ssh_userauth_list().

int ssh_userauth_offer_pubkey ( ssh_session  session,
const char *  username,
int  type,
ssh_string  publickey 
)

Try to authenticate through public key.

Parameters:
sessionThe ssh session to use.
usernameThe username to authenticate. You can specify NULL if ssh_option_set_username() has been used. You cannot try two different logins in a row.
typeThe type of the public key. This value is given by publickey_from_file().
publickeyA public key returned by publickey_from_file().
Returns:
SSH_AUTH_ERROR: A serious error happened.
SSH_AUTH_DENIED: The server doesn't accept that public key as an authentication token. Try another key or another method.
SSH_AUTH_PARTIAL: You've been partially authenticated, you still have to use another method.
SSH_AUTH_SUCCESS: The public key is accepted, you want now to use ssh_userauth_pubkey().
See also:
publickey_from_file()
privatekey_from_file()
ssh_userauth_pubkey()

References string_free(), and string_from_char().

Referenced by ssh_userauth_autopubkey().

int ssh_userauth_password ( ssh_session  session,
const char *  username,
const char *  password 
)

Try to authenticate by password.

Parameters:
sessionThe ssh session to use.
usernameThe username to authenticate. You can specify NULL if ssh_option_set_username() has been used. You cannot try two different logins in a row.
passwordThe password to use. Take care to clean it after the authentication.
Returns:
SSH_AUTH_ERROR: A serious error happened.
SSH_AUTH_DENIED: Authentication failed: use another method.
SSH_AUTH_PARTIAL: You've been partially authenticated, you still have to use another method.
SSH_AUTH_SUCCESS: Authentication successful.
See also:
ssh_userauth_kbdint()
BURN_STRING

References string_burn(), string_free(), and string_from_char().

int ssh_userauth_pubkey ( ssh_session  session,
const char *  username,
ssh_string  publickey,
ssh_private_key  privatekey 
)

Try to authenticate through public key.

Parameters:
sessionThe ssh session to use.
usernameThe username to authenticate. You can specify NULL if ssh_option_set_username() has been used. You cannot try two different logins in a row.
publickeyA public key returned by publickey_from_file().
privatekeyA private key returned by privatekey_from_file().
Returns:
SSH_AUTH_ERROR: A serious error happened.
SSH_AUTH_DENIED: Authentication failed: use another method.
SSH_AUTH_PARTIAL: You've been partially authenticated, you still have to use another method.
SSH_AUTH_SUCCESS: Authentication successful.
See also:
publickey_from_file()
privatekey_from_file()
privatekey_free()
ssh_userauth_offer_pubkey()

References string_free(), and string_from_char().

Referenced by ssh_userauth_autopubkey().