source: trunk/third/openssh/auth2-gss.c @ 18763

Revision 18763, 6.4 KB checked in by zacheiss, 22 years ago (diff)
Merge openssh 3.5p1.
Line 
1/*
2 * Copyright (c) 2001,2002 Simon Wilkinson. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25#include "includes.h"
26
27#ifdef GSSAPI
28#include "auth.h"
29#include "ssh2.h"
30#include "xmalloc.h"
31#include "log.h"
32#include "dispatch.h"
33#include "servconf.h"
34#include "compat.h"
35#include "packet.h"
36#include "monitor_wrap.h"
37
38#include "ssh-gss.h"
39
40extern ServerOptions options;
41
42static int
43userauth_external(Authctxt *authctxt)
44{
45        packet_check_eom();
46
47        return(PRIVSEP(ssh_gssapi_userok(authctxt)));
48}
49
50static void input_gssapi_token(int type, u_int32_t plen, void *ctxt);
51static void input_gssapi_exchange_complete(int type, u_int32_t plen, void *ctxt);
52
53/* We only support those mechanisms that we know about (ie ones that we know
54 * how to check local user kuserok and the like
55 */
56static int
57userauth_gssapi(Authctxt *authctxt)
58{
59        gss_OID_desc    oid= {0,NULL};
60        Gssctxt         *ctxt = NULL;
61        int             mechs;
62        gss_OID_set     supported;
63        int             present;
64        OM_uint32       ms;
65        u_int           len;
66       
67        if (!authctxt->valid || authctxt->user == NULL)
68                return 0;
69               
70        if (datafellows & SSH_OLD_GSSAPI) {
71                debug("Early drafts of GSSAPI userauth not supported");
72                return 0;
73        }
74       
75        mechs=packet_get_int();
76        if (mechs==0) {
77                debug("Mechanism negotiation is not supported");
78                return 0;
79        }
80
81        ssh_gssapi_supported_oids(&supported);
82        do {
83                if (oid.elements)
84                        xfree(oid.elements);
85                oid.elements = packet_get_string(&len);
86                oid.length = len;
87                gss_test_oid_set_member(&ms, &oid, supported, &present);
88                mechs--;
89        } while (mechs>0 && !present);
90       
91        if (!present) {
92                xfree(oid.elements);
93                return(0);
94        }
95               
96        if (GSS_ERROR(PRIVSEP(ssh_gssapi_server_ctx(&ctxt,&oid))))
97                return(0);
98       
99        authctxt->methoddata=(void *)ctxt;
100
101        /* Send SSH_MSG_USERAUTH_GSSAPI_RESPONSE */
102
103        packet_start(SSH2_MSG_USERAUTH_GSSAPI_RESPONSE);
104        packet_put_string(oid.elements,oid.length);
105        packet_send();
106        packet_write_wait();
107        xfree(oid.elements);
108
109        dispatch_set(SSH2_MSG_USERAUTH_GSSAPI_TOKEN,
110                     &input_gssapi_token);
111        authctxt->postponed = 1;
112       
113        return 0;
114}
115
116static void
117input_gssapi_token(int type, u_int32_t plen, void *ctxt)
118{
119        Authctxt *authctxt = ctxt;
120        Gssctxt *gssctxt;
121        gss_buffer_desc send_tok,recv_tok;
122        OM_uint32 maj_status, min_status;
123       
124        if (authctxt == NULL || (authctxt->methoddata == NULL && !use_privsep))
125                fatal("No authentication or GSSAPI context");
126               
127        gssctxt=authctxt->methoddata;
128        recv_tok.value=packet_get_string(&recv_tok.length);
129       
130        maj_status=PRIVSEP(ssh_gssapi_accept_ctx(gssctxt, &recv_tok,
131                                                 &send_tok, NULL));
132        packet_check_eom();
133       
134        if (GSS_ERROR(maj_status)) {
135                /* Failure <sniff> */
136                authctxt->postponed = 0;
137                dispatch_set(SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL);
138                userauth_finish(authctxt, 0, "gssapi");
139        }
140                       
141        if (send_tok.length != 0) {
142                /* Send a packet back to the client */
143                packet_start(SSH2_MSG_USERAUTH_GSSAPI_TOKEN);
144                packet_put_string(send_tok.value,send_tok.length);
145                packet_send();
146                packet_write_wait();
147                gss_release_buffer(&min_status, &send_tok);       
148        }
149       
150        if (maj_status == GSS_S_COMPLETE) {
151                dispatch_set(SSH2_MSG_USERAUTH_GSSAPI_TOKEN,NULL);
152                dispatch_set(SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE,
153                             &input_gssapi_exchange_complete);
154        }
155}
156
157/* This is called when the client thinks we've completed authentication.
158 * It should only be enabled in the dispatch handler by the function above,
159 * which only enables it once the GSSAPI exchange is complete.
160 */
161 
162static void
163input_gssapi_exchange_complete(int type, u_int32_t plen, void *ctxt)
164{
165        Authctxt *authctxt = ctxt;
166        Gssctxt *gssctxt;
167        int authenticated;
168       
169        if (authctxt == NULL || (authctxt->methoddata == NULL && !use_privsep))
170                fatal("No authentication or GSSAPI context");
171               
172        gssctxt=authctxt->methoddata;
173
174        /* We don't need to check the status, because the stored credentials
175         * which userok uses are only populated once the context init step
176         * has returned complete.
177         */
178
179        authenticated = PRIVSEP(ssh_gssapi_userok(authctxt));
180
181        authctxt->postponed = 0;
182        dispatch_set(SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL);
183        dispatch_set(SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE, NULL);
184        userauth_finish(authctxt, authenticated, "gssapi");
185}
186
187Authmethod method_external = {
188        "external-keyx",
189        userauth_external,
190        &options.gss_authentication
191};
192       
193Authmethod method_gssapi = {
194        "gssapi",
195        userauth_gssapi,
196        &options.gss_authentication
197};
198
199#endif /* GSSAPI */
Note: See TracBrowser for help on using the repository browser.