void server_handle_message(ssh_session s, ssh_message m, int type, int subtype, int *state) { int handled = 0; if((*state == SERVER_CONNECTED) && (type == SSH_REQUEST_AUTH) && (subtype == SSH_AUTH_METHOD_PUBLICKEY)) { ssh_public_key key = ssh_message_auth_publickey(m); ssh_string keystr = publickey_to_string(key); char *keyhash = pubkey_hash(keystr); int has_sig = ssh_message_auth_publickey_state(m); if(has_sig == SSH_PUBLICKEY_STATE_NONE) { if(authenticate(keyhash, 1)) { //FIXME: type detection ssh_string algostr = ssh_string_from_char("ssh-rsa"); ssh_message_auth_reply_pk_ok(m, algostr, keystr); handled = 1; ssh_string_free(algostr); } } else if(has_sig == SSH_PUBLICKEY_STATE_VALID) { if(authenticate(keyhash, 0)) { session_event(s, "authenticated", keyhash); ssh_message_auth_reply_success(m, 0); handled = 1; *state = SERVER_AUTHENTICATED; } else { ssh_message_reply_default(m); handled = 1; *state = SERVER_CLOSED; } } ssh_string_free(keystr); free(keyhash); } else if((*state == SERVER_AUTHENTICATED) && (type == SSH_REQUEST_CHANNEL_OPEN) && (subtype == SSH_CHANNEL_SESSION)) { ssh_channel chan = ssh_message_channel_request_open_reply_accept(m); if(!chan) session_error(s, "open-channel"); handled = 1; session_event(s, "channel-opened", NULL); channel_to_file(chan, 1); ssh_channel_free(chan); *state = SERVER_CLOSED; } if(!handled) ssh_message_reply_default(m); }
static int auth_publickey (ssh_message message) { int ret = -1; int auth_state = ssh_message_auth_publickey_state (message); gboolean have = ssh_key_cmp (state.pkey, ssh_message_auth_pubkey (message), SSH_KEY_CMP_PUBLIC) == 0; if (have && auth_state == SSH_PUBLICKEY_STATE_VALID) ret = 1; else if (have && auth_state == SSH_PUBLICKEY_STATE_NONE) ret = 0; return ret; }