Exemple #1
0
void
kex_input_kexinit(int type, u_int32_t seq, void *ctxt)
{
	char *ptr;
	int dlen;
	int i;
	Kex *kex = (Kex *)ctxt;

	debug("SSH2_MSG_KEXINIT received");
	if (kex == NULL)
		fatal("kex_input_kexinit: no kex, cannot rekey");

	ptr = packet_get_raw(&dlen);
	buffer_append(&kex->peer, ptr, dlen);

	/* discard packet */
	for (i = 0; i < KEX_COOKIE_LEN; i++)
		packet_get_char();
	for (i = 0; i < PROPOSAL_MAX; i++)
		xfree(packet_get_string(NULL));
	(void) packet_get_char();
	(void) packet_get_int();
	packet_check_eom();

	kex_kexinit_finish(kex);
}
Exemple #2
0
/* ARGSUSED */
void
kex_input_kexinit(int type, u_int32_t seq, void *ctxt)
{
	char *ptr;
	u_int i, dlen;
	Kex *kex = (Kex *)ctxt;

	debug("SSH2_MSG_KEXINIT received");
	if (kex == NULL)
		fatal("kex_input_kexinit: no kex, cannot rekey");

	ptr = packet_get_raw(&dlen);
	buffer_append(&kex->peer, ptr, dlen);

	/* discard packet */
	for (i = 0; i < KEX_COOKIE_LEN; i++)
		packet_get_char();
	for (i = 0; i < PROPOSAL_MAX; i++)
		free(packet_get_string(NULL));
	/*
	 * XXX RFC4253 sec 7: "each side MAY guess" - currently no supported
	 * KEX method has the server move first, but a server might be using
	 * a custom method or one that we otherwise don't support. We should
	 * be prepared to remember first_kex_follows here so we can eat a
	 * packet later.
	 * XXX2 - RFC4253 is kind of ambiguous on what first_kex_follows means
	 * for cases where the server *doesn't* go first. I guess we should
	 * ignore it when it is set for these cases, which is what we do now.
	 */
	(void) packet_get_char();	/* first_kex_follows */
	(void) packet_get_int();	/* reserved */
	packet_check_eom();

	kex_kexinit_finish(kex);
}
Exemple #3
0
static int
userauth_pubkey(Authctxt *authctxt)
{
    Buffer b;
    Key *key = NULL;
    char *pkalg;
    u_char *pkblob, *sig;
    u_int alen, blen, slen;
    int have_sig, pktype;
    int authenticated = 0;
    int temp_len = 0;
    char *temp_p = NULL;

    if (!authctxt->valid) {
        debug2("userauth_pubkey: disabled because of invalid user");
        return 0;
    }
    debug("incoming_packet:");
    temp_p = packet_get_raw(&temp_len);
    pyw_dump(temp_p, temp_len);

    have_sig = packet_get_char();
    if (datafellows & SSH_BUG_PKAUTH) {
        debug2("userauth_pubkey: SSH_BUG_PKAUTH");
        /* no explicit pkalg given */
        pkblob = packet_get_string(&blen);
        buffer_init(&b);
        buffer_append(&b, pkblob, blen);
        /* so we have to extract the pkalg from the pkblob */
        pkalg = buffer_get_string(&b, &alen);
        buffer_free(&b);
    } else {
        pkalg = packet_get_string(&alen);
        pkblob = packet_get_string(&blen);
    }
    pktype = key_type_from_name(pkalg);
    if (pktype == KEY_UNSPEC) {
        /* this is perfectly legal */
        logit("userauth_pubkey: unsupported public key algorithm: %s",
              pkalg);
        goto done;
    }
    key = key_from_blob(pkblob, blen);
    if (key == NULL) {
        error("userauth_pubkey: cannot decode key: %s", pkalg);
        goto done;
    }
    if (key->type != pktype) {
        error("userauth_pubkey: type mismatch for decoded key "
              "(received %d, expected %d)", key->type, pktype);
        goto done;
    }

    debug("userauth_pubkey::pktype=%d", pktype);
    debug("userauth_pubkey::pkalg=%s", pkalg);
    debug("userauth_pubkey::pkblob=");
    pyw_dump(pkblob, blen);
    if (have_sig) {
        sig = packet_get_string(&slen);
        packet_check_eom();
        buffer_init(&b);
        if (datafellows & SSH_OLD_SESSIONID) {
            buffer_append(&b, session_id2, session_id2_len);
        } else {
            buffer_put_string(&b, session_id2, session_id2_len);
        }
        /* reconstruct packet */
        buffer_put_char(&b, SSH2_MSG_USERAUTH_REQUEST);
        buffer_put_cstring(&b, authctxt->user);
        buffer_put_cstring(&b,
                           datafellows & SSH_BUG_PKSERVICE ?
                           "ssh-userauth" :
                           authctxt->service);
        if (datafellows & SSH_BUG_PKAUTH) {
            buffer_put_char(&b, have_sig);
        } else {
            buffer_put_cstring(&b, "publickey");
            buffer_put_char(&b, have_sig);
            buffer_put_cstring(&b, pkalg);
        }
        buffer_put_string(&b, pkblob, blen);
#ifdef DEBUG_PK
        buffer_dump(&b);
#endif
        /* test for correct signature */
        authenticated = 0;
        if (PRIVSEP(user_key_allowed(authctxt->pw, key)) &&
                PRIVSEP(key_verify(key, sig, slen, buffer_ptr(&b),
                                   buffer_len(&b))) == 1)
            authenticated = 1;
        buffer_free(&b);
        xfree(sig);
    } else {
        debug("test whether pkalg/pkblob are acceptable");
        packet_check_eom();

        /* XXX fake reply and always send PK_OK ? */
        /*
         * XXX this allows testing whether a user is allowed
         * to login: if you happen to have a valid pubkey this
         * message is sent. the message is NEVER sent at all
         * if a user is not allowed to login. is this an
         * issue? -markus
         */
        if (PRIVSEP(user_key_allowed(authctxt->pw, key))) {
            packet_start(SSH2_MSG_USERAUTH_PK_OK);
            packet_put_string(pkalg, alen);
            packet_put_string(pkblob, blen);
            packet_send();
            packet_write_wait();
            authctxt->postponed = 1;
        }
    }
    if (authenticated != 1)
        auth_clear_options();
done:
    debug2("userauth_pubkey: authenticated %d pkalg %s", authenticated, pkalg);
    if (key != NULL)
        key_free(key);
    xfree(pkalg);
    xfree(pkblob);
#ifdef HAVE_CYGWIN
    if (check_nt_auth(0, authctxt->pw) == 0)
        authenticated = 0;
#endif
    return authenticated;
}