djm@openbsd.org | 74287f5 | 2018-07-31 03:10:27 +0000 | [diff] [blame] | 1 | /* $OpenBSD: auth2-gss.c,v 1.29 2018/07/31 03:10:27 djm Exp $ */ |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AS IS'' AND ANY EXPRESS OR |
| 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | */ |
| 26 | |
| 27 | #include "includes.h" |
| 28 | |
Darren Tucker | 8c6feda | 2006-08-05 15:24:59 +1000 | [diff] [blame] | 29 | #ifdef GSSAPI |
| 30 | |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 31 | #include <sys/types.h> |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 32 | |
Damien Miller | ded319c | 2006-09-01 15:38:36 +1000 | [diff] [blame] | 33 | #include <stdarg.h> |
| 34 | |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 35 | #include "xmalloc.h" |
markus@openbsd.org | b8d9214 | 2018-07-09 21:37:55 +0000 | [diff] [blame] | 36 | #include "sshkey.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 37 | #include "hostfile.h" |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 38 | #include "auth.h" |
| 39 | #include "ssh2.h" |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 40 | #include "log.h" |
| 41 | #include "dispatch.h" |
markus@openbsd.org | b8d9214 | 2018-07-09 21:37:55 +0000 | [diff] [blame] | 42 | #include "sshbuf.h" |
| 43 | #include "ssherr.h" |
Darren Tucker | 450bc11 | 2014-07-19 06:23:18 +1000 | [diff] [blame] | 44 | #include "misc.h" |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 45 | #include "servconf.h" |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 46 | #include "packet.h" |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 47 | #include "ssh-gss.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 48 | #include "monitor_wrap.h" |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 49 | |
| 50 | extern ServerOptions options; |
| 51 | |
markus@openbsd.org | 2ae666a | 2017-05-30 14:23:52 +0000 | [diff] [blame] | 52 | static int input_gssapi_token(int type, u_int32_t plen, struct ssh *ssh); |
| 53 | static int input_gssapi_mic(int type, u_int32_t plen, struct ssh *ssh); |
| 54 | static int input_gssapi_exchange_complete(int type, u_int32_t plen, struct ssh *ssh); |
| 55 | static int input_gssapi_errtok(int, u_int32_t, struct ssh *); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 56 | |
| 57 | /* |
| 58 | * We only support those mechanisms that we know about (ie ones that we know |
Damien Miller | 6fd6def | 2005-11-05 15:07:05 +1100 | [diff] [blame] | 59 | * how to check local user kuserok and the like) |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 60 | */ |
| 61 | static int |
markus@openbsd.org | eb272ea | 2017-05-30 14:29:59 +0000 | [diff] [blame] | 62 | userauth_gssapi(struct ssh *ssh) |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 63 | { |
markus@openbsd.org | eb272ea | 2017-05-30 14:29:59 +0000 | [diff] [blame] | 64 | Authctxt *authctxt = ssh->authctxt; |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 65 | gss_OID_desc goid = {0, NULL}; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 66 | Gssctxt *ctxt = NULL; |
markus@openbsd.org | b8d9214 | 2018-07-09 21:37:55 +0000 | [diff] [blame] | 67 | int r, present; |
| 68 | u_int mechs; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 69 | OM_uint32 ms; |
markus@openbsd.org | b8d9214 | 2018-07-09 21:37:55 +0000 | [diff] [blame] | 70 | size_t len; |
Damien Miller | eccb9de | 2005-06-17 12:59:34 +1000 | [diff] [blame] | 71 | u_char *doid = NULL; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 72 | |
markus@openbsd.org | b8d9214 | 2018-07-09 21:37:55 +0000 | [diff] [blame] | 73 | if ((r = sshpkt_get_u32(ssh, &mechs)) != 0) |
| 74 | fatal("%s: %s", __func__, ssh_err(r)); |
| 75 | |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 76 | if (mechs == 0) { |
| 77 | debug("Mechanism negotiation is not supported"); |
| 78 | return (0); |
| 79 | } |
| 80 | |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 81 | do { |
| 82 | mechs--; |
| 83 | |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 84 | free(doid); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 85 | |
Darren Tucker | 655a5e0 | 2003-11-03 20:09:03 +1100 | [diff] [blame] | 86 | present = 0; |
markus@openbsd.org | b8d9214 | 2018-07-09 21:37:55 +0000 | [diff] [blame] | 87 | if ((r = sshpkt_get_string(ssh, &doid, &len)) != 0) |
| 88 | fatal("%s: %s", __func__, ssh_err(r)); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 89 | |
Damien Miller | 0dc1bef | 2005-07-17 17:22:45 +1000 | [diff] [blame] | 90 | if (len > 2 && doid[0] == SSH_GSS_OIDTYPE && |
| 91 | doid[1] == len - 2) { |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 92 | goid.elements = doid + 2; |
| 93 | goid.length = len - 2; |
Damien Miller | e6a74ae | 2014-02-27 10:17:49 +1100 | [diff] [blame] | 94 | ssh_gssapi_test_oid_supported(&ms, &goid, &present); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 95 | } else { |
Darren Tucker | 655a5e0 | 2003-11-03 20:09:03 +1100 | [diff] [blame] | 96 | logit("Badly formed OID received"); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 97 | } |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 98 | } while (mechs > 0 && !present); |
| 99 | |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 100 | if (!present) { |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 101 | free(doid); |
Damien Miller | 3fcdfd5 | 2011-05-05 14:04:11 +1000 | [diff] [blame] | 102 | authctxt->server_caused_failure = 1; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 103 | return (0); |
| 104 | } |
| 105 | |
djm@openbsd.org | 74287f5 | 2018-07-31 03:10:27 +0000 | [diff] [blame] | 106 | if (!authctxt->valid || authctxt->user == NULL) { |
| 107 | debug2("%s: disabled because of invalid user", __func__); |
| 108 | free(doid); |
| 109 | return (0); |
| 110 | } |
| 111 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 112 | if (GSS_ERROR(PRIVSEP(ssh_gssapi_server_ctx(&ctxt, &goid)))) { |
Damien Miller | f23c096 | 2006-03-26 00:04:53 +1100 | [diff] [blame] | 113 | if (ctxt != NULL) |
| 114 | ssh_gssapi_delete_ctx(&ctxt); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 115 | free(doid); |
Damien Miller | 3fcdfd5 | 2011-05-05 14:04:11 +1000 | [diff] [blame] | 116 | authctxt->server_caused_failure = 1; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 117 | return (0); |
Damien Miller | 982d326 | 2003-09-02 22:59:01 +1000 | [diff] [blame] | 118 | } |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 119 | |
Damien Miller | 6fd6def | 2005-11-05 15:07:05 +1100 | [diff] [blame] | 120 | authctxt->methoddata = (void *)ctxt; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 121 | |
Darren Tucker | 655a5e0 | 2003-11-03 20:09:03 +1100 | [diff] [blame] | 122 | /* Return the OID that we received */ |
markus@openbsd.org | b8d9214 | 2018-07-09 21:37:55 +0000 | [diff] [blame] | 123 | if ((r = sshpkt_start(ssh, SSH2_MSG_USERAUTH_GSSAPI_RESPONSE)) != 0 || |
| 124 | (r = sshpkt_put_string(ssh, doid, len)) != 0 || |
| 125 | (r = sshpkt_send(ssh)) != 0) |
| 126 | fatal("%s: %s", __func__, ssh_err(r)); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 127 | |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 128 | free(doid); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 129 | |
markus@openbsd.org | eb272ea | 2017-05-30 14:29:59 +0000 | [diff] [blame] | 130 | ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_TOKEN, &input_gssapi_token); |
| 131 | ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_ERRTOK, &input_gssapi_errtok); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 132 | authctxt->postponed = 1; |
| 133 | |
| 134 | return (0); |
| 135 | } |
| 136 | |
markus@openbsd.org | 3fdc88a | 2015-01-19 20:07:45 +0000 | [diff] [blame] | 137 | static int |
markus@openbsd.org | 2ae666a | 2017-05-30 14:23:52 +0000 | [diff] [blame] | 138 | input_gssapi_token(int type, u_int32_t plen, struct ssh *ssh) |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 139 | { |
markus@openbsd.org | 5f4082d | 2017-05-30 14:18:15 +0000 | [diff] [blame] | 140 | Authctxt *authctxt = ssh->authctxt; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 141 | Gssctxt *gssctxt; |
| 142 | gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER; |
| 143 | gss_buffer_desc recv_tok; |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 144 | OM_uint32 maj_status, min_status, flags; |
markus@openbsd.org | b8d9214 | 2018-07-09 21:37:55 +0000 | [diff] [blame] | 145 | u_char *p; |
| 146 | size_t len; |
| 147 | int r; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 148 | |
| 149 | if (authctxt == NULL || (authctxt->methoddata == NULL && !use_privsep)) |
| 150 | fatal("No authentication or GSSAPI context"); |
| 151 | |
| 152 | gssctxt = authctxt->methoddata; |
markus@openbsd.org | b8d9214 | 2018-07-09 21:37:55 +0000 | [diff] [blame] | 153 | if ((r = sshpkt_get_string(ssh, &p, &len)) != 0 || |
| 154 | (r = sshpkt_get_end(ssh)) != 0) |
| 155 | fatal("%s: %s", __func__, ssh_err(r)); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 156 | |
markus@openbsd.org | b8d9214 | 2018-07-09 21:37:55 +0000 | [diff] [blame] | 157 | recv_tok.value = p; |
| 158 | recv_tok.length = len; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 159 | maj_status = PRIVSEP(ssh_gssapi_accept_ctx(gssctxt, &recv_tok, |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 160 | &send_tok, &flags)); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 161 | |
markus@openbsd.org | b8d9214 | 2018-07-09 21:37:55 +0000 | [diff] [blame] | 162 | free(p); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 163 | |
| 164 | if (GSS_ERROR(maj_status)) { |
| 165 | if (send_tok.length != 0) { |
markus@openbsd.org | b8d9214 | 2018-07-09 21:37:55 +0000 | [diff] [blame] | 166 | if ((r = sshpkt_start(ssh, |
| 167 | SSH2_MSG_USERAUTH_GSSAPI_ERRTOK)) != 0 || |
| 168 | (r = sshpkt_put_string(ssh, send_tok.value, |
| 169 | send_tok.length)) != 0 || |
| 170 | (r = sshpkt_send(ssh)) != 0) |
| 171 | fatal("%s: %s", __func__, ssh_err(r)); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 172 | } |
| 173 | authctxt->postponed = 0; |
markus@openbsd.org | eb272ea | 2017-05-30 14:29:59 +0000 | [diff] [blame] | 174 | ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL); |
| 175 | userauth_finish(ssh, 0, "gssapi-with-mic", NULL); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 176 | } else { |
| 177 | if (send_tok.length != 0) { |
markus@openbsd.org | b8d9214 | 2018-07-09 21:37:55 +0000 | [diff] [blame] | 178 | if ((r = sshpkt_start(ssh, |
| 179 | SSH2_MSG_USERAUTH_GSSAPI_TOKEN)) != 0 || |
| 180 | (r = sshpkt_put_string(ssh, send_tok.value, |
| 181 | send_tok.length)) != 0 || |
| 182 | (r = sshpkt_send(ssh)) != 0) |
| 183 | fatal("%s: %s", __func__, ssh_err(r)); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 184 | } |
| 185 | if (maj_status == GSS_S_COMPLETE) { |
markus@openbsd.org | eb272ea | 2017-05-30 14:29:59 +0000 | [diff] [blame] | 186 | ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL); |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 187 | if (flags & GSS_C_INTEG_FLAG) |
markus@openbsd.org | eb272ea | 2017-05-30 14:29:59 +0000 | [diff] [blame] | 188 | ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_MIC, |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 189 | &input_gssapi_mic); |
| 190 | else |
markus@openbsd.org | eb272ea | 2017-05-30 14:29:59 +0000 | [diff] [blame] | 191 | ssh_dispatch_set(ssh, |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 192 | SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE, |
| 193 | &input_gssapi_exchange_complete); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
| 197 | gss_release_buffer(&min_status, &send_tok); |
markus@openbsd.org | 3fdc88a | 2015-01-19 20:07:45 +0000 | [diff] [blame] | 198 | return 0; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 199 | } |
| 200 | |
markus@openbsd.org | 3fdc88a | 2015-01-19 20:07:45 +0000 | [diff] [blame] | 201 | static int |
markus@openbsd.org | 2ae666a | 2017-05-30 14:23:52 +0000 | [diff] [blame] | 202 | input_gssapi_errtok(int type, u_int32_t plen, struct ssh *ssh) |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 203 | { |
markus@openbsd.org | 5f4082d | 2017-05-30 14:18:15 +0000 | [diff] [blame] | 204 | Authctxt *authctxt = ssh->authctxt; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 205 | Gssctxt *gssctxt; |
| 206 | gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER; |
| 207 | gss_buffer_desc recv_tok; |
| 208 | OM_uint32 maj_status; |
markus@openbsd.org | b8d9214 | 2018-07-09 21:37:55 +0000 | [diff] [blame] | 209 | int r; |
djm@openbsd.org | 0f3958c | 2018-07-10 09:13:30 +0000 | [diff] [blame] | 210 | u_char *p; |
| 211 | size_t len; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 212 | |
| 213 | if (authctxt == NULL || (authctxt->methoddata == NULL && !use_privsep)) |
| 214 | fatal("No authentication or GSSAPI context"); |
| 215 | |
| 216 | gssctxt = authctxt->methoddata; |
djm@openbsd.org | 0f3958c | 2018-07-10 09:13:30 +0000 | [diff] [blame] | 217 | if ((r = sshpkt_get_string(ssh, &p, &len)) != 0 || |
markus@openbsd.org | b8d9214 | 2018-07-09 21:37:55 +0000 | [diff] [blame] | 218 | (r = sshpkt_get_end(ssh)) != 0) |
| 219 | fatal("%s: %s", __func__, ssh_err(r)); |
djm@openbsd.org | 0f3958c | 2018-07-10 09:13:30 +0000 | [diff] [blame] | 220 | recv_tok.value = p; |
| 221 | recv_tok.length = len; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 222 | |
| 223 | /* Push the error token into GSSAPI to see what it says */ |
| 224 | maj_status = PRIVSEP(ssh_gssapi_accept_ctx(gssctxt, &recv_tok, |
| 225 | &send_tok, NULL)); |
| 226 | |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 227 | free(recv_tok.value); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 228 | |
| 229 | /* We can't return anything to the client, even if we wanted to */ |
markus@openbsd.org | eb272ea | 2017-05-30 14:29:59 +0000 | [diff] [blame] | 230 | ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL); |
| 231 | ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_ERRTOK, NULL); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 232 | |
| 233 | /* The client will have already moved on to the next auth */ |
| 234 | |
| 235 | gss_release_buffer(&maj_status, &send_tok); |
markus@openbsd.org | 3fdc88a | 2015-01-19 20:07:45 +0000 | [diff] [blame] | 236 | return 0; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | /* |
| 240 | * This is called when the client thinks we've completed authentication. |
| 241 | * It should only be enabled in the dispatch handler by the function above, |
| 242 | * which only enables it once the GSSAPI exchange is complete. |
| 243 | */ |
| 244 | |
markus@openbsd.org | 3fdc88a | 2015-01-19 20:07:45 +0000 | [diff] [blame] | 245 | static int |
markus@openbsd.org | 2ae666a | 2017-05-30 14:23:52 +0000 | [diff] [blame] | 246 | input_gssapi_exchange_complete(int type, u_int32_t plen, struct ssh *ssh) |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 247 | { |
markus@openbsd.org | 5f4082d | 2017-05-30 14:18:15 +0000 | [diff] [blame] | 248 | Authctxt *authctxt = ssh->authctxt; |
djm@openbsd.org | 0f3958c | 2018-07-10 09:13:30 +0000 | [diff] [blame] | 249 | int r, authenticated; |
djm@openbsd.org | 8f57495 | 2017-06-24 06:34:38 +0000 | [diff] [blame] | 250 | const char *displayname; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 251 | |
| 252 | if (authctxt == NULL || (authctxt->methoddata == NULL && !use_privsep)) |
| 253 | fatal("No authentication or GSSAPI context"); |
| 254 | |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 255 | /* |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 256 | * We don't need to check the status, because we're only enabled in |
| 257 | * the dispatcher once the exchange is complete |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 258 | */ |
| 259 | |
markus@openbsd.org | b8d9214 | 2018-07-09 21:37:55 +0000 | [diff] [blame] | 260 | if ((r = sshpkt_get_end(ssh)) != 0) |
| 261 | fatal("%s: %s", __func__, ssh_err(r)); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 262 | |
| 263 | authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user)); |
| 264 | |
djm@openbsd.org | 8f57495 | 2017-06-24 06:34:38 +0000 | [diff] [blame] | 265 | if ((!use_privsep || mm_is_monitor()) && |
| 266 | (displayname = ssh_gssapi_displayname()) != NULL) |
| 267 | auth2_record_info(authctxt, "%s", displayname); |
| 268 | |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 269 | authctxt->postponed = 0; |
markus@openbsd.org | eb272ea | 2017-05-30 14:29:59 +0000 | [diff] [blame] | 270 | ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL); |
| 271 | ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_ERRTOK, NULL); |
| 272 | ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_MIC, NULL); |
| 273 | ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE, NULL); |
| 274 | userauth_finish(ssh, authenticated, "gssapi-with-mic", NULL); |
markus@openbsd.org | 3fdc88a | 2015-01-19 20:07:45 +0000 | [diff] [blame] | 275 | return 0; |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 276 | } |
| 277 | |
markus@openbsd.org | 3fdc88a | 2015-01-19 20:07:45 +0000 | [diff] [blame] | 278 | static int |
markus@openbsd.org | 2ae666a | 2017-05-30 14:23:52 +0000 | [diff] [blame] | 279 | input_gssapi_mic(int type, u_int32_t plen, struct ssh *ssh) |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 280 | { |
markus@openbsd.org | 5f4082d | 2017-05-30 14:18:15 +0000 | [diff] [blame] | 281 | Authctxt *authctxt = ssh->authctxt; |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 282 | Gssctxt *gssctxt; |
markus@openbsd.org | b8d9214 | 2018-07-09 21:37:55 +0000 | [diff] [blame] | 283 | int r, authenticated = 0; |
| 284 | struct sshbuf *b; |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 285 | gss_buffer_desc mic, gssbuf; |
djm@openbsd.org | 8f57495 | 2017-06-24 06:34:38 +0000 | [diff] [blame] | 286 | const char *displayname; |
djm@openbsd.org | 0f3958c | 2018-07-10 09:13:30 +0000 | [diff] [blame] | 287 | u_char *p; |
| 288 | size_t len; |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 289 | |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 290 | if (authctxt == NULL || (authctxt->methoddata == NULL && !use_privsep)) |
| 291 | fatal("No authentication or GSSAPI context"); |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 292 | |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 293 | gssctxt = authctxt->methoddata; |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 294 | |
djm@openbsd.org | 0f3958c | 2018-07-10 09:13:30 +0000 | [diff] [blame] | 295 | if ((r = sshpkt_get_string(ssh, &p, &len)) != 0) |
markus@openbsd.org | b8d9214 | 2018-07-09 21:37:55 +0000 | [diff] [blame] | 296 | fatal("%s: %s", __func__, ssh_err(r)); |
| 297 | if ((b = sshbuf_new()) == NULL) |
| 298 | fatal("%s: sshbuf_new failed", __func__); |
djm@openbsd.org | 0f3958c | 2018-07-10 09:13:30 +0000 | [diff] [blame] | 299 | mic.value = p; |
| 300 | mic.length = len; |
markus@openbsd.org | b8d9214 | 2018-07-09 21:37:55 +0000 | [diff] [blame] | 301 | ssh_gssapi_buildmic(b, authctxt->user, authctxt->service, |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 302 | "gssapi-with-mic"); |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 303 | |
markus@openbsd.org | b8d9214 | 2018-07-09 21:37:55 +0000 | [diff] [blame] | 304 | if ((gssbuf.value = sshbuf_mutable_ptr(b)) == NULL) |
| 305 | fatal("%s: sshbuf_mutable_ptr failed", __func__); |
| 306 | gssbuf.length = sshbuf_len(b); |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 307 | |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 308 | if (!GSS_ERROR(PRIVSEP(ssh_gssapi_checkmic(gssctxt, &gssbuf, &mic)))) |
| 309 | authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user)); |
| 310 | else |
| 311 | logit("GSSAPI MIC check failed"); |
| 312 | |
markus@openbsd.org | b8d9214 | 2018-07-09 21:37:55 +0000 | [diff] [blame] | 313 | sshbuf_free(b); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 314 | free(mic.value); |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 315 | |
djm@openbsd.org | 8f57495 | 2017-06-24 06:34:38 +0000 | [diff] [blame] | 316 | if ((!use_privsep || mm_is_monitor()) && |
| 317 | (displayname = ssh_gssapi_displayname()) != NULL) |
| 318 | auth2_record_info(authctxt, "%s", displayname); |
| 319 | |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 320 | authctxt->postponed = 0; |
markus@openbsd.org | eb272ea | 2017-05-30 14:29:59 +0000 | [diff] [blame] | 321 | ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL); |
| 322 | ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_ERRTOK, NULL); |
| 323 | ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_MIC, NULL); |
| 324 | ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE, NULL); |
| 325 | userauth_finish(ssh, authenticated, "gssapi-with-mic", NULL); |
markus@openbsd.org | 3fdc88a | 2015-01-19 20:07:45 +0000 | [diff] [blame] | 326 | return 0; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | Authmethod method_gssapi = { |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 330 | "gssapi-with-mic", |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 331 | userauth_gssapi, |
| 332 | &options.gss_authentication |
| 333 | }; |
Darren Tucker | 8c6feda | 2006-08-05 15:24:59 +1000 | [diff] [blame] | 334 | |
| 335 | #endif /* GSSAPI */ |