components/openssh/sources/kexgssc.c
author Tomas Kuthan <tomas.kuthan@oracle.com>
Wed, 11 Jan 2017 12:12:15 -0800
changeset 7561 64cbdac1f406
parent 6930 31ef2580c45d
permissions -rw-r--r--
25055579 ssh should be more descriptive when GSS key exchange fails
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     1
/*
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     2
 * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     3
 *
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     4
 * Redistribution and use in source and binary forms, with or without
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     5
 * modification, are permitted provided that the following conditions
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     6
 * are met:
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     7
 * 1. Redistributions of source code must retain the above copyright
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     8
 *    notice, this list of conditions and the following disclaimer.
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     9
 * 2. Redistributions in binary form must reproduce the above copyright
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    10
 *    notice, this list of conditions and the following disclaimer in the
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    11
 *    documentation and/or other materials provided with the distribution.
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    12
 *
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    13
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    14
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    15
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    16
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    17
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    18
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    19
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    20
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    21
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    22
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    23
 */
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    24
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
    25
/*
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
    26
 * May 22, 2015
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
    27
 * In version 6.8 a new packet interface has been introduced to OpenSSH,
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
    28
 * while the old packet API has been provided in opacket.c.
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
    29
 * At this moment we are not rewritting GSS-API key exchange code to the new
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
    30
 * API, just adjusting it to still work with new struct ssh.
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
    31
 * Rewritting to the new API can be considered in the future.
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
    32
 */
7561
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
    33
/*
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
    34
 * Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
    35
 */
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
    36
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    37
#include "includes.h"
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    38
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    39
#ifdef GSSAPI
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    40
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    41
#include "includes.h"
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    42
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    43
#include <openssl/crypto.h>
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    44
#include <openssl/bn.h>
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    45
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
    46
#include <signal.h>	/* for sig_atomic_t in kex.h */
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    47
#include <string.h>
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    48
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    49
#include "xmalloc.h"
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    50
#include "buffer.h"
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    51
#include "ssh2.h"
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    52
#include "key.h"
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    53
#include "cipher.h"
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
    54
#include "digest.h"
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    55
#include "kex.h"
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    56
#include "log.h"
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    57
#include "packet.h"
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    58
#include "dh.h"
7561
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
    59
#include "ssherr.h"
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    60
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    61
#include "ssh-gss.h"
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    62
7561
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
    63
#define	GSSKEX_ERRHINT \
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
    64
	"Disable GSS-API key exchange by including '-o GSSAPIKeyExchange=no'\n"\
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
    65
	"in the ssh(1) command line invocation and try again."
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
    66
#define	GSSKEX_ERRMSG \
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
    67
	"GSS-API protected key exchange failed due to an unspecified error \n" \
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
    68
	"encountered on the server.  This may be due to a misconfiguration \n" \
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
    69
	"of Kerberos on the server.\n" \
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
    70
	GSSKEX_ERRHINT
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
    71
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
    72
int
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
    73
kexgss_client(struct ssh *ssh) {
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    74
	gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    75
	gss_buffer_desc recv_tok, gssbuf, msg_tok, *token_ptr;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    76
	Gssctxt *ctxt;
7561
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
    77
	OM_uint32 maj_status, min_status, ret_flags, smaj_status, smin_status;
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
    78
	uint_t klen, kout, slen = 0, strlen;
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    79
	BIGNUM *dh_server_pub = NULL;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    80
	BIGNUM *shared_secret = NULL;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    81
	BIGNUM *p = NULL;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    82
	BIGNUM *g = NULL;
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
    83
	uchar_t *kbuf;
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    84
	uchar_t *serverhostkey = NULL;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    85
	uchar_t *empty = "";
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    86
	char *msg;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    87
	char *lang;
7561
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
    88
	uchar_t type = 0;
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    89
	int first = 1;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    90
	int nbits = 0, min = DH_GRP_MIN, max = DH_GRP_MAX;
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
    91
	struct kex *kex = ssh->kex;
7561
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
    92
	int r, err;
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
    93
	uchar_t hash[SSH_DIGEST_MAX_LENGTH];
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
    94
	size_t hashlen;
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    95
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    96
	/* Initialise our GSSAPI world */
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    97
	ssh_gssapi_build_ctx(&ctxt);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    98
	if (ssh_gssapi_id_kex(ctxt, kex->name, kex->kex_type)
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    99
	    == GSS_C_NO_OID)
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   100
		fatal("Couldn't identify host exchange");
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   101
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   102
	if (ssh_gssapi_import_name(ctxt, kex->gss_host))
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   103
		fatal("Couldn't import hostname");
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   104
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   105
	switch (kex->kex_type) {
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   106
	case KEX_GSS_GRP1_SHA1:
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
   107
		kex->dh = dh_new_group1();
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   108
		break;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   109
	case KEX_GSS_GRP14_SHA1:
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
   110
		kex->dh = dh_new_group14();
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   111
		break;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   112
	case KEX_GSS_GEX_SHA1:
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   113
		debug("Doing group exchange\n");
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   114
		nbits = dh_estimate(kex->we_need * 8);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   115
		packet_start(SSH2_MSG_KEXGSS_GROUPREQ);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   116
		packet_put_int(min);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   117
		packet_put_int(nbits);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   118
		packet_put_int(max);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   119
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   120
		packet_send();
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   121
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   122
		packet_read_expect(SSH2_MSG_KEXGSS_GROUP);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   123
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   124
		if ((p = BN_new()) == NULL)
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   125
			fatal("BN_new() failed");
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   126
		packet_get_bignum2(p);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   127
		if ((g = BN_new()) == NULL)
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   128
			fatal("BN_new() failed");
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   129
		packet_get_bignum2(g);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   130
		packet_check_eom();
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   131
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   132
		if (BN_num_bits(p) < min || BN_num_bits(p) > max)
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   133
			fatal("GSSGRP_GEX group out of range: %d !< %d !< %d",
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   134
			    min, BN_num_bits(p), max);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   135
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
   136
		kex->dh = dh_new_group(g, p);
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   137
		break;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   138
	default:
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   139
		fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   140
	}
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   141
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   142
	/* Step 1 - e is dh->pub_key */
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
   143
	dh_gen_key(kex->dh, kex->we_need * 8);
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   144
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   145
	/* This is f, we initialise it now to make life easier */
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   146
	dh_server_pub = BN_new();
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   147
	if (dh_server_pub == NULL)
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   148
		fatal("dh_server_pub == NULL");
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   149
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   150
	token_ptr = GSS_C_NO_BUFFER;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   151
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   152
	do {
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   153
		debug("Calling gss_init_sec_context");
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   154
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   155
		maj_status = ssh_gssapi_init_ctx(ctxt,
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   156
		    kex->gss_deleg_creds, token_ptr, &send_tok,
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   157
		    &ret_flags);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   158
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   159
		if (GSS_ERROR(maj_status)) {
7561
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   160
			ssh_gssapi_error(ctxt);
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   161
			(void) gss_release_buffer(&min_status, &send_tok);
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   162
			packet_disconnect("A GSS-API error occurred during "
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   163
			    "GSS-API protected key exchange\n");
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   164
		}
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   165
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   166
		/* If we've got an old receive buffer get rid of it */
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   167
		if (token_ptr != GSS_C_NO_BUFFER)
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   168
			free(recv_tok.value);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   169
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   170
		if (maj_status == GSS_S_COMPLETE) {
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   171
			/* If mutual state flag is not true, kex fails */
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   172
			if (!(ret_flags & GSS_C_MUTUAL_FLAG))
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   173
				fatal("Mutual authentication failed");
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   174
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   175
			/* If integ avail flag is not true kex fails */
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   176
			if (!(ret_flags & GSS_C_INTEG_FLAG))
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   177
				fatal("Integrity check failed");
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   178
		}
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   179
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   180
		/*
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   181
		 * If we have data to send, then the last message that we
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   182
		 * received cannot have been a 'complete'.
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   183
		 */
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   184
		if (send_tok.length != 0) {
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   185
			if (first) {
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   186
				packet_start(SSH2_MSG_KEXGSS_INIT);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   187
				packet_put_string(send_tok.value,
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   188
				    send_tok.length);
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
   189
				packet_put_bignum2(kex->dh->pub_key);
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   190
				first = 0;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   191
			} else {
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   192
				packet_start(SSH2_MSG_KEXGSS_CONTINUE);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   193
				packet_put_string(send_tok.value,
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   194
				    send_tok.length);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   195
			}
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   196
			packet_send();
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   197
			gss_release_buffer(&min_status, &send_tok);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   198
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   199
			/* If we've sent them data, they should reply */
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   200
			do {
7561
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   201
				err = ssh_packet_read_seqnr(active_state,
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   202
				    &type, NULL);
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   203
				if (err != 0) {
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   204
					fatal("%s: %s.\n%s", __func__,
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   205
					    ssh_err(err), GSSKEX_ERRMSG);
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   206
				}
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   207
				if (type == SSH2_MSG_KEXGSS_HOSTKEY) {
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   208
					debug("Received KEXGSS_HOSTKEY");
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   209
					if (serverhostkey)
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   210
						fatal("Server host key received"
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   211
						    "more than once");
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   212
					serverhostkey =
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   213
					    packet_get_string(&slen);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   214
				}
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   215
			} while (type == SSH2_MSG_KEXGSS_HOSTKEY);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   216
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   217
			switch (type) {
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   218
			case SSH2_MSG_KEXGSS_CONTINUE:
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   219
				debug("Received GSSAPI_CONTINUE");
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   220
				if (maj_status == GSS_S_COMPLETE)
7561
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   221
					packet_disconnect("Protocol error: "
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   222
					    "received GSS-API context token "
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   223
					    "but the context was already "
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   224
					    "established");
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   225
				recv_tok.value = packet_get_string(&strlen);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   226
				recv_tok.length = strlen;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   227
				break;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   228
			case SSH2_MSG_KEXGSS_COMPLETE:
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   229
				debug("Received GSSAPI_COMPLETE");
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   230
				packet_get_bignum2(dh_server_pub);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   231
				msg_tok.value =  packet_get_string(&strlen);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   232
				msg_tok.length = strlen;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   233
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   234
				/* Is there a token included? */
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   235
				if (packet_get_char()) {
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   236
					recv_tok.value=
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   237
					    packet_get_string(&strlen);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   238
					recv_tok.length = strlen;
7561
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   239
				}
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   240
				if (recv_tok.length > 0 &&
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   241
				    maj_status == GSS_S_COMPLETE) {
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   242
					packet_disconnect("Protocol error: "
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   243
					    "received GSS-API context token "
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   244
					    "but the context was already "
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   245
					    "established");
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   246
				} else if (recv_tok.length == 0 &&
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   247
				    maj_status == GSS_S_CONTINUE_NEEDED) {
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   248
					/* No token included */
7561
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   249
					packet_disconnect("Protocol error: "
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   250
					    "did not receive expected "
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   251
					    "GSS-API context token");
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   252
				}
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   253
				break;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   254
			case SSH2_MSG_KEXGSS_ERROR:
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   255
				debug("Received Error");
7561
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   256
				smaj_status = packet_get_int();
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   257
				smin_status = packet_get_int();
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   258
				msg = packet_get_string(NULL);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   259
				lang = packet_get_string(NULL);
7561
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   260
				free(lang);
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   261
				error("Server had a GSS-API error; the "
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   262
				    "connection will close (%u/%u):\n%s",
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   263
				    smaj_status, smin_status, msg);
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   264
				free(msg);
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   265
				error(GSSKEX_ERRHINT);
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   266
				packet_disconnect("The server encountered "
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   267
				    "a GSS-API error during GSS-API protected "
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   268
				    "key exchange\n");
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   269
				break;
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   270
			default:
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   271
				packet_disconnect("Protocol error: didn't"
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   272
				    " expect packet type %d", type);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   273
			}
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   274
			token_ptr = &recv_tok;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   275
		} else {
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   276
			/* No data, and not complete */
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   277
			if (maj_status != GSS_S_COMPLETE)
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   278
				fatal("Not complete, and no token output");
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   279
		}
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   280
	} while (maj_status & GSS_S_CONTINUE_NEEDED);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   281
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   282
	/*
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   283
	 * We _must_ have received a COMPLETE message in reply from the
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   284
	 * server, which will have set dh_server_pub and msg_tok
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   285
	 */
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   286
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   287
	if (type != SSH2_MSG_KEXGSS_COMPLETE)
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   288
		fatal("Didn't receive SSH2_MSG_KEXGSS_COMPLETE when expected");
7561
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   289
	if (maj_status != GSS_S_COMPLETE)
64cbdac1f406 25055579 ssh should be more descriptive when GSS key exchange fails
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 6930
diff changeset
   290
		fatal("Internal error in GSS-API protected key exchange");
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   291
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   292
	/* Check f in range [1, p-1] */
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
   293
	if (!dh_pub_is_valid(kex->dh, dh_server_pub))
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   294
		packet_disconnect("bad server public DH value");
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   295
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   296
	/* compute K=f^x mod p */
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
   297
	klen = DH_size(kex->dh);
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   298
	kbuf = xmalloc(klen);
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
   299
	kout = DH_compute_key(kbuf, dh_server_pub, kex->dh);
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   300
	if (kout < 0)
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   301
		fatal("DH_compute_key: failed");
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   302
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   303
	shared_secret = BN_new();
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   304
	if (shared_secret == NULL)
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   305
		fatal("kexgss_client: BN_new failed");
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   306
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   307
	if (BN_bin2bn(kbuf, kout, shared_secret) == NULL)
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   308
		fatal("kexdh_client: BN_bin2bn failed");
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   309
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   310
	memset(kbuf, 0, klen);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   311
	free(kbuf);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   312
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
   313
	hashlen = sizeof (hash);
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   314
	switch (kex->kex_type) {
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   315
	case KEX_GSS_GRP1_SHA1:
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   316
	case KEX_GSS_GRP14_SHA1:
6930
31ef2580c45d 24525860 upgrade OpenSSH to 7.3p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 4503
diff changeset
   317
		kex_dh_hash(
31ef2580c45d 24525860 upgrade OpenSSH to 7.3p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 4503
diff changeset
   318
		    kex->hash_alg,
31ef2580c45d 24525860 upgrade OpenSSH to 7.3p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 4503
diff changeset
   319
		    kex->client_version_string,
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   320
		    kex->server_version_string,
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
   321
		    buffer_ptr(kex->my), buffer_len(kex->my),
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
   322
		    buffer_ptr(kex->peer), buffer_len(kex->peer),
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   323
		    (serverhostkey ? serverhostkey : empty), slen,
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
   324
		    kex->dh->pub_key,	/* e */
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   325
		    dh_server_pub,	/* f */
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   326
		    shared_secret,	/* K */
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
   327
		    hash, &hashlen);
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   328
		break;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   329
	case KEX_GSS_GEX_SHA1:
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   330
		kexgex_hash(
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   331
		    kex->hash_alg,
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   332
		    kex->client_version_string,
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   333
		    kex->server_version_string,
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
   334
		    buffer_ptr(kex->my), buffer_len(kex->my),
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
   335
		    buffer_ptr(kex->peer), buffer_len(kex->peer),
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   336
		    (serverhostkey ? serverhostkey : empty), slen,
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   337
		    min, nbits, max,
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
   338
		    kex->dh->p, kex->dh->g,
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
   339
		    kex->dh->pub_key,
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   340
		    dh_server_pub,
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   341
		    shared_secret,
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
   342
		    hash, &hashlen);
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   343
		break;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   344
	default:
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   345
		fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   346
	}
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   347
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   348
	gssbuf.value = hash;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   349
	gssbuf.length = hashlen;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   350
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   351
	/* Verify that the hash matches the MIC we just got. */
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   352
	if (GSS_ERROR(ssh_gssapi_checkmic(ctxt, &gssbuf, &msg_tok)))
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   353
		packet_disconnect("Hash's MIC didn't verify");
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   354
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   355
	free(msg_tok.value);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   356
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
   357
	DH_free(kex->dh);
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   358
	if (serverhostkey)
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   359
		free(serverhostkey);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   360
	BN_clear_free(dh_server_pub);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   361
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   362
	/* save session id */
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   363
	if (kex->session_id == NULL) {
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   364
		kex->session_id_len = hashlen;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   365
		kex->session_id = xmalloc(kex->session_id_len);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   366
		memcpy(kex->session_id, hash, kex->session_id_len);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   367
	}
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   368
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   369
	if (gss_kex_context == NULL)
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   370
		gss_kex_context = ctxt;
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   371
	else
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   372
		ssh_gssapi_delete_ctx(&ctxt);
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   373
4503
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
   374
	if ((r = kex_derive_keys_bn(ssh, hash, hashlen, shared_secret)) == 0)
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
   375
		r = kex_send_newkeys(ssh);
bf30d46ab06e PSARC/2015/179 OpenSSH 6.8
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 3574
diff changeset
   376
	return (r);
3574
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   377
}
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   378
80e9a4e240d3 PSARC/2014/390 OpenSSH GSSKEY
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   379
#endif /* GSSAPI */