kexgssc.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "includes.h"
#ifdef GSSAPI
#include "xmalloc.h"
#include "buffer.h"
#include "bufaux.h"
#include "kex.h"
#include "log.h"
#include "packet.h"
#include "dh.h"
#include "canohost.h"
#include "ssh2.h"
#include "ssh-gss.h"
extern char *xxx_host;
static void kexgss_verbose_cleanup(void *arg);
void
{
BIGNUM *dh_server_pub = 0;
BIGNUM *shared_secret = 0;
unsigned char *kbuf;
unsigned char *hash;
unsigned char *server_host_key_blob = NULL;
int type = 0;
int first = 1;
/* Map the negotiated kex name to a mech OID*/
if (mech == GSS_C_NULL_OID)
fatal("Couldn't match the negotiated GSS key exchange");
/* This code should match that in ssh_dh1_client */
/* Step 1 - e is dh->pub_key */
dh = dh_new_group1();
/* This is f, we initialise it now to make life easier */
dh_server_pub = BN_new();
if (dh_server_pub == NULL) {
fatal("dh_server_pub == NULL");
}
do {
debug("Calling gss_init_sec_context");
&send_tok);
if (GSS_ERROR(maj_status)) {
"SSHv2 key exchange");
packet_disconnect("A GSS-API error occurred during "
"GSS-API protected SSHv2 key exchange\n");
}
/* If we've got an old receive buffer get rid of it */
if (token_ptr != GSS_C_NO_BUFFER) {
/* We allocated recv_tok */
}
if (maj_status == GSS_S_COMPLETE) {
/* If mutual state flag is not true, kex fails */
fatal("Mutual authentication failed");
}
/* If integ avail flag is not true kex fails */
fatal("Integrity check failed");
}
}
/* If we have data to send, then the last message that we
* received cannot have been a 'complete'. */
if (first) {
first=0;
} else {
}
packet_send();
/* If we've sent them data, they'd better be polite
* and reply. */
/*
* We need to catch connection closing w/o error
* tokens or messages so we can tell the user
* _something_ more useful than "Connection
* closed by ..."
*
* We use a fatal cleanup function as that's
* all, really, that we can do for now.
*/
type = packet_read();
switch (type) {
case SSH2_MSG_KEXGSS_HOSTKEY:
debug("Received KEXGSS_HOSTKEY");
sbloblen);
goto next_packet; /* there MUSt be another */
break;
case SSH2_MSG_KEXGSS_CONTINUE:
debug("Received GSSAPI_CONTINUE");
if (maj_status == GSS_S_COMPLETE)
packet_disconnect("Protocol error: "
"received GSS-API context token"
" though the context was already"
" established");
break;
case SSH2_MSG_KEXGSS_COMPLETE:
debug("Received GSSAPI_COMPLETE");
/* Is there a token included? */
if (packet_get_char()) {
}
maj_status == GSS_S_COMPLETE) {
packet_disconnect("Protocol error: "
"received GSS-API context token"
" though the context was already"
" established");
/* No token included */
packet_disconnect("Protocol error: "
"did not receive expected "
"GSS-API context token");
}
break;
case SSH2_MSG_KEXGSS_ERROR:
error("Server had a GSS-API error; the "
"connection will close (%d/%d):\n%s",
error("Use the GssKeyEx option to disable "
"GSS-API key exchange and try again.");
packet_disconnect("The server had a GSS-API "
"error during GSS-API protected SSHv2 "
"key exchange\n");
break;
default:
packet_disconnect("Protocol error: "
"didn't expect packet type %d", type);
}
} else {
/* No data, and not complete */
if (maj_status != GSS_S_COMPLETE) {
fatal("Not complete, and no token output");
}
}
} while (maj_status == GSS_S_CONTINUE_NEEDED);
/* We _must_ have received a COMPLETE message in reply from the
* server, which will have set dh_server_pub and msg_tok */
if (type != SSH2_MSG_KEXGSS_COMPLETE)
fatal("Expected SSH2_MSG_KEXGSS_COMPLETE never arrived");
if (maj_status != GSS_S_COMPLETE)
fatal("Internal error in GSS-API protected SSHv2 key exchange");
/* Check f in range [1, p-1] */
packet_disconnect("bad server public DH value");
/* compute K=f^x mod p */
shared_secret = BN_new();
/* The GSS hash is identical to the DH one */
hash = kex_dh_hash(
dh_server_pub, /* f */
shared_secret /* K */
);
/* Verify that H matches the token we just got. */
&gssbuf,
&msg_tok,
NULL))) {
packet_disconnect("Hash's MIC didn't verify");
}
/* save session id */
}
}
/* ARGSUSED */
static
void
kexgss_verbose_cleanup(void *arg)
{
error("The GSS-API protected key exchange has failed without "
"indication\nfrom the server, possibly due to misconfiguration "
"of the server.");
error("Use the GssKeyEx option to disable GSS-API key exchange "
"and try again.");
}
#endif /* GSSAPI */