17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved. 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 57c478bd9Sstevel@tonic-gate * modification, are permitted provided that the following conditions 67c478bd9Sstevel@tonic-gate * are met: 77c478bd9Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 87c478bd9Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 97c478bd9Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 107c478bd9Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the 117c478bd9Sstevel@tonic-gate * documentation and/or other materials provided with the distribution. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR 147c478bd9Sstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 157c478bd9Sstevel@tonic-gate * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 167c478bd9Sstevel@tonic-gate * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 177c478bd9Sstevel@tonic-gate * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 187c478bd9Sstevel@tonic-gate * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 197c478bd9Sstevel@tonic-gate * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 207c478bd9Sstevel@tonic-gate * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 217c478bd9Sstevel@tonic-gate * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 227c478bd9Sstevel@tonic-gate * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 237c478bd9Sstevel@tonic-gate */ 247c478bd9Sstevel@tonic-gate /* 25*c15e4e4bSjp161948 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 267c478bd9Sstevel@tonic-gate * Use is subject to license terms. 277c478bd9Sstevel@tonic-gate */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #ifndef _SSH_GSS_H 307c478bd9Sstevel@tonic-gate #define _SSH_GSS_H 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #ifdef GSSAPI 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #include "kex.h" 377c478bd9Sstevel@tonic-gate #include "buffer.h" 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #ifdef SUNW_GSSAPI 407c478bd9Sstevel@tonic-gate #include <gssapi/gssapi.h> 417c478bd9Sstevel@tonic-gate #include <gssapi/gssapi_ext.h> 427c478bd9Sstevel@tonic-gate #else 437c478bd9Sstevel@tonic-gate #ifdef GSS_KRB5 447c478bd9Sstevel@tonic-gate #ifndef HEIMDAL 457c478bd9Sstevel@tonic-gate #include <gssapi_generic.h> 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate /* MIT Kerberos doesn't seem to define GSS_NT_HOSTBASED_SERVICE */ 487c478bd9Sstevel@tonic-gate #ifndef GSS_C_NT_HOSTBASED_SERVICE 497c478bd9Sstevel@tonic-gate #define GSS_C_NT_HOSTBASED_SERVICE gss_nt_service_name 507c478bd9Sstevel@tonic-gate #endif /* GSS_C_NT_... */ 517c478bd9Sstevel@tonic-gate #endif /* !HEIMDAL */ 527c478bd9Sstevel@tonic-gate #endif /* GSS_KRB5 */ 537c478bd9Sstevel@tonic-gate #endif /* SUNW_GSSAPI */ 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate /* draft-ietf-secsh-gsskeyex-03 */ 567c478bd9Sstevel@tonic-gate #define SSH2_MSG_KEXGSS_INIT 30 577c478bd9Sstevel@tonic-gate #define SSH2_MSG_KEXGSS_CONTINUE 31 587c478bd9Sstevel@tonic-gate #define SSH2_MSG_KEXGSS_COMPLETE 32 597c478bd9Sstevel@tonic-gate #define SSH2_MSG_KEXGSS_HOSTKEY 33 607c478bd9Sstevel@tonic-gate #define SSH2_MSG_KEXGSS_ERROR 34 617c478bd9Sstevel@tonic-gate #define SSH2_MSG_USERAUTH_GSSAPI_RESPONSE 60 627c478bd9Sstevel@tonic-gate #define SSH2_MSG_USERAUTH_GSSAPI_TOKEN 61 637c478bd9Sstevel@tonic-gate #define SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE 63 647c478bd9Sstevel@tonic-gate #define SSH2_MSG_USERAUTH_GSSAPI_ERROR 64 657c478bd9Sstevel@tonic-gate #define SSH2_MSG_USERAUTH_GSSAPI_ERRTOK 65 667c478bd9Sstevel@tonic-gate #define SSH2_MSG_USERAUTH_GSSAPI_MIC 66 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate #define KEX_GSS_SHA1 "gss-group1-sha1-" 697c478bd9Sstevel@tonic-gate #define SSH_GSS_HOSTBASED_SERVICE "host" 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate #ifndef HAVE_GSS_STORE_CRED 727c478bd9Sstevel@tonic-gate typedef struct ssh_gssapi_cred_store ssh_gssapi_cred_store; /* server-only */ 737c478bd9Sstevel@tonic-gate #endif /* !HAVE_GSS_STORE_CRED */ 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate typedef struct { 767c478bd9Sstevel@tonic-gate OM_uint32 major; 777c478bd9Sstevel@tonic-gate OM_uint32 minor; 787c478bd9Sstevel@tonic-gate int local; /* true on client, false on server */ 797c478bd9Sstevel@tonic-gate int established; 807c478bd9Sstevel@tonic-gate OM_uint32 flags; 817c478bd9Sstevel@tonic-gate gss_ctx_id_t context; 827c478bd9Sstevel@tonic-gate gss_OID desired_mech; /* client-side only */ 837c478bd9Sstevel@tonic-gate gss_OID actual_mech; 847c478bd9Sstevel@tonic-gate gss_name_t desired_name; /* targ on both */ 857c478bd9Sstevel@tonic-gate gss_name_t src_name; 867c478bd9Sstevel@tonic-gate gss_name_t dst_name; 877c478bd9Sstevel@tonic-gate gss_cred_id_t creds; /* server-side only */ 887c478bd9Sstevel@tonic-gate gss_cred_id_t deleg_creds; /* server-side only */ 897c478bd9Sstevel@tonic-gate int default_creds; /* server-side only */ 907c478bd9Sstevel@tonic-gate #ifndef HAVE_GSS_STORE_CRED 917c478bd9Sstevel@tonic-gate ssh_gssapi_cred_store *cred_store; /* server-side only */ 927c478bd9Sstevel@tonic-gate #endif /* !HAVE_GSS_STORE_CRED */ 937c478bd9Sstevel@tonic-gate } Gssctxt; 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate /* Functions to get supported mech lists */ 967c478bd9Sstevel@tonic-gate void ssh_gssapi_server_mechs(gss_OID_set *mechs); 977c478bd9Sstevel@tonic-gate void ssh_gssapi_client_mechs(const char *server_host, gss_OID_set *mechs); 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate /* Functions to get fix KEX proposals (needed for rekey cases) */ 1007c478bd9Sstevel@tonic-gate void ssh_gssapi_modify_kex(Kex *kex, gss_OID_set mechs, char **proposal); 1017c478bd9Sstevel@tonic-gate void ssh_gssapi_server_kex_hook(Kex *kex, char **proposal); 1027c478bd9Sstevel@tonic-gate void ssh_gssapi_client_kex_hook(Kex *kex, char **proposal); 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate /* Map an encoded mechanism keyex name to a mechanism OID */ 1057c478bd9Sstevel@tonic-gate void ssh_gssapi_mech_oid_to_kexname(const gss_OID mech, char **kexname); 1067c478bd9Sstevel@tonic-gate void ssh_gssapi_mech_oids_to_kexnames(const gss_OID_set mechs, 1077c478bd9Sstevel@tonic-gate char **kexname_list); 108*c15e4e4bSjp161948 /* dup oid? */ 109*c15e4e4bSjp161948 void ssh_gssapi_oid_of_kexname(const char *kexname, gss_OID *mech); 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate /* 1127c478bd9Sstevel@tonic-gate * Unfortunately, the GSS-API is not generic enough for some things -- 1137c478bd9Sstevel@tonic-gate * see gss-serv.c and ssh-gss.c 1147c478bd9Sstevel@tonic-gate */ 1157c478bd9Sstevel@tonic-gate int ssh_gssapi_is_spnego(gss_OID oid); 1167c478bd9Sstevel@tonic-gate int ssh_gssapi_is_krb5(gss_OID oid); 1177c478bd9Sstevel@tonic-gate int ssh_gssapi_is_gsi(gss_OID oid); 1187c478bd9Sstevel@tonic-gate int ssh_gssapi_is_dh(gss_OID oid); 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate /* GSS_Init/Accept_sec_context() and GSS_Acquire_cred() wrappers */ 121*c15e4e4bSjp161948 /* client-only */ 122*c15e4e4bSjp161948 OM_uint32 ssh_gssapi_init_ctx(Gssctxt *ctx, const char *server_host, 123*c15e4e4bSjp161948 int deleg_creds, gss_buffer_t recv_tok, gss_buffer_t send_tok); 124*c15e4e4bSjp161948 /* server-only */ 125*c15e4e4bSjp161948 OM_uint32 ssh_gssapi_accept_ctx(Gssctxt *ctx, gss_buffer_t recv_tok, 126*c15e4e4bSjp161948 gss_buffer_t send_tok); 127*c15e4e4bSjp161948 /* server-only */ 128*c15e4e4bSjp161948 OM_uint32 ssh_gssapi_acquire_cred(Gssctxt *ctx); 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate /* MIC wrappers */ 1317c478bd9Sstevel@tonic-gate OM_uint32 ssh_gssapi_get_mic(Gssctxt *ctx, gss_buffer_t buffer, 1327c478bd9Sstevel@tonic-gate gss_buffer_t hash); 1337c478bd9Sstevel@tonic-gate OM_uint32 ssh_gssapi_verify_mic(Gssctxt *ctx, gss_buffer_t buffer, 1347c478bd9Sstevel@tonic-gate gss_buffer_t hash); 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate /* Gssctxt functions */ 1377c478bd9Sstevel@tonic-gate void ssh_gssapi_build_ctx(Gssctxt **ctx, int client, gss_OID mech); 1387c478bd9Sstevel@tonic-gate void ssh_gssapi_delete_ctx(Gssctxt **ctx); 1397c478bd9Sstevel@tonic-gate int ssh_gssapi_check_mech_oid(Gssctxt *ctx, void *data, size_t len); 1407c478bd9Sstevel@tonic-gate void ssh_gssapi_error(Gssctxt *ctx, const char *where); 1417c478bd9Sstevel@tonic-gate char *ssh_gssapi_last_error(Gssctxt *ctxt, OM_uint32 *maj, OM_uint32 *min); 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate /* Server-side */ 1447c478bd9Sstevel@tonic-gate int ssh_gssapi_userok(Gssctxt *ctx, char *name); 1457c478bd9Sstevel@tonic-gate char *ssh_gssapi_localname(Gssctxt *ctx); 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate /* Server-side, if PAM and gss_store_cred() are available, ... */ 1487c478bd9Sstevel@tonic-gate struct Authctxt; /* needed to avoid conflicts between auth.h, sshconnect2.c */ 1497c478bd9Sstevel@tonic-gate void ssh_gssapi_storecreds(Gssctxt *ctx, struct Authctxt *authctxt); 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate /* ... else, if other interfaces are available for GSS-API cred storing */ 152*c15e4e4bSjp161948 void ssh_gssapi_do_child(Gssctxt *ctx, char ***envp, uint_t *envsizep); 1537c478bd9Sstevel@tonic-gate void ssh_gssapi_cleanup_creds(Gssctxt *ctx); 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate /* Misc */ 1567c478bd9Sstevel@tonic-gate int ssh_gssapi_import_name(Gssctxt *ctx, const char *server_host); 1577c478bd9Sstevel@tonic-gate const char *ssh_gssapi_oid_to_name(gss_OID oid); 1587c478bd9Sstevel@tonic-gate char *ssh_gssapi_oid_to_str(gss_OID oid); 1597c478bd9Sstevel@tonic-gate gss_OID ssh_gssapi_dup_oid(gss_OID oid); 1607c478bd9Sstevel@tonic-gate gss_OID ssh_gssapi_make_oid(size_t length, void *elements); 161*c15e4e4bSjp161948 gss_OID ssh_gssapi_make_oid_ext(size_t length, void *elements, 1627c478bd9Sstevel@tonic-gate int der_wrapped); 1637c478bd9Sstevel@tonic-gate void *ssh_gssapi_der_wrap(size_t, size_t *length); 1647c478bd9Sstevel@tonic-gate size_t ssh_gssapi_der_wrap_size(size_t, size_t *length); 1657c478bd9Sstevel@tonic-gate void ssh_gssapi_release_oid(gss_OID *oid); 1667c478bd9Sstevel@tonic-gate #endif /* GSSAPI */ 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate #endif /* _SSH_GSS_H */ 169