diff options
author | markus@openbsd.org <markus@openbsd.org> | 2018-07-09 23:37:55 +0200 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2018-07-10 07:28:30 +0200 |
commit | b8d9214d969775e409e1408ecdf0d58fad99b344 (patch) | |
tree | a14a0ac02bd578cb35129946f86aaa12797d0199 /auth2-gss.c | |
parent | upstream: sshd: switch authentication to sshbuf API; ok djm@ (diff) | |
download | openssh-b8d9214d969775e409e1408ecdf0d58fad99b344.tar.xz openssh-b8d9214d969775e409e1408ecdf0d58fad99b344.zip |
upstream: sshd: switch GSSAPI to sshbuf API; ok djm@
OpenBSD-Commit-ID: e48449ab4be3f006f7ba33c66241b7d652973e30
Diffstat (limited to 'auth2-gss.c')
-rw-r--r-- | auth2-gss.c | 95 |
1 files changed, 55 insertions, 40 deletions
diff --git a/auth2-gss.c b/auth2-gss.c index 589283b72..a6f2a7125 100644 --- a/auth2-gss.c +++ b/auth2-gss.c @@ -1,4 +1,4 @@ -/* $OpenBSD: auth2-gss.c,v 1.26 2017/06/24 06:34:38 djm Exp $ */ +/* $OpenBSD: auth2-gss.c,v 1.27 2018/07/09 21:37:55 markus Exp $ */ /* * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved. @@ -33,13 +33,14 @@ #include <stdarg.h> #include "xmalloc.h" -#include "key.h" +#include "sshkey.h" #include "hostfile.h" #include "auth.h" #include "ssh2.h" #include "log.h" #include "dispatch.h" -#include "buffer.h" +#include "sshbuf.h" +#include "ssherr.h" #include "misc.h" #include "servconf.h" #include "packet.h" @@ -63,16 +64,18 @@ userauth_gssapi(struct ssh *ssh) Authctxt *authctxt = ssh->authctxt; gss_OID_desc goid = {0, NULL}; Gssctxt *ctxt = NULL; - int mechs; - int present; + int r, present; + u_int mechs; OM_uint32 ms; - u_int len; + size_t len; u_char *doid = NULL; if (!authctxt->valid || authctxt->user == NULL) return (0); - mechs = packet_get_int(); + if ((r = sshpkt_get_u32(ssh, &mechs)) != 0) + fatal("%s: %s", __func__, ssh_err(r)); + if (mechs == 0) { debug("Mechanism negotiation is not supported"); return (0); @@ -84,7 +87,8 @@ userauth_gssapi(struct ssh *ssh) free(doid); present = 0; - doid = packet_get_string(&len); + if ((r = sshpkt_get_string(ssh, &doid, &len)) != 0) + fatal("%s: %s", __func__, ssh_err(r)); if (len > 2 && doid[0] == SSH_GSS_OIDTYPE && doid[1] == len - 2) { @@ -112,12 +116,12 @@ userauth_gssapi(struct ssh *ssh) authctxt->methoddata = (void *)ctxt; - packet_start(SSH2_MSG_USERAUTH_GSSAPI_RESPONSE); - /* Return the OID that we received */ - packet_put_string(doid, len); + if ((r = sshpkt_start(ssh, SSH2_MSG_USERAUTH_GSSAPI_RESPONSE)) != 0 || + (r = sshpkt_put_string(ssh, doid, len)) != 0 || + (r = sshpkt_send(ssh)) != 0) + fatal("%s: %s", __func__, ssh_err(r)); - packet_send(); free(doid); ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_TOKEN, &input_gssapi_token); @@ -135,36 +139,45 @@ input_gssapi_token(int type, u_int32_t plen, struct ssh *ssh) gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER; gss_buffer_desc recv_tok; OM_uint32 maj_status, min_status, flags; - u_int len; + u_char *p; + size_t len; + int r; if (authctxt == NULL || (authctxt->methoddata == NULL && !use_privsep)) fatal("No authentication or GSSAPI context"); gssctxt = authctxt->methoddata; - recv_tok.value = packet_get_string(&len); - recv_tok.length = len; /* u_int vs. size_t */ - - packet_check_eom(); + if ((r = sshpkt_get_string(ssh, &p, &len)) != 0 || + (r = sshpkt_get_end(ssh)) != 0) + fatal("%s: %s", __func__, ssh_err(r)); + recv_tok.value = p; + recv_tok.length = len; maj_status = PRIVSEP(ssh_gssapi_accept_ctx(gssctxt, &recv_tok, &send_tok, &flags)); - free(recv_tok.value); + free(p); if (GSS_ERROR(maj_status)) { if (send_tok.length != 0) { - packet_start(SSH2_MSG_USERAUTH_GSSAPI_ERRTOK); - packet_put_string(send_tok.value, send_tok.length); - packet_send(); + if ((r = sshpkt_start(ssh, + SSH2_MSG_USERAUTH_GSSAPI_ERRTOK)) != 0 || + (r = sshpkt_put_string(ssh, send_tok.value, + send_tok.length)) != 0 || + (r = sshpkt_send(ssh)) != 0) + fatal("%s: %s", __func__, ssh_err(r)); } authctxt->postponed = 0; ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL); userauth_finish(ssh, 0, "gssapi-with-mic", NULL); } else { if (send_tok.length != 0) { - packet_start(SSH2_MSG_USERAUTH_GSSAPI_TOKEN); - packet_put_string(send_tok.value, send_tok.length); - packet_send(); + if ((r = sshpkt_start(ssh, + SSH2_MSG_USERAUTH_GSSAPI_TOKEN)) != 0 || + (r = sshpkt_put_string(ssh, send_tok.value, + send_tok.length)) != 0 || + (r = sshpkt_send(ssh)) != 0) + fatal("%s: %s", __func__, ssh_err(r)); } if (maj_status == GSS_S_COMPLETE) { ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL); @@ -190,16 +203,16 @@ input_gssapi_errtok(int type, u_int32_t plen, struct ssh *ssh) gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER; gss_buffer_desc recv_tok; OM_uint32 maj_status; - u_int len; + int r; if (authctxt == NULL || (authctxt->methoddata == NULL && !use_privsep)) fatal("No authentication or GSSAPI context"); gssctxt = authctxt->methoddata; - recv_tok.value = packet_get_string(&len); - recv_tok.length = len; - - packet_check_eom(); + if ((r = sshpkt_get_string(ssh, + &recv_tok.value, &recv_tok.length)) != 0 || + (r = sshpkt_get_end(ssh)) != 0) + fatal("%s: %s", __func__, ssh_err(r)); /* Push the error token into GSSAPI to see what it says */ maj_status = PRIVSEP(ssh_gssapi_accept_ctx(gssctxt, &recv_tok, @@ -238,7 +251,8 @@ input_gssapi_exchange_complete(int type, u_int32_t plen, struct ssh *ssh) * the dispatcher once the exchange is complete */ - packet_check_eom(); + if ((r = sshpkt_get_end(ssh)) != 0) + fatal("%s: %s", __func__, ssh_err(r)); authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user)); @@ -260,10 +274,9 @@ input_gssapi_mic(int type, u_int32_t plen, struct ssh *ssh) { Authctxt *authctxt = ssh->authctxt; Gssctxt *gssctxt; - int authenticated = 0; - Buffer b; + int r, authenticated = 0; + struct sshbuf *b; gss_buffer_desc mic, gssbuf; - u_int len; const char *displayname; if (authctxt == NULL || (authctxt->methoddata == NULL && !use_privsep)) @@ -271,21 +284,23 @@ input_gssapi_mic(int type, u_int32_t plen, struct ssh *ssh) gssctxt = authctxt->methoddata; - mic.value = packet_get_string(&len); - mic.length = len; - - ssh_gssapi_buildmic(&b, authctxt->user, authctxt->service, + if ((r = sshpkt_get_string(ssh, &mic.value, &mic.length)) != 0) + fatal("%s: %s", __func__, ssh_err(r)); + if ((b = sshbuf_new()) == NULL) + fatal("%s: sshbuf_new failed", __func__); + ssh_gssapi_buildmic(b, authctxt->user, authctxt->service, "gssapi-with-mic"); - gssbuf.value = buffer_ptr(&b); - gssbuf.length = buffer_len(&b); + if ((gssbuf.value = sshbuf_mutable_ptr(b)) == NULL) + fatal("%s: sshbuf_mutable_ptr failed", __func__); + gssbuf.length = sshbuf_len(b); if (!GSS_ERROR(PRIVSEP(ssh_gssapi_checkmic(gssctxt, &gssbuf, &mic)))) authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user)); else logit("GSSAPI MIC check failed"); - buffer_free(&b); + sshbuf_free(b); free(mic.value); if ((!use_privsep || mm_is_monitor()) && |