/*
* Copyright (c) 2001-2009 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.
*/
/*
* May 22, 2015
* In version 6.8 a new packet interface has been introduced to OpenSSH,
* while the old packet API has been provided in opacket.c.
* At this moment we are not rewritting GSS-API key exchange code to the new
* API, just adjusting it to still work with new struct ssh.
* Rewritting to the new API can be considered in the future.
*/
#include "includes.h"
#ifdef GSSAPI
#include "includes.h"
#include <string.h>
#include "xmalloc.h"
#include "buffer.h"
#include "ssh2.h"
#include "key.h"
#include "cipher.h"
#include "digest.h"
#include "kex.h"
#include "log.h"
#include "packet.h"
#include "dh.h"
#include "ssh-gss.h"
int
char *msg;
char *lang;
int type = 0;
int r;
/* Initialise our GSSAPI world */
== GSS_C_NO_OID)
fatal("Couldn't identify host exchange");
fatal("Couldn't import hostname");
case KEX_GSS_GRP1_SHA1:
break;
case KEX_GSS_GRP14_SHA1:
break;
case KEX_GSS_GEX_SHA1:
debug("Doing group exchange\n");
packet_send();
fatal("BN_new() failed");
fatal("BN_new() failed");
fatal("GSSGRP_GEX group out of range: %d !< %d !< %d",
break;
default:
}
/* Step 1 - e is dh->pub_key */
/* 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");
&ret_flags);
if (GSS_ERROR(maj_status)) {
}
fatal("gss_init_context failed");
}
/* If we've got an old receive buffer get rid of it */
if (token_ptr != GSS_C_NO_BUFFER)
if (maj_status == GSS_S_COMPLETE) {
/* If mutual state flag is not true, kex fails */
if (!(ret_flags & GSS_C_MUTUAL_FLAG))
fatal("Mutual authentication failed");
/* If integ avail flag is not true kex fails */
if (!(ret_flags & GSS_C_INTEG_FLAG))
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 should reply */
do {
type = packet_read();
if (type == SSH2_MSG_KEXGSS_HOSTKEY) {
debug("Received KEXGSS_HOSTKEY");
if (serverhostkey)
fatal("Server host key received"
"more than once");
}
} while (type == SSH2_MSG_KEXGSS_HOSTKEY);
switch (type) {
case SSH2_MSG_KEXGSS_CONTINUE:
debug("Received GSSAPI_CONTINUE");
if (maj_status == GSS_S_COMPLETE)
fatal("GSSAPI Continue received from"
"server when complete");
break;
case SSH2_MSG_KEXGSS_COMPLETE:
debug("Received GSSAPI_COMPLETE");
/* Is there a token included? */
if (packet_get_char()) {
/* If complete - protocol error */
if (maj_status == GSS_S_COMPLETE)
packet_disconnect("Protocol"
" error: received token"
" when complete");
} else {
/* No token included */
if (maj_status != GSS_S_COMPLETE)
packet_disconnect("Protocol"
" error: did not receive"
" final token");
}
break;
case SSH2_MSG_KEXGSS_ERROR:
debug("Received Error");
maj_status = packet_get_int();
min_status = packet_get_int();
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("Didn't receive SSH2_MSG_KEXGSS_COMPLETE when expected");
/* Check f in range [1, p-1] */
packet_disconnect("bad server public DH value");
/* compute K=f^x mod p */
if (kout < 0)
fatal("DH_compute_key: failed");
shared_secret = BN_new();
if (shared_secret == NULL)
fatal("kexgss_client: BN_new failed");
fatal("kexdh_client: BN_bin2bn failed");
case KEX_GSS_GRP1_SHA1:
case KEX_GSS_GRP14_SHA1:
dh_server_pub, /* f */
shared_secret, /* K */
break;
case KEX_GSS_GEX_SHA1:
break;
default:
}
/* Verify that the hash matches the MIC we just got. */
packet_disconnect("Hash's MIC didn't verify");
if (serverhostkey)
/* save session id */
}
if (gss_kex_context == NULL)
else
r = kex_send_newkeys(ssh);
return (r);
}
#endif /* GSSAPI */