10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved. * 30Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 40Sstevel@tonic-gate * modification, are permitted provided that the following conditions 50Sstevel@tonic-gate * are met: 60Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 70Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 80Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 90Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the 100Sstevel@tonic-gate * documentation and/or other materials provided with the distribution. 110Sstevel@tonic-gate * 120Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR 130Sstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 140Sstevel@tonic-gate * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 150Sstevel@tonic-gate * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 160Sstevel@tonic-gate * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 170Sstevel@tonic-gate * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 180Sstevel@tonic-gate * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 190Sstevel@tonic-gate * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 200Sstevel@tonic-gate * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 210Sstevel@tonic-gate * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 220Sstevel@tonic-gate */ 230Sstevel@tonic-gate /* 24*6080Sjp161948 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 250Sstevel@tonic-gate * Use is subject to license terms. 260Sstevel@tonic-gate */ 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include "includes.h" 290Sstevel@tonic-gate 300Sstevel@tonic-gate #ifdef GSSAPI 310Sstevel@tonic-gate 320Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 330Sstevel@tonic-gate 340Sstevel@tonic-gate #include "ssh.h" 350Sstevel@tonic-gate #include "ssh2.h" 360Sstevel@tonic-gate #include "xmalloc.h" 370Sstevel@tonic-gate #include "buffer.h" 380Sstevel@tonic-gate #include "bufaux.h" 390Sstevel@tonic-gate #include "packet.h" 400Sstevel@tonic-gate #include "compat.h" 410Sstevel@tonic-gate #include <openssl/evp.h> 420Sstevel@tonic-gate #include "cipher.h" 430Sstevel@tonic-gate #include "kex.h" 440Sstevel@tonic-gate #include "log.h" 450Sstevel@tonic-gate #include "compat.h" 460Sstevel@tonic-gate #include "xlist.h" 470Sstevel@tonic-gate 480Sstevel@tonic-gate #include <netdb.h> 490Sstevel@tonic-gate 500Sstevel@tonic-gate #include "ssh-gss.h" 510Sstevel@tonic-gate 520Sstevel@tonic-gate #ifdef HAVE_GSS_OID_TO_MECH 530Sstevel@tonic-gate #include <gssapi/gssapi_ext.h> 540Sstevel@tonic-gate #endif /* HAVE_GSS_OID_TO_MECH */ 550Sstevel@tonic-gate 560Sstevel@tonic-gate typedef struct { 570Sstevel@tonic-gate char *encoded; 580Sstevel@tonic-gate gss_OID oid; 590Sstevel@tonic-gate } ssh_gss_kex_mapping; 600Sstevel@tonic-gate 610Sstevel@tonic-gate static ssh_gss_kex_mapping **gss_enc2oid = NULL; 620Sstevel@tonic-gate 630Sstevel@tonic-gate static void ssh_gssapi_encode_oid_for_kex(const gss_OID oid, char **enc_name); 640Sstevel@tonic-gate static char *ssh_gssapi_make_kexalgs_list(gss_OID_set mechs, 65*6080Sjp161948 const char *old_kexalgs); 660Sstevel@tonic-gate 670Sstevel@tonic-gate /* 680Sstevel@tonic-gate * Populate gss_enc2oid table and return list of kexnames. 690Sstevel@tonic-gate * 700Sstevel@tonic-gate * If called with both mechs == GSS_C_NULL_OID_SET and kexname_list == NULL 710Sstevel@tonic-gate * then cached gss_enc2oid table is cleaned up. 720Sstevel@tonic-gate */ 730Sstevel@tonic-gate void 740Sstevel@tonic-gate ssh_gssapi_mech_oids_to_kexnames(const gss_OID_set mechs, char **kexname_list) 750Sstevel@tonic-gate { 760Sstevel@tonic-gate ssh_gss_kex_mapping **new_gss_enc2oid, **p; 770Sstevel@tonic-gate Buffer buf; 780Sstevel@tonic-gate char *enc_name; 790Sstevel@tonic-gate int i; 800Sstevel@tonic-gate 810Sstevel@tonic-gate if (kexname_list != NULL) 820Sstevel@tonic-gate *kexname_list = NULL; /* default to failed */ 830Sstevel@tonic-gate 840Sstevel@tonic-gate if (mechs != GSS_C_NULL_OID_SET || kexname_list == NULL) { 850Sstevel@tonic-gate /* Cleanup gss_enc2oid table */ 86*6080Sjp161948 for (p = gss_enc2oid; p != NULL && *p != NULL; p++) { 870Sstevel@tonic-gate if ((*p)->encoded) 880Sstevel@tonic-gate xfree((*p)->encoded); 890Sstevel@tonic-gate ssh_gssapi_release_oid(&(*p)->oid); 900Sstevel@tonic-gate xfree(*p); 910Sstevel@tonic-gate } 920Sstevel@tonic-gate if (gss_enc2oid) 930Sstevel@tonic-gate xfree(gss_enc2oid); 940Sstevel@tonic-gate } 950Sstevel@tonic-gate 960Sstevel@tonic-gate if (mechs == GSS_C_NULL_OID_SET && kexname_list == NULL) 970Sstevel@tonic-gate return; /* nothing left to do */ 980Sstevel@tonic-gate 990Sstevel@tonic-gate if (mechs) { 1000Sstevel@tonic-gate gss_OID mech; 1010Sstevel@tonic-gate /* Populate gss_enc2oid table */ 102*6080Sjp161948 new_gss_enc2oid = xmalloc(sizeof (ssh_gss_kex_mapping *) * 103*6080Sjp161948 (mechs->count + 1)); 1040Sstevel@tonic-gate memset(new_gss_enc2oid, 0, 105*6080Sjp161948 sizeof (ssh_gss_kex_mapping *) * (mechs->count + 1)); 1060Sstevel@tonic-gate 107*6080Sjp161948 for (i = 0; i < mechs->count; i++) { 1080Sstevel@tonic-gate mech = &mechs->elements[i]; 1090Sstevel@tonic-gate ssh_gssapi_encode_oid_for_kex((const gss_OID)mech, 110*6080Sjp161948 &enc_name); 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate if (!enc_name) 1130Sstevel@tonic-gate continue; 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate new_gss_enc2oid[i] = 116*6080Sjp161948 xmalloc(sizeof (ssh_gss_kex_mapping)); 1170Sstevel@tonic-gate (new_gss_enc2oid[i])->encoded = enc_name; 1180Sstevel@tonic-gate (new_gss_enc2oid[i])->oid = 119*6080Sjp161948 ssh_gssapi_dup_oid(&mechs->elements[i]); 1200Sstevel@tonic-gate } 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate /* Do this last to avoid run-ins with fatal_cleanups */ 1230Sstevel@tonic-gate gss_enc2oid = new_gss_enc2oid; 1240Sstevel@tonic-gate } 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate if (!kexname_list) 1270Sstevel@tonic-gate return; /* nothing left to do */ 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate /* Make kex name list */ 1300Sstevel@tonic-gate buffer_init(&buf); 131*6080Sjp161948 for (p = gss_enc2oid; p && *p; p++) { 132*6080Sjp161948 buffer_put_char(&buf, ','); 1330Sstevel@tonic-gate buffer_append(&buf, (*p)->encoded, strlen((*p)->encoded)); 1340Sstevel@tonic-gate } 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate if (buffer_len(&buf) == 0) { 1370Sstevel@tonic-gate buffer_free(&buf); 1380Sstevel@tonic-gate return; 1390Sstevel@tonic-gate } 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate buffer_consume(&buf, 1); /* consume leading ',' */ 142*6080Sjp161948 buffer_put_char(&buf, '\0'); 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate *kexname_list = xstrdup(buffer_ptr(&buf)); 1450Sstevel@tonic-gate buffer_free(&buf); 1460Sstevel@tonic-gate } 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate void 1490Sstevel@tonic-gate ssh_gssapi_mech_oid_to_kexname(const gss_OID mech, char **kexname) 1500Sstevel@tonic-gate { 1510Sstevel@tonic-gate ssh_gss_kex_mapping **p; 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate if (mech == GSS_C_NULL_OID || !kexname) 1540Sstevel@tonic-gate return; 1550Sstevel@tonic-gate 1560Sstevel@tonic-gate *kexname = NULL; /* default to not found */ 1570Sstevel@tonic-gate if (gss_enc2oid) { 158*6080Sjp161948 for (p = gss_enc2oid; p && *p; p++) { 1590Sstevel@tonic-gate if (mech->length == (*p)->oid->length && 1600Sstevel@tonic-gate memcmp(mech->elements, (*p)->oid->elements, 161*6080Sjp161948 mech->length) == 0) 1620Sstevel@tonic-gate *kexname = xstrdup((*p)->encoded); 1630Sstevel@tonic-gate } 1640Sstevel@tonic-gate } 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate if (*kexname) 1670Sstevel@tonic-gate return; /* found */ 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate ssh_gssapi_encode_oid_for_kex(mech, kexname); 1700Sstevel@tonic-gate } 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate void 1730Sstevel@tonic-gate ssh_gssapi_oid_of_kexname(const char *kexname, gss_OID *mech) 1740Sstevel@tonic-gate { 1750Sstevel@tonic-gate ssh_gss_kex_mapping **p; 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate if (!mech || !kexname || !*kexname) 1780Sstevel@tonic-gate return; 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate *mech = GSS_C_NULL_OID; /* default to not found */ 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate if (!gss_enc2oid) 1830Sstevel@tonic-gate return; 1840Sstevel@tonic-gate 185*6080Sjp161948 for (p = gss_enc2oid; p && *p; p++) { 1860Sstevel@tonic-gate if (strcmp(kexname, (*p)->encoded) == 0) { 1870Sstevel@tonic-gate *mech = (*p)->oid; 1880Sstevel@tonic-gate return; 1890Sstevel@tonic-gate } 1900Sstevel@tonic-gate } 1910Sstevel@tonic-gate } 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate static 1940Sstevel@tonic-gate void 1950Sstevel@tonic-gate ssh_gssapi_encode_oid_for_kex(const gss_OID oid, char **enc_name) 1960Sstevel@tonic-gate { 197*6080Sjp161948 Buffer buf; 198*6080Sjp161948 OM_uint32 oidlen; 199*6080Sjp161948 uint_t enclen; 200*6080Sjp161948 const EVP_MD *evp_md = EVP_md5(); 201*6080Sjp161948 EVP_MD_CTX md; 202*6080Sjp161948 uchar_t digest[EVP_MAX_MD_SIZE]; 203*6080Sjp161948 char *encoded; 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate if (oid == GSS_C_NULL_OID || !enc_name) 2060Sstevel@tonic-gate return; 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate *enc_name = NULL; 2090Sstevel@tonic-gate 2100Sstevel@tonic-gate oidlen = oid->length; 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate /* No GSS mechs have OIDs as long as 128 -- simplify DER encoding */ 2130Sstevel@tonic-gate if (oidlen > 128) 2140Sstevel@tonic-gate return; /* fail gracefully */ 2150Sstevel@tonic-gate 2160Sstevel@tonic-gate /* 2170Sstevel@tonic-gate * NOTE: If we need to support SSH_BUG_GSSAPI_BER this is where 2180Sstevel@tonic-gate * we'd do it. 2190Sstevel@tonic-gate * 2200Sstevel@tonic-gate * That means using "Se3H81ismmOC3OE+FwYCiQ==" for the Kerberos 2210Sstevel@tonic-gate * V mech and "N3+k7/4wGxHyuP8Yxi4RhA==" for the GSI mech. Ick. 2220Sstevel@tonic-gate */ 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate buffer_init(&buf); 2250Sstevel@tonic-gate 2260Sstevel@tonic-gate /* UNIVERSAL class tag for OBJECT IDENTIFIER */ 2270Sstevel@tonic-gate buffer_put_char(&buf, 0x06); 2280Sstevel@tonic-gate buffer_put_char(&buf, oidlen); /* one octet DER length -- see above */ 2290Sstevel@tonic-gate 2300Sstevel@tonic-gate /* OID elements */ 2310Sstevel@tonic-gate buffer_append(&buf, oid->elements, oidlen); 2320Sstevel@tonic-gate 2330Sstevel@tonic-gate /* Make digest */ 2340Sstevel@tonic-gate EVP_DigestInit(&md, evp_md); 2350Sstevel@tonic-gate EVP_DigestUpdate(&md, buffer_ptr(&buf), buffer_len(&buf)); 2360Sstevel@tonic-gate EVP_DigestFinal(&md, digest, NULL); 2370Sstevel@tonic-gate buffer_free(&buf); 2380Sstevel@tonic-gate 2390Sstevel@tonic-gate /* Base 64 encoding */ 240*6080Sjp161948 encoded = xmalloc(EVP_MD_size(evp_md)*2); 241*6080Sjp161948 enclen = __b64_ntop(digest, EVP_MD_size(evp_md), 242*6080Sjp161948 encoded, EVP_MD_size(evp_md) * 2); 2430Sstevel@tonic-gate buffer_init(&buf); 244*6080Sjp161948 buffer_append(&buf, KEX_GSS_SHA1, sizeof (KEX_GSS_SHA1) - 1); 2450Sstevel@tonic-gate buffer_append(&buf, encoded, enclen); 2460Sstevel@tonic-gate buffer_put_char(&buf, '\0'); 247*6080Sjp161948 248*6080Sjp161948 debug2("GSS-API Mechanism encoded as %s", encoded); 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate *enc_name = xstrdup(buffer_ptr(&buf)); 2510Sstevel@tonic-gate buffer_free(&buf); 2520Sstevel@tonic-gate } 2530Sstevel@tonic-gate 254*6080Sjp161948 static char * 2550Sstevel@tonic-gate ssh_gssapi_make_kexalgs_list(gss_OID_set mechs, const char *old_kexalgs) 2560Sstevel@tonic-gate { 2570Sstevel@tonic-gate char *gss_kexalgs, *new_kexalgs; 2580Sstevel@tonic-gate int len; 2590Sstevel@tonic-gate 2600Sstevel@tonic-gate if (mechs == GSS_C_NULL_OID_SET) 2610Sstevel@tonic-gate return (xstrdup(old_kexalgs)); /* never null */ 2620Sstevel@tonic-gate 2630Sstevel@tonic-gate ssh_gssapi_mech_oids_to_kexnames(mechs, &gss_kexalgs); 2640Sstevel@tonic-gate 2650Sstevel@tonic-gate if (gss_kexalgs == NULL || *gss_kexalgs == '\0') 2660Sstevel@tonic-gate return (xstrdup(old_kexalgs)); /* never null */ 2670Sstevel@tonic-gate 2680Sstevel@tonic-gate if (old_kexalgs == NULL || *old_kexalgs == '\0') 2690Sstevel@tonic-gate return (gss_kexalgs); 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate len = strlen(old_kexalgs) + strlen(gss_kexalgs) + 2; 2720Sstevel@tonic-gate new_kexalgs = xmalloc(len); 2730Sstevel@tonic-gate (void) snprintf(new_kexalgs, len, "%s,%s", gss_kexalgs, old_kexalgs); 2740Sstevel@tonic-gate 2750Sstevel@tonic-gate return (new_kexalgs); 2760Sstevel@tonic-gate } 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate void 2790Sstevel@tonic-gate ssh_gssapi_modify_kex(Kex *kex, gss_OID_set mechs, char **proposal) 2800Sstevel@tonic-gate { 2810Sstevel@tonic-gate char *kexalgs, *orig_kexalgs, *p; 2820Sstevel@tonic-gate char **hostalg, *orig_hostalgs, *new_hostalgs; 2830Sstevel@tonic-gate char **hostalgs; 2840Sstevel@tonic-gate gss_OID_set dup_mechs; 2850Sstevel@tonic-gate OM_uint32 maj, min; 2860Sstevel@tonic-gate int i; 2870Sstevel@tonic-gate 2880Sstevel@tonic-gate if (kex == NULL || proposal == NULL || 2890Sstevel@tonic-gate (orig_kexalgs = proposal[PROPOSAL_KEX_ALGS]) == NULL) { 2900Sstevel@tonic-gate fatal("INTERNAL ERROR (%s)", __func__); 2910Sstevel@tonic-gate } 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate orig_hostalgs = proposal[PROPOSAL_SERVER_HOST_KEY_ALGS]; 2940Sstevel@tonic-gate 2950Sstevel@tonic-gate if (kex->mechs == GSS_C_NULL_OID_SET && mechs == GSS_C_NULL_OID_SET) 2960Sstevel@tonic-gate return; /* didn't offer GSS last time, not offering now */ 2970Sstevel@tonic-gate 2980Sstevel@tonic-gate if (kex->mechs == GSS_C_NULL_OID_SET || mechs == GSS_C_NULL_OID_SET) 2990Sstevel@tonic-gate goto mod_offer; /* didn't offer last time or not offering now */ 3000Sstevel@tonic-gate 3010Sstevel@tonic-gate /* Check if mechs is congruent to kex->mechs (last offered) */ 3020Sstevel@tonic-gate if (kex->mechs->count == mechs->count) { 3030Sstevel@tonic-gate int present, matches = 0; 3040Sstevel@tonic-gate 305*6080Sjp161948 for (i = 0; i < mechs->count; i++) { 3060Sstevel@tonic-gate maj = gss_test_oid_set_member(&min, 307*6080Sjp161948 &kex->mechs->elements[i], mechs, &present); 3080Sstevel@tonic-gate 3090Sstevel@tonic-gate if (GSS_ERROR(maj)) { 3100Sstevel@tonic-gate mechs = GSS_C_NULL_OID_SET; 3110Sstevel@tonic-gate break; 3120Sstevel@tonic-gate } 3130Sstevel@tonic-gate 3140Sstevel@tonic-gate matches += (present) ? 1 : 0; 3150Sstevel@tonic-gate } 3160Sstevel@tonic-gate 3170Sstevel@tonic-gate if (matches == kex->mechs->count) 3180Sstevel@tonic-gate return; /* no change in offer from last time */ 3190Sstevel@tonic-gate } 3200Sstevel@tonic-gate 3210Sstevel@tonic-gate mod_offer: 3220Sstevel@tonic-gate /* 3230Sstevel@tonic-gate * Remove previously offered mechs from PROPOSAL_KEX_ALGS proposal 3240Sstevel@tonic-gate * 3250Sstevel@tonic-gate * ASSUMPTION: GSS-API kex algs always go in front, so removing 3260Sstevel@tonic-gate * them is a matter of skipping them. 3270Sstevel@tonic-gate */ 3280Sstevel@tonic-gate p = kexalgs = orig_kexalgs = proposal[PROPOSAL_KEX_ALGS]; 3290Sstevel@tonic-gate while (p != NULL && *p != '\0' && 330*6080Sjp161948 strncmp(p, KEX_GSS_SHA1, strlen(KEX_GSS_SHA1)) == 0) { 3310Sstevel@tonic-gate 3320Sstevel@tonic-gate if ((p = strchr(p, ',')) == NULL) 3330Sstevel@tonic-gate break; 3340Sstevel@tonic-gate p++; 3350Sstevel@tonic-gate kexalgs = p; 3360Sstevel@tonic-gate 3370Sstevel@tonic-gate } 3380Sstevel@tonic-gate kexalgs = proposal[PROPOSAL_KEX_ALGS] = xstrdup(kexalgs); 3390Sstevel@tonic-gate xfree(orig_kexalgs); 3400Sstevel@tonic-gate 3410Sstevel@tonic-gate (void) gss_release_oid_set(&min, &kex->mechs); /* ok if !kex->mechs */ 3420Sstevel@tonic-gate 3430Sstevel@tonic-gate /* Not offering GSS kexalgs now -> all done */ 3440Sstevel@tonic-gate if (mechs == GSS_C_NULL_OID_SET) 3450Sstevel@tonic-gate return; 3460Sstevel@tonic-gate 3470Sstevel@tonic-gate /* Remember mechs we're offering */ 3480Sstevel@tonic-gate maj = gss_create_empty_oid_set(&min, &dup_mechs); 3490Sstevel@tonic-gate if (GSS_ERROR(maj)) 3500Sstevel@tonic-gate return; 351*6080Sjp161948 for (i = 0; i < mechs->count; i++) { 3520Sstevel@tonic-gate maj = gss_add_oid_set_member(&min, &mechs->elements[i], 353*6080Sjp161948 &dup_mechs); 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate if (GSS_ERROR(maj)) { 3560Sstevel@tonic-gate (void) gss_release_oid_set(&min, &dup_mechs); 3570Sstevel@tonic-gate return; 3580Sstevel@tonic-gate } 3590Sstevel@tonic-gate } 3600Sstevel@tonic-gate 3610Sstevel@tonic-gate /* Add mechs to kexalgs ... */ 362*6080Sjp161948 proposal[PROPOSAL_KEX_ALGS] = ssh_gssapi_make_kexalgs_list(mechs, 363*6080Sjp161948 kexalgs); 3640Sstevel@tonic-gate kex->mechs = dup_mechs; /* remember what we offer now */ 3650Sstevel@tonic-gate 3660Sstevel@tonic-gate /* 3670Sstevel@tonic-gate * ... and add null host key alg, if it wasn't there before, but 3680Sstevel@tonic-gate * not if we're the server and we have other host key algs to 3690Sstevel@tonic-gate * offer. 3700Sstevel@tonic-gate * 3710Sstevel@tonic-gate * NOTE: Never remove "null" host key alg once added. 3720Sstevel@tonic-gate */ 3730Sstevel@tonic-gate if (orig_hostalgs == NULL || *orig_hostalgs == '\0') { 3740Sstevel@tonic-gate proposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = xstrdup("null"); 3750Sstevel@tonic-gate } else if (!kex->server) { 3760Sstevel@tonic-gate hostalgs = xsplit(orig_hostalgs, ','); 377*6080Sjp161948 for (hostalg = hostalgs; *hostalg != NULL; hostalg++) { 3780Sstevel@tonic-gate if (strcmp(*hostalg, "null") == 0) { 3790Sstevel@tonic-gate xfree_split_list(hostalgs); 3800Sstevel@tonic-gate return; 3810Sstevel@tonic-gate } 3820Sstevel@tonic-gate } 3830Sstevel@tonic-gate xfree_split_list(hostalgs); 3840Sstevel@tonic-gate 3850Sstevel@tonic-gate if (kex->mechs != GSS_C_NULL_OID_SET) { 3860Sstevel@tonic-gate int len; 3870Sstevel@tonic-gate 388*6080Sjp161948 len = strlen(orig_hostalgs) + sizeof (",null"); 3890Sstevel@tonic-gate new_hostalgs = xmalloc(len); 3900Sstevel@tonic-gate (void) snprintf(new_hostalgs, len, "%s,null", 391*6080Sjp161948 orig_hostalgs); 3920Sstevel@tonic-gate proposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = new_hostalgs; 3930Sstevel@tonic-gate } 3940Sstevel@tonic-gate 3950Sstevel@tonic-gate xfree(orig_hostalgs); 3960Sstevel@tonic-gate } 3970Sstevel@tonic-gate } 3980Sstevel@tonic-gate 3990Sstevel@tonic-gate /* 4000Sstevel@tonic-gate * Yes, we harcode OIDs for some things, for now it's all we can do. 4010Sstevel@tonic-gate * 4020Sstevel@tonic-gate * We have to reference particular mechanisms due to lack of generality 4030Sstevel@tonic-gate * in the GSS-API in several areas: authorization, mapping principal 4040Sstevel@tonic-gate * names to usernames, "storing" delegated credentials, and discovering 4050Sstevel@tonic-gate * whether a mechanism is a pseudo-mechanism that negotiates mechanisms. 4060Sstevel@tonic-gate * 4070Sstevel@tonic-gate * Even if they were in some header file or if __gss_mech_to_oid() 4080Sstevel@tonic-gate * and/or __gss_oid_to_mech() were standard we'd still have to hardcode 4090Sstevel@tonic-gate * the mechanism names, and since the mechanisms have no standard names 4100Sstevel@tonic-gate * other than their OIDs it's actually worse [less portable] to hardcode 4110Sstevel@tonic-gate * names than OIDs, so we hardcode OIDs. 4120Sstevel@tonic-gate * 4130Sstevel@tonic-gate * SPNEGO is a difficult problem though -- it MUST NOT be used in SSHv2, 4140Sstevel@tonic-gate * but that's true of all possible pseudo-mechanisms that can perform 4150Sstevel@tonic-gate * mechanism negotiation, and SPNEGO could have new OIDs in the future. 4160Sstevel@tonic-gate * Ideally we could query each mechanism for its feature set and then 4170Sstevel@tonic-gate * ignore any mechanisms that negotiate mechanisms, but, alas, there's 4180Sstevel@tonic-gate * no interface to do that. 4190Sstevel@tonic-gate * 4200Sstevel@tonic-gate * In the future, if the necessary generic GSS interfaces for the issues 4210Sstevel@tonic-gate * listed above are made available (even if they differ by platform, as 4220Sstevel@tonic-gate * we can expect authorization interfaces will), then we can stop 4230Sstevel@tonic-gate * referencing specific mechanism OIDs here. 4240Sstevel@tonic-gate */ 4250Sstevel@tonic-gate int 4260Sstevel@tonic-gate ssh_gssapi_is_spnego(gss_OID oid) 4270Sstevel@tonic-gate { 4280Sstevel@tonic-gate return (oid->length == 6 && 429*6080Sjp161948 memcmp("\053\006\001\005\005\002", oid->elements, 6) == 0); 4300Sstevel@tonic-gate } 4310Sstevel@tonic-gate 4320Sstevel@tonic-gate int 4330Sstevel@tonic-gate ssh_gssapi_is_krb5(gss_OID oid) 4340Sstevel@tonic-gate { 4350Sstevel@tonic-gate return (oid->length == 9 && 436*6080Sjp161948 memcmp("\x2A\x86\x48\x86\xF7\x12\x01\x02\x02", 437*6080Sjp161948 oid->elements, 9) == 0); 4380Sstevel@tonic-gate } 4390Sstevel@tonic-gate 4400Sstevel@tonic-gate int 4410Sstevel@tonic-gate ssh_gssapi_is_dh(gss_OID oid) 4420Sstevel@tonic-gate { 4430Sstevel@tonic-gate return (oid->length == 9 && 444*6080Sjp161948 memcmp("\053\006\004\001\052\002\032\002\005", 445*6080Sjp161948 oid->elements, 9) == 0); 4460Sstevel@tonic-gate } 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate int 4490Sstevel@tonic-gate ssh_gssapi_is_gsi(gss_OID oid) 4500Sstevel@tonic-gate { 4510Sstevel@tonic-gate return (oid->length == 9 && 452*6080Sjp161948 memcmp("\x2B\x06\x01\x04\x01\x9B\x50\x01\x01", 453*6080Sjp161948 oid->elements, 9) == 0); 4540Sstevel@tonic-gate } 4550Sstevel@tonic-gate 456*6080Sjp161948 const char * 4570Sstevel@tonic-gate ssh_gssapi_oid_to_name(gss_OID oid) 4580Sstevel@tonic-gate { 4590Sstevel@tonic-gate #ifdef HAVE_GSS_OID_TO_MECH 460*6080Sjp161948 return (__gss_oid_to_mech(oid)); 4610Sstevel@tonic-gate #else 4620Sstevel@tonic-gate if (ssh_gssapi_is_krb5(oid)) 463*6080Sjp161948 return ("Kerberos"); 4640Sstevel@tonic-gate if (ssh_gssapi_is_gsi(oid)) 465*6080Sjp161948 return ("GSI"); 466*6080Sjp161948 return ("(unknown)"); 4670Sstevel@tonic-gate #endif /* HAVE_GSS_OID_TO_MECH */ 4680Sstevel@tonic-gate } 4690Sstevel@tonic-gate 4700Sstevel@tonic-gate char * 4710Sstevel@tonic-gate ssh_gssapi_oid_to_str(gss_OID oid) 4720Sstevel@tonic-gate { 4730Sstevel@tonic-gate #ifdef HAVE_GSS_OID_TO_STR 4740Sstevel@tonic-gate gss_buffer_desc str_buf; 4750Sstevel@tonic-gate char *str; 4760Sstevel@tonic-gate OM_uint32 maj, min; 4770Sstevel@tonic-gate 4780Sstevel@tonic-gate maj = gss_oid_to_str(&min, oid, &str_buf); 4790Sstevel@tonic-gate 4800Sstevel@tonic-gate if (GSS_ERROR(maj)) 481*6080Sjp161948 return (xstrdup("<gss_oid_to_str() failed>")); 4820Sstevel@tonic-gate 4830Sstevel@tonic-gate str = xmalloc(str_buf.length + 1); 4840Sstevel@tonic-gate memset(str, 0, str_buf.length + 1); 4850Sstevel@tonic-gate strlcpy(str, str_buf.value, str_buf.length + 1); 4860Sstevel@tonic-gate (void) gss_release_buffer(&min, &str_buf); 4870Sstevel@tonic-gate 488*6080Sjp161948 return (str); 4890Sstevel@tonic-gate #else 490*6080Sjp161948 return (xstrdup("<gss_oid_to_str() unsupported>")); 4910Sstevel@tonic-gate #endif /* HAVE_GSS_OID_TO_STR */ 4920Sstevel@tonic-gate } 4930Sstevel@tonic-gate 4940Sstevel@tonic-gate /* Check that the OID in a data stream matches that in the context */ 495*6080Sjp161948 int 496*6080Sjp161948 ssh_gssapi_check_mech_oid(Gssctxt *ctx, void *data, size_t len) 497*6080Sjp161948 { 4980Sstevel@tonic-gate 499*6080Sjp161948 return (ctx != NULL && ctx->desired_mech != GSS_C_NULL_OID && 500*6080Sjp161948 ctx->desired_mech->length == len && 501*6080Sjp161948 memcmp(ctx->desired_mech->elements, data, len) == 0); 5020Sstevel@tonic-gate } 5030Sstevel@tonic-gate 5040Sstevel@tonic-gate /* Set the contexts OID from a data stream */ 505*6080Sjp161948 void 506*6080Sjp161948 ssh_gssapi_set_oid_data(Gssctxt *ctx, void *data, size_t len) 507*6080Sjp161948 { 508*6080Sjp161948 if (ctx->actual_mech != GSS_C_NULL_OID) { 509*6080Sjp161948 xfree(ctx->actual_mech->elements); 510*6080Sjp161948 xfree(ctx->actual_mech); 511*6080Sjp161948 } 512*6080Sjp161948 ctx->actual_mech = xmalloc(sizeof (gss_OID_desc)); 513*6080Sjp161948 ctx->actual_mech->length = len; 514*6080Sjp161948 ctx->actual_mech->elements = xmalloc(len); 515*6080Sjp161948 memcpy(ctx->actual_mech->elements, data, len); 5160Sstevel@tonic-gate } 5170Sstevel@tonic-gate 5180Sstevel@tonic-gate /* Set the contexts OID */ 519*6080Sjp161948 void 520*6080Sjp161948 ssh_gssapi_set_oid(Gssctxt *ctx, gss_OID oid) 521*6080Sjp161948 { 522*6080Sjp161948 ssh_gssapi_set_oid_data(ctx, oid->elements, oid->length); 5230Sstevel@tonic-gate } 5240Sstevel@tonic-gate 5250Sstevel@tonic-gate /* All this effort to report an error ... */ 5260Sstevel@tonic-gate 5270Sstevel@tonic-gate void 5285562Sjp161948 ssh_gssapi_error(Gssctxt *ctxt, const char *where) 5295562Sjp161948 { 5305562Sjp161948 char *errmsg = ssh_gssapi_last_error(ctxt, NULL, NULL); 5315562Sjp161948 5325562Sjp161948 if (where != NULL) 5335562Sjp161948 debug("GSS-API error while %s: %s", where, errmsg); 5340Sstevel@tonic-gate else 5355562Sjp161948 debug("GSS-API error: %s", errmsg); 5365562Sjp161948 5375562Sjp161948 /* ssh_gssapi_last_error() can't return NULL */ 5385562Sjp161948 xfree(errmsg); 5390Sstevel@tonic-gate } 5400Sstevel@tonic-gate 5410Sstevel@tonic-gate char * 542*6080Sjp161948 ssh_gssapi_last_error(Gssctxt *ctxt, OM_uint32 *major_status, 543*6080Sjp161948 OM_uint32 *minor_status) 544*6080Sjp161948 { 5450Sstevel@tonic-gate OM_uint32 lmin, more; 5460Sstevel@tonic-gate OM_uint32 maj, min; 5470Sstevel@tonic-gate gss_OID mech = GSS_C_NULL_OID; 548*6080Sjp161948 gss_buffer_desc msg; 549*6080Sjp161948 Buffer b; 550*6080Sjp161948 char *ret; 5510Sstevel@tonic-gate 552*6080Sjp161948 buffer_init(&b); 5530Sstevel@tonic-gate 5540Sstevel@tonic-gate if (ctxt) { 5550Sstevel@tonic-gate /* Get status codes from the Gssctxt */ 5560Sstevel@tonic-gate maj = ctxt->major; 5570Sstevel@tonic-gate min = ctxt->minor; 5580Sstevel@tonic-gate /* Output them if desired */ 5590Sstevel@tonic-gate if (major_status) 5600Sstevel@tonic-gate *major_status = maj; 5610Sstevel@tonic-gate if (minor_status) 5620Sstevel@tonic-gate *minor_status = min; 5630Sstevel@tonic-gate /* Get mechanism for minor status display */ 5640Sstevel@tonic-gate mech = (ctxt->actual_mech != GSS_C_NULL_OID) ? 565*6080Sjp161948 ctxt->actual_mech : ctxt->desired_mech; 5660Sstevel@tonic-gate } else if (major_status && minor_status) { 5670Sstevel@tonic-gate maj = *major_status; 5680Sstevel@tonic-gate min = *major_status; 5690Sstevel@tonic-gate } else { 5700Sstevel@tonic-gate maj = GSS_S_COMPLETE; 5710Sstevel@tonic-gate min = 0; 5720Sstevel@tonic-gate } 5730Sstevel@tonic-gate 574*6080Sjp161948 more = 0; 5750Sstevel@tonic-gate /* The GSSAPI error */ 576*6080Sjp161948 do { 577*6080Sjp161948 gss_display_status(&lmin, maj, GSS_C_GSS_CODE, 578*6080Sjp161948 GSS_C_NULL_OID, &more, &msg); 5790Sstevel@tonic-gate 580*6080Sjp161948 buffer_append(&b, msg.value, msg.length); 581*6080Sjp161948 buffer_put_char(&b, '\n'); 582*6080Sjp161948 gss_release_buffer(&lmin, &msg); 583*6080Sjp161948 } while (more != 0); 5840Sstevel@tonic-gate 585*6080Sjp161948 /* The mechanism specific error */ 586*6080Sjp161948 do { 5870Sstevel@tonic-gate /* 5880Sstevel@tonic-gate * If mech == GSS_C_NULL_OID we may get the default 5890Sstevel@tonic-gate * mechanism, whatever that is, and that may not be 5900Sstevel@tonic-gate * useful. 5910Sstevel@tonic-gate */ 592*6080Sjp161948 gss_display_status(&lmin, min, GSS_C_MECH_CODE, mech, &more, 593*6080Sjp161948 &msg); 5940Sstevel@tonic-gate 595*6080Sjp161948 buffer_append(&b, msg.value, msg.length); 596*6080Sjp161948 buffer_put_char(&b, '\n'); 5970Sstevel@tonic-gate 598*6080Sjp161948 gss_release_buffer(&lmin, &msg); 599*6080Sjp161948 } while (more != 0); 6000Sstevel@tonic-gate 601*6080Sjp161948 buffer_put_char(&b, '\0'); 602*6080Sjp161948 ret = xstrdup(buffer_ptr(&b)); 603*6080Sjp161948 buffer_free(&b); 6040Sstevel@tonic-gate 605*6080Sjp161948 return (ret); 6060Sstevel@tonic-gate } 6070Sstevel@tonic-gate 608*6080Sjp161948 /* 609*6080Sjp161948 * Initialise our GSSAPI context. We use this opaque structure to contain all 6100Sstevel@tonic-gate * of the data which both the client and server need to persist across 6110Sstevel@tonic-gate * {accept,init}_sec_context calls, so that when we do it from the userauth 6120Sstevel@tonic-gate * stuff life is a little easier 6130Sstevel@tonic-gate */ 6140Sstevel@tonic-gate void 6150Sstevel@tonic-gate ssh_gssapi_build_ctx(Gssctxt **ctx, int client, gss_OID mech) 6160Sstevel@tonic-gate { 6170Sstevel@tonic-gate Gssctxt *newctx; 6180Sstevel@tonic-gate 6190Sstevel@tonic-gate 6200Sstevel@tonic-gate newctx = (Gssctxt*)xmalloc(sizeof (Gssctxt)); 621*6080Sjp161948 memset(newctx, 0, sizeof (Gssctxt)); 6220Sstevel@tonic-gate 6231776Snw141292 6240Sstevel@tonic-gate newctx->local = client; 6250Sstevel@tonic-gate newctx->desired_mech = ssh_gssapi_dup_oid(mech); 626*6080Sjp161948 6270Sstevel@tonic-gate /* This happens to be redundant given the memset() above */ 6280Sstevel@tonic-gate newctx->major = GSS_S_COMPLETE; 6290Sstevel@tonic-gate newctx->context = GSS_C_NO_CONTEXT; 6300Sstevel@tonic-gate newctx->actual_mech = GSS_C_NULL_OID; 6310Sstevel@tonic-gate newctx->desired_name = GSS_C_NO_NAME; 6320Sstevel@tonic-gate newctx->src_name = GSS_C_NO_NAME; 6330Sstevel@tonic-gate newctx->dst_name = GSS_C_NO_NAME; 6340Sstevel@tonic-gate newctx->creds = GSS_C_NO_CREDENTIAL; 6350Sstevel@tonic-gate newctx->deleg_creds = GSS_C_NO_CREDENTIAL; 6360Sstevel@tonic-gate 6371776Snw141292 newctx->default_creds = (*ctx != NULL) ? (*ctx)->default_creds : 0; 6381776Snw141292 6391776Snw141292 ssh_gssapi_delete_ctx(ctx); 6401776Snw141292 6410Sstevel@tonic-gate *ctx = newctx; 6420Sstevel@tonic-gate } 6430Sstevel@tonic-gate 6440Sstevel@tonic-gate gss_OID 6450Sstevel@tonic-gate ssh_gssapi_dup_oid(gss_OID oid) 6460Sstevel@tonic-gate { 6470Sstevel@tonic-gate gss_OID new_oid; 6480Sstevel@tonic-gate 649*6080Sjp161948 new_oid = xmalloc(sizeof (gss_OID_desc)); 6500Sstevel@tonic-gate 6510Sstevel@tonic-gate new_oid->elements = xmalloc(oid->length); 6520Sstevel@tonic-gate new_oid->length = oid->length; 6530Sstevel@tonic-gate memcpy(new_oid->elements, oid->elements, oid->length); 6540Sstevel@tonic-gate 6550Sstevel@tonic-gate return (new_oid); 6560Sstevel@tonic-gate } 6570Sstevel@tonic-gate 6580Sstevel@tonic-gate gss_OID 6590Sstevel@tonic-gate ssh_gssapi_make_oid(size_t length, void *elements) 6600Sstevel@tonic-gate { 6610Sstevel@tonic-gate gss_OID_desc oid; 6620Sstevel@tonic-gate 6630Sstevel@tonic-gate oid.length = length; 6640Sstevel@tonic-gate oid.elements = elements; 6650Sstevel@tonic-gate 6660Sstevel@tonic-gate return (ssh_gssapi_dup_oid(&oid)); 6670Sstevel@tonic-gate } 6680Sstevel@tonic-gate 6690Sstevel@tonic-gate void 6700Sstevel@tonic-gate ssh_gssapi_release_oid(gss_OID *oid) 6710Sstevel@tonic-gate { 6720Sstevel@tonic-gate OM_uint32 min; 6730Sstevel@tonic-gate 6740Sstevel@tonic-gate if (oid && *oid == GSS_C_NULL_OID) 6750Sstevel@tonic-gate return; 6760Sstevel@tonic-gate (void) gss_release_oid(&min, oid); 6770Sstevel@tonic-gate 6780Sstevel@tonic-gate if (*oid == GSS_C_NULL_OID) 6790Sstevel@tonic-gate return; /* libgss did own this gss_OID and released it */ 6800Sstevel@tonic-gate 6810Sstevel@tonic-gate xfree((*oid)->elements); 6820Sstevel@tonic-gate xfree(*oid); 6830Sstevel@tonic-gate *oid = GSS_C_NULL_OID; 6840Sstevel@tonic-gate } 6850Sstevel@tonic-gate 6860Sstevel@tonic-gate struct gss_name { 687*6080Sjp161948 gss_OID name_type; 688*6080Sjp161948 gss_buffer_t external_name; 689*6080Sjp161948 gss_OID mech_type; 690*6080Sjp161948 void *mech_name; 6910Sstevel@tonic-gate }; 6920Sstevel@tonic-gate 6930Sstevel@tonic-gate /* Delete our context, providing it has been built correctly */ 6940Sstevel@tonic-gate void 6950Sstevel@tonic-gate ssh_gssapi_delete_ctx(Gssctxt **ctx) 6960Sstevel@tonic-gate { 6970Sstevel@tonic-gate OM_uint32 ms; 6980Sstevel@tonic-gate 6990Sstevel@tonic-gate if ((*ctx) == NULL) 7000Sstevel@tonic-gate return; 7010Sstevel@tonic-gate 7020Sstevel@tonic-gate if ((*ctx)->context != GSS_C_NO_CONTEXT) 703*6080Sjp161948 gss_delete_sec_context(&ms, &(*ctx)->context, GSS_C_NO_BUFFER); 704*6080Sjp161948 #if 0 705*6080Sjp161948 /* XXX */ 706*6080Sjp161948 if ((*ctx)->desired_mech != GSS_C_NULL_OID) 707*6080Sjp161948 ssh_gssapi_release_oid(&(*ctx)->desired_mech); 708*6080Sjp161948 #endif 7090Sstevel@tonic-gate if ((*ctx)->actual_mech != GSS_C_NULL_OID) 7100Sstevel@tonic-gate (void) ssh_gssapi_release_oid(&(*ctx)->actual_mech); 7110Sstevel@tonic-gate if ((*ctx)->desired_name != GSS_C_NO_NAME) 712*6080Sjp161948 gss_release_name(&ms, &(*ctx)->desired_name); 713*6080Sjp161948 #if 0 714*6080Sjp161948 if ((*ctx)->src_name != GSS_C_NO_NAME) 715*6080Sjp161948 gss_release_name(&ms, &(*ctx)->src_name); 716*6080Sjp161948 #endif 7170Sstevel@tonic-gate if ((*ctx)->dst_name != GSS_C_NO_NAME) 718*6080Sjp161948 gss_release_name(&ms, &(*ctx)->dst_name); 7190Sstevel@tonic-gate if ((*ctx)->creds != GSS_C_NO_CREDENTIAL) 720*6080Sjp161948 gss_release_cred(&ms, &(*ctx)->creds); 7210Sstevel@tonic-gate if ((*ctx)->deleg_creds != GSS_C_NO_CREDENTIAL) 722*6080Sjp161948 gss_release_cred(&ms, &(*ctx)->deleg_creds); 7230Sstevel@tonic-gate 7240Sstevel@tonic-gate xfree(*ctx); 725*6080Sjp161948 *ctx = NULL; 7260Sstevel@tonic-gate } 7270Sstevel@tonic-gate 7280Sstevel@tonic-gate /* Create a GSS hostbased service principal name for a given server hostname */ 7290Sstevel@tonic-gate int 7300Sstevel@tonic-gate ssh_gssapi_import_name(Gssctxt *ctx, const char *server_host) 7310Sstevel@tonic-gate { 7320Sstevel@tonic-gate gss_buffer_desc name_buf; 7330Sstevel@tonic-gate int ret; 7340Sstevel@tonic-gate 7350Sstevel@tonic-gate /* Build target principal */ 7360Sstevel@tonic-gate name_buf.length = strlen(SSH_GSS_HOSTBASED_SERVICE) + 737*6080Sjp161948 strlen(server_host) + 1; /* +1 for '@' */ 7380Sstevel@tonic-gate name_buf.value = xmalloc(name_buf.length + 1); /* +1 for NUL */ 7390Sstevel@tonic-gate ret = snprintf(name_buf.value, name_buf.length + 1, "%s@%s", 740*6080Sjp161948 SSH_GSS_HOSTBASED_SERVICE, server_host); 7410Sstevel@tonic-gate 742*6080Sjp161948 debug3("%s: snprintf() returned %d, expected %d", __func__, ret, 743*6080Sjp161948 name_buf.length + 1); 7440Sstevel@tonic-gate 7450Sstevel@tonic-gate ctx->major = gss_import_name(&ctx->minor, &name_buf, 746*6080Sjp161948 GSS_C_NT_HOSTBASED_SERVICE, &ctx->desired_name); 7470Sstevel@tonic-gate 7480Sstevel@tonic-gate if (GSS_ERROR(ctx->major)) { 7490Sstevel@tonic-gate ssh_gssapi_error(ctx, "calling GSS_Import_name()"); 750*6080Sjp161948 return (0); 7510Sstevel@tonic-gate } 7520Sstevel@tonic-gate 7530Sstevel@tonic-gate xfree(name_buf.value); 7540Sstevel@tonic-gate 755*6080Sjp161948 return (1); 7560Sstevel@tonic-gate } 7570Sstevel@tonic-gate 7580Sstevel@tonic-gate OM_uint32 759*6080Sjp161948 ssh_gssapi_get_mic(Gssctxt *ctx, gss_buffer_desc *buffer, gss_buffer_desc *hash) 760*6080Sjp161948 { 7610Sstevel@tonic-gate 762*6080Sjp161948 ctx->major = gss_get_mic(&ctx->minor, ctx->context, 763*6080Sjp161948 GSS_C_QOP_DEFAULT, buffer, hash); 7640Sstevel@tonic-gate if (GSS_ERROR(ctx->major)) 7650Sstevel@tonic-gate ssh_gssapi_error(ctx, "while getting MIC"); 766*6080Sjp161948 return (ctx->major); 7670Sstevel@tonic-gate } 7680Sstevel@tonic-gate 7690Sstevel@tonic-gate OM_uint32 770*6080Sjp161948 ssh_gssapi_verify_mic(Gssctxt *ctx, gss_buffer_desc *buffer, 771*6080Sjp161948 gss_buffer_desc *hash) 772*6080Sjp161948 { 7730Sstevel@tonic-gate gss_qop_t qop; 7740Sstevel@tonic-gate 775*6080Sjp161948 ctx->major = gss_verify_mic(&ctx->minor, ctx->context, buffer, 776*6080Sjp161948 hash, &qop); 7770Sstevel@tonic-gate if (GSS_ERROR(ctx->major)) 7780Sstevel@tonic-gate ssh_gssapi_error(ctx, "while verifying MIC"); 779*6080Sjp161948 return (ctx->major); 7800Sstevel@tonic-gate } 7810Sstevel@tonic-gate #endif /* GSSAPI */ 782