10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved. 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 50Sstevel@tonic-gate * modification, are permitted provided that the following conditions 60Sstevel@tonic-gate * are met: 70Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 80Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 90Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 100Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the 110Sstevel@tonic-gate * documentation and/or other materials provided with the distribution. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR 140Sstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 150Sstevel@tonic-gate * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 160Sstevel@tonic-gate * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 170Sstevel@tonic-gate * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 180Sstevel@tonic-gate * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 190Sstevel@tonic-gate * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 200Sstevel@tonic-gate * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 210Sstevel@tonic-gate * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 220Sstevel@tonic-gate * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 230Sstevel@tonic-gate */ 240Sstevel@tonic-gate /* 25*6080Sjp161948 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 260Sstevel@tonic-gate * Use is subject to license terms. 270Sstevel@tonic-gate */ 280Sstevel@tonic-gate 290Sstevel@tonic-gate #ifndef _SSH_GSS_H 30*6080Sjp161948 #define _SSH_GSS_H 310Sstevel@tonic-gate 320Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 330Sstevel@tonic-gate 340Sstevel@tonic-gate #ifdef GSSAPI 350Sstevel@tonic-gate 360Sstevel@tonic-gate #include "kex.h" 370Sstevel@tonic-gate #include "buffer.h" 380Sstevel@tonic-gate 390Sstevel@tonic-gate #ifdef SUNW_GSSAPI 400Sstevel@tonic-gate #include <gssapi/gssapi.h> 410Sstevel@tonic-gate #include <gssapi/gssapi_ext.h> 420Sstevel@tonic-gate #else 430Sstevel@tonic-gate #ifdef GSS_KRB5 440Sstevel@tonic-gate #ifndef HEIMDAL 450Sstevel@tonic-gate #include <gssapi_generic.h> 460Sstevel@tonic-gate 470Sstevel@tonic-gate /* MIT Kerberos doesn't seem to define GSS_NT_HOSTBASED_SERVICE */ 480Sstevel@tonic-gate #ifndef GSS_C_NT_HOSTBASED_SERVICE 49*6080Sjp161948 #define GSS_C_NT_HOSTBASED_SERVICE gss_nt_service_name 500Sstevel@tonic-gate #endif /* GSS_C_NT_... */ 510Sstevel@tonic-gate #endif /* !HEIMDAL */ 520Sstevel@tonic-gate #endif /* GSS_KRB5 */ 530Sstevel@tonic-gate #endif /* SUNW_GSSAPI */ 540Sstevel@tonic-gate 550Sstevel@tonic-gate /* draft-ietf-secsh-gsskeyex-03 */ 56*6080Sjp161948 #define SSH2_MSG_KEXGSS_INIT 30 57*6080Sjp161948 #define SSH2_MSG_KEXGSS_CONTINUE 31 58*6080Sjp161948 #define SSH2_MSG_KEXGSS_COMPLETE 32 59*6080Sjp161948 #define SSH2_MSG_KEXGSS_HOSTKEY 33 60*6080Sjp161948 #define SSH2_MSG_KEXGSS_ERROR 34 61*6080Sjp161948 #define SSH2_MSG_USERAUTH_GSSAPI_RESPONSE 60 62*6080Sjp161948 #define SSH2_MSG_USERAUTH_GSSAPI_TOKEN 61 63*6080Sjp161948 #define SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE 63 64*6080Sjp161948 #define SSH2_MSG_USERAUTH_GSSAPI_ERROR 64 65*6080Sjp161948 #define SSH2_MSG_USERAUTH_GSSAPI_ERRTOK 65 66*6080Sjp161948 #define SSH2_MSG_USERAUTH_GSSAPI_MIC 66 670Sstevel@tonic-gate 68*6080Sjp161948 #define KEX_GSS_SHA1 "gss-group1-sha1-" 69*6080Sjp161948 #define SSH_GSS_HOSTBASED_SERVICE "host" 700Sstevel@tonic-gate 710Sstevel@tonic-gate #ifndef HAVE_GSS_STORE_CRED 720Sstevel@tonic-gate typedef struct ssh_gssapi_cred_store ssh_gssapi_cred_store; /* server-only */ 730Sstevel@tonic-gate #endif /* !HAVE_GSS_STORE_CRED */ 740Sstevel@tonic-gate 750Sstevel@tonic-gate typedef struct { 760Sstevel@tonic-gate OM_uint32 major; 770Sstevel@tonic-gate OM_uint32 minor; 780Sstevel@tonic-gate int local; /* true on client, false on server */ 790Sstevel@tonic-gate int established; 800Sstevel@tonic-gate OM_uint32 flags; 810Sstevel@tonic-gate gss_ctx_id_t context; 820Sstevel@tonic-gate gss_OID desired_mech; /* client-side only */ 830Sstevel@tonic-gate gss_OID actual_mech; 840Sstevel@tonic-gate gss_name_t desired_name; /* targ on both */ 850Sstevel@tonic-gate gss_name_t src_name; 860Sstevel@tonic-gate gss_name_t dst_name; 870Sstevel@tonic-gate gss_cred_id_t creds; /* server-side only */ 880Sstevel@tonic-gate gss_cred_id_t deleg_creds; /* server-side only */ 890Sstevel@tonic-gate int default_creds; /* server-side only */ 900Sstevel@tonic-gate #ifndef HAVE_GSS_STORE_CRED 910Sstevel@tonic-gate ssh_gssapi_cred_store *cred_store; /* server-side only */ 920Sstevel@tonic-gate #endif /* !HAVE_GSS_STORE_CRED */ 930Sstevel@tonic-gate } Gssctxt; 940Sstevel@tonic-gate 950Sstevel@tonic-gate /* Functions to get supported mech lists */ 960Sstevel@tonic-gate void ssh_gssapi_server_mechs(gss_OID_set *mechs); 970Sstevel@tonic-gate void ssh_gssapi_client_mechs(const char *server_host, gss_OID_set *mechs); 980Sstevel@tonic-gate 990Sstevel@tonic-gate /* Functions to get fix KEX proposals (needed for rekey cases) */ 1000Sstevel@tonic-gate void ssh_gssapi_modify_kex(Kex *kex, gss_OID_set mechs, char **proposal); 1010Sstevel@tonic-gate void ssh_gssapi_server_kex_hook(Kex *kex, char **proposal); 1020Sstevel@tonic-gate void ssh_gssapi_client_kex_hook(Kex *kex, char **proposal); 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate /* Map an encoded mechanism keyex name to a mechanism OID */ 1050Sstevel@tonic-gate void ssh_gssapi_mech_oid_to_kexname(const gss_OID mech, char **kexname); 1060Sstevel@tonic-gate void ssh_gssapi_mech_oids_to_kexnames(const gss_OID_set mechs, 107*6080Sjp161948 char **kexname_list); 108*6080Sjp161948 /* dup oid? */ 109*6080Sjp161948 void ssh_gssapi_oid_of_kexname(const char *kexname, gss_OID *mech); 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate /* 1120Sstevel@tonic-gate * Unfortunately, the GSS-API is not generic enough for some things -- 1130Sstevel@tonic-gate * see gss-serv.c and ssh-gss.c 1140Sstevel@tonic-gate */ 1150Sstevel@tonic-gate int ssh_gssapi_is_spnego(gss_OID oid); 1160Sstevel@tonic-gate int ssh_gssapi_is_krb5(gss_OID oid); 1170Sstevel@tonic-gate int ssh_gssapi_is_gsi(gss_OID oid); 1180Sstevel@tonic-gate int ssh_gssapi_is_dh(gss_OID oid); 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate /* GSS_Init/Accept_sec_context() and GSS_Acquire_cred() wrappers */ 121*6080Sjp161948 /* client-only */ 122*6080Sjp161948 OM_uint32 ssh_gssapi_init_ctx(Gssctxt *ctx, const char *server_host, 123*6080Sjp161948 int deleg_creds, gss_buffer_t recv_tok, gss_buffer_t send_tok); 124*6080Sjp161948 /* server-only */ 125*6080Sjp161948 OM_uint32 ssh_gssapi_accept_ctx(Gssctxt *ctx, gss_buffer_t recv_tok, 126*6080Sjp161948 gss_buffer_t send_tok); 127*6080Sjp161948 /* server-only */ 128*6080Sjp161948 OM_uint32 ssh_gssapi_acquire_cred(Gssctxt *ctx); 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate /* MIC wrappers */ 1310Sstevel@tonic-gate OM_uint32 ssh_gssapi_get_mic(Gssctxt *ctx, gss_buffer_t buffer, 1320Sstevel@tonic-gate gss_buffer_t hash); 1330Sstevel@tonic-gate OM_uint32 ssh_gssapi_verify_mic(Gssctxt *ctx, gss_buffer_t buffer, 1340Sstevel@tonic-gate gss_buffer_t hash); 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate /* Gssctxt functions */ 1370Sstevel@tonic-gate void ssh_gssapi_build_ctx(Gssctxt **ctx, int client, gss_OID mech); 1380Sstevel@tonic-gate void ssh_gssapi_delete_ctx(Gssctxt **ctx); 1390Sstevel@tonic-gate int ssh_gssapi_check_mech_oid(Gssctxt *ctx, void *data, size_t len); 1400Sstevel@tonic-gate void ssh_gssapi_error(Gssctxt *ctx, const char *where); 1410Sstevel@tonic-gate char *ssh_gssapi_last_error(Gssctxt *ctxt, OM_uint32 *maj, OM_uint32 *min); 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate /* Server-side */ 1440Sstevel@tonic-gate int ssh_gssapi_userok(Gssctxt *ctx, char *name); 1450Sstevel@tonic-gate char *ssh_gssapi_localname(Gssctxt *ctx); 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate /* Server-side, if PAM and gss_store_cred() are available, ... */ 1480Sstevel@tonic-gate struct Authctxt; /* needed to avoid conflicts between auth.h, sshconnect2.c */ 1490Sstevel@tonic-gate void ssh_gssapi_storecreds(Gssctxt *ctx, struct Authctxt *authctxt); 1500Sstevel@tonic-gate 1510Sstevel@tonic-gate /* ... else, if other interfaces are available for GSS-API cred storing */ 152*6080Sjp161948 void ssh_gssapi_do_child(Gssctxt *ctx, char ***envp, uint_t *envsizep); 1530Sstevel@tonic-gate void ssh_gssapi_cleanup_creds(Gssctxt *ctx); 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate /* Misc */ 1560Sstevel@tonic-gate int ssh_gssapi_import_name(Gssctxt *ctx, const char *server_host); 1570Sstevel@tonic-gate const char *ssh_gssapi_oid_to_name(gss_OID oid); 1580Sstevel@tonic-gate char *ssh_gssapi_oid_to_str(gss_OID oid); 1590Sstevel@tonic-gate gss_OID ssh_gssapi_dup_oid(gss_OID oid); 1600Sstevel@tonic-gate gss_OID ssh_gssapi_make_oid(size_t length, void *elements); 161*6080Sjp161948 gss_OID ssh_gssapi_make_oid_ext(size_t length, void *elements, 162*6080Sjp161948 int der_wrapped); 1630Sstevel@tonic-gate void *ssh_gssapi_der_wrap(size_t, size_t *length); 1640Sstevel@tonic-gate size_t ssh_gssapi_der_wrap_size(size_t, size_t *length); 1650Sstevel@tonic-gate void ssh_gssapi_release_oid(gss_OID *oid); 1660Sstevel@tonic-gate #endif /* GSSAPI */ 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate #endif /* _SSH_GSS_H */ 169