1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved. 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 5*0Sstevel@tonic-gate * modification, are permitted provided that the following conditions 6*0Sstevel@tonic-gate * are met: 7*0Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 8*0Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 9*0Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 10*0Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the 11*0Sstevel@tonic-gate * documentation and/or other materials provided with the distribution. 12*0Sstevel@tonic-gate * 13*0Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR 14*0Sstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15*0Sstevel@tonic-gate * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16*0Sstevel@tonic-gate * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17*0Sstevel@tonic-gate * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18*0Sstevel@tonic-gate * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19*0Sstevel@tonic-gate * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20*0Sstevel@tonic-gate * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21*0Sstevel@tonic-gate * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22*0Sstevel@tonic-gate * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23*0Sstevel@tonic-gate */ 24*0Sstevel@tonic-gate /* 25*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 26*0Sstevel@tonic-gate * Use is subject to license terms. 27*0Sstevel@tonic-gate */ 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #ifndef _SSH_GSS_H 30*0Sstevel@tonic-gate #define _SSH_GSS_H 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate #ifdef GSSAPI 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate #include "kex.h" 37*0Sstevel@tonic-gate #include "buffer.h" 38*0Sstevel@tonic-gate 39*0Sstevel@tonic-gate #ifdef SUNW_GSSAPI 40*0Sstevel@tonic-gate #include <gssapi/gssapi.h> 41*0Sstevel@tonic-gate #include <gssapi/gssapi_ext.h> 42*0Sstevel@tonic-gate #else 43*0Sstevel@tonic-gate #ifdef GSS_KRB5 44*0Sstevel@tonic-gate #ifndef HEIMDAL 45*0Sstevel@tonic-gate #include <gssapi_generic.h> 46*0Sstevel@tonic-gate 47*0Sstevel@tonic-gate /* MIT Kerberos doesn't seem to define GSS_NT_HOSTBASED_SERVICE */ 48*0Sstevel@tonic-gate #ifndef GSS_C_NT_HOSTBASED_SERVICE 49*0Sstevel@tonic-gate #define GSS_C_NT_HOSTBASED_SERVICE gss_nt_service_name 50*0Sstevel@tonic-gate #endif /* GSS_C_NT_... */ 51*0Sstevel@tonic-gate #endif /* !HEIMDAL */ 52*0Sstevel@tonic-gate #endif /* GSS_KRB5 */ 53*0Sstevel@tonic-gate #endif /* SUNW_GSSAPI */ 54*0Sstevel@tonic-gate 55*0Sstevel@tonic-gate /* draft-ietf-secsh-gsskeyex-03 */ 56*0Sstevel@tonic-gate #define SSH2_MSG_KEXGSS_INIT 30 57*0Sstevel@tonic-gate #define SSH2_MSG_KEXGSS_CONTINUE 31 58*0Sstevel@tonic-gate #define SSH2_MSG_KEXGSS_COMPLETE 32 59*0Sstevel@tonic-gate #define SSH2_MSG_KEXGSS_HOSTKEY 33 60*0Sstevel@tonic-gate #define SSH2_MSG_KEXGSS_ERROR 34 61*0Sstevel@tonic-gate #define SSH2_MSG_USERAUTH_GSSAPI_RESPONSE 60 62*0Sstevel@tonic-gate #define SSH2_MSG_USERAUTH_GSSAPI_TOKEN 61 63*0Sstevel@tonic-gate #define SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE 63 64*0Sstevel@tonic-gate #define SSH2_MSG_USERAUTH_GSSAPI_ERROR 64 65*0Sstevel@tonic-gate #define SSH2_MSG_USERAUTH_GSSAPI_ERRTOK 65 66*0Sstevel@tonic-gate #define SSH2_MSG_USERAUTH_GSSAPI_MIC 66 67*0Sstevel@tonic-gate 68*0Sstevel@tonic-gate #define KEX_GSS_SHA1 "gss-group1-sha1-" 69*0Sstevel@tonic-gate #define SSH_GSS_HOSTBASED_SERVICE "host" 70*0Sstevel@tonic-gate 71*0Sstevel@tonic-gate #ifndef HAVE_GSS_STORE_CRED 72*0Sstevel@tonic-gate typedef struct ssh_gssapi_cred_store ssh_gssapi_cred_store; /* server-only */ 73*0Sstevel@tonic-gate #endif /* !HAVE_GSS_STORE_CRED */ 74*0Sstevel@tonic-gate 75*0Sstevel@tonic-gate typedef struct { 76*0Sstevel@tonic-gate OM_uint32 major; 77*0Sstevel@tonic-gate OM_uint32 minor; 78*0Sstevel@tonic-gate int local; /* true on client, false on server */ 79*0Sstevel@tonic-gate int established; 80*0Sstevel@tonic-gate OM_uint32 flags; 81*0Sstevel@tonic-gate gss_ctx_id_t context; 82*0Sstevel@tonic-gate gss_OID desired_mech; /* client-side only */ 83*0Sstevel@tonic-gate gss_OID actual_mech; 84*0Sstevel@tonic-gate gss_name_t desired_name; /* targ on both */ 85*0Sstevel@tonic-gate gss_name_t src_name; 86*0Sstevel@tonic-gate gss_name_t dst_name; 87*0Sstevel@tonic-gate gss_cred_id_t creds; /* server-side only */ 88*0Sstevel@tonic-gate gss_cred_id_t deleg_creds; /* server-side only */ 89*0Sstevel@tonic-gate int default_creds; /* server-side only */ 90*0Sstevel@tonic-gate #ifndef HAVE_GSS_STORE_CRED 91*0Sstevel@tonic-gate ssh_gssapi_cred_store *cred_store; /* server-side only */ 92*0Sstevel@tonic-gate #endif /* !HAVE_GSS_STORE_CRED */ 93*0Sstevel@tonic-gate } Gssctxt; 94*0Sstevel@tonic-gate 95*0Sstevel@tonic-gate /* Functions to get supported mech lists */ 96*0Sstevel@tonic-gate void ssh_gssapi_server_mechs(gss_OID_set *mechs); 97*0Sstevel@tonic-gate void ssh_gssapi_client_mechs(const char *server_host, gss_OID_set *mechs); 98*0Sstevel@tonic-gate 99*0Sstevel@tonic-gate /* Functions to get fix KEX proposals (needed for rekey cases) */ 100*0Sstevel@tonic-gate void ssh_gssapi_modify_kex(Kex *kex, gss_OID_set mechs, char **proposal); 101*0Sstevel@tonic-gate void ssh_gssapi_server_kex_hook(Kex *kex, char **proposal); 102*0Sstevel@tonic-gate void ssh_gssapi_client_kex_hook(Kex *kex, char **proposal); 103*0Sstevel@tonic-gate 104*0Sstevel@tonic-gate /* Map an encoded mechanism keyex name to a mechanism OID */ 105*0Sstevel@tonic-gate void ssh_gssapi_mech_oid_to_kexname(const gss_OID mech, char **kexname); 106*0Sstevel@tonic-gate void ssh_gssapi_mech_oids_to_kexnames(const gss_OID_set mechs, 107*0Sstevel@tonic-gate char **kexname_list); 108*0Sstevel@tonic-gate void ssh_gssapi_oid_of_kexname(const char *kexname, gss_OID *mech); /* dup oid? */ 109*0Sstevel@tonic-gate 110*0Sstevel@tonic-gate /* 111*0Sstevel@tonic-gate * Unfortunately, the GSS-API is not generic enough for some things -- 112*0Sstevel@tonic-gate * see gss-serv.c and ssh-gss.c 113*0Sstevel@tonic-gate */ 114*0Sstevel@tonic-gate int ssh_gssapi_is_spnego(gss_OID oid); 115*0Sstevel@tonic-gate int ssh_gssapi_is_krb5(gss_OID oid); 116*0Sstevel@tonic-gate int ssh_gssapi_is_gsi(gss_OID oid); 117*0Sstevel@tonic-gate int ssh_gssapi_is_dh(gss_OID oid); 118*0Sstevel@tonic-gate 119*0Sstevel@tonic-gate /* GSS_Init/Accept_sec_context() and GSS_Acquire_cred() wrappers */ 120*0Sstevel@tonic-gate OM_uint32 ssh_gssapi_init_ctx(Gssctxt *ctx, 121*0Sstevel@tonic-gate const char *server_host, 122*0Sstevel@tonic-gate int deleg_creds, 123*0Sstevel@tonic-gate gss_buffer_t recv_tok, 124*0Sstevel@tonic-gate gss_buffer_t send_tok); /* client-only */ 125*0Sstevel@tonic-gate OM_uint32 ssh_gssapi_accept_ctx(Gssctxt *ctx, 126*0Sstevel@tonic-gate gss_buffer_t recv_tok, 127*0Sstevel@tonic-gate gss_buffer_t send_tok); /* server-only */ 128*0Sstevel@tonic-gate OM_uint32 ssh_gssapi_acquire_cred(Gssctxt *ctx); /* server-only */ 129*0Sstevel@tonic-gate 130*0Sstevel@tonic-gate /* MIC wrappers */ 131*0Sstevel@tonic-gate OM_uint32 ssh_gssapi_get_mic(Gssctxt *ctx, gss_buffer_t buffer, 132*0Sstevel@tonic-gate gss_buffer_t hash); 133*0Sstevel@tonic-gate OM_uint32 ssh_gssapi_verify_mic(Gssctxt *ctx, gss_buffer_t buffer, 134*0Sstevel@tonic-gate gss_buffer_t hash); 135*0Sstevel@tonic-gate 136*0Sstevel@tonic-gate /* Gssctxt functions */ 137*0Sstevel@tonic-gate void ssh_gssapi_build_ctx(Gssctxt **ctx, int client, gss_OID mech); 138*0Sstevel@tonic-gate void ssh_gssapi_delete_ctx(Gssctxt **ctx); 139*0Sstevel@tonic-gate int ssh_gssapi_check_mech_oid(Gssctxt *ctx, void *data, size_t len); 140*0Sstevel@tonic-gate void ssh_gssapi_error(Gssctxt *ctx, const char *where); 141*0Sstevel@tonic-gate char *ssh_gssapi_last_error(Gssctxt *ctxt, OM_uint32 *maj, OM_uint32 *min); 142*0Sstevel@tonic-gate 143*0Sstevel@tonic-gate /* Server-side */ 144*0Sstevel@tonic-gate int ssh_gssapi_userok(Gssctxt *ctx, char *name); 145*0Sstevel@tonic-gate char *ssh_gssapi_localname(Gssctxt *ctx); 146*0Sstevel@tonic-gate 147*0Sstevel@tonic-gate /* Server-side, if PAM and gss_store_cred() are available, ... */ 148*0Sstevel@tonic-gate struct Authctxt; /* needed to avoid conflicts between auth.h, sshconnect2.c */ 149*0Sstevel@tonic-gate void ssh_gssapi_storecreds(Gssctxt *ctx, struct Authctxt *authctxt); 150*0Sstevel@tonic-gate 151*0Sstevel@tonic-gate /* ... else, if other interfaces are available for GSS-API cred storing */ 152*0Sstevel@tonic-gate void ssh_gssapi_do_child(Gssctxt *ctx, char ***envp, u_int *envsizep); 153*0Sstevel@tonic-gate void ssh_gssapi_cleanup_creds(Gssctxt *ctx); 154*0Sstevel@tonic-gate 155*0Sstevel@tonic-gate /* Misc */ 156*0Sstevel@tonic-gate int ssh_gssapi_import_name(Gssctxt *ctx, const char *server_host); 157*0Sstevel@tonic-gate const char *ssh_gssapi_oid_to_name(gss_OID oid); 158*0Sstevel@tonic-gate char *ssh_gssapi_oid_to_str(gss_OID oid); 159*0Sstevel@tonic-gate gss_OID ssh_gssapi_dup_oid(gss_OID oid); 160*0Sstevel@tonic-gate gss_OID ssh_gssapi_make_oid(size_t length, void *elements); 161*0Sstevel@tonic-gate gss_OID ssh_gssapi_make_oid_ext(size_t length, 162*0Sstevel@tonic-gate void *elements, 163*0Sstevel@tonic-gate int der_wrapped); 164*0Sstevel@tonic-gate void *ssh_gssapi_der_wrap(size_t, size_t *length); 165*0Sstevel@tonic-gate size_t ssh_gssapi_der_wrap_size(size_t, size_t *length); 166*0Sstevel@tonic-gate void ssh_gssapi_release_oid(gss_OID *oid); 167*0Sstevel@tonic-gate #endif /* GSSAPI */ 168*0Sstevel@tonic-gate 169*0Sstevel@tonic-gate #endif /* _SSH_GSS_H */ 170