diff options
author | Markus Friedl <markus@cvs.openbsd.org> | 2018-07-09 21:37:56 +0000 |
---|---|---|
committer | Markus Friedl <markus@cvs.openbsd.org> | 2018-07-09 21:37:56 +0000 |
commit | b9542799fc38cf1479c204486c8fd4b59af12737 (patch) | |
tree | 9c666b3ba09950953d03a3f54555983b6e901ecd /usr.bin/ssh | |
parent | 8742b67b460db60a91ac5b3f37cb4e6f7116edb7 (diff) |
sshd: switch GSSAPI to sshbuf API; ok djm@
Diffstat (limited to 'usr.bin/ssh')
-rw-r--r-- | usr.bin/ssh/auth2-gss.c | 95 | ||||
-rw-r--r-- | usr.bin/ssh/gss-genr.c | 46 | ||||
-rw-r--r-- | usr.bin/ssh/gss-serv-krb5.c | 5 | ||||
-rw-r--r-- | usr.bin/ssh/gss-serv.c | 5 |
4 files changed, 86 insertions, 65 deletions
diff --git a/usr.bin/ssh/auth2-gss.c b/usr.bin/ssh/auth2-gss.c index c9c11a130c9..789206ef2f2 100644 --- a/usr.bin/ssh/auth2-gss.c +++ b/usr.bin/ssh/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. @@ -29,13 +29,14 @@ #include <sys/types.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 "servconf.h" #include "packet.h" #include "ssh-gss.h" @@ -58,16 +59,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); @@ -79,7 +82,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) { @@ -107,12 +111,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); @@ -130,36 +134,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); @@ -185,16 +198,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, @@ -233,7 +246,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)); @@ -255,10 +269,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)) @@ -266,21 +279,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()) && diff --git a/usr.bin/ssh/gss-genr.c b/usr.bin/ssh/gss-genr.c index 4055317bcaa..14e8a8d3c67 100644 --- a/usr.bin/ssh/gss-genr.c +++ b/usr.bin/ssh/gss-genr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gss-genr.c,v 1.24 2016/09/12 01:22:38 deraadt Exp $ */ +/* $OpenBSD: gss-genr.c,v 1.25 2018/07/09 21:37:55 markus Exp $ */ /* * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved. @@ -32,7 +32,8 @@ #include <limits.h> #include "xmalloc.h" -#include "buffer.h" +#include "ssherr.h" +#include "sshbuf.h" #include "log.h" #include "ssh2.h" @@ -89,10 +90,12 @@ ssh_gssapi_last_error(Gssctxt *ctxt, OM_uint32 *major_status, OM_uint32 lmin; gss_buffer_desc msg = GSS_C_EMPTY_BUFFER; OM_uint32 ctx; - Buffer b; + struct sshbuf *b; char *ret; + int r; - buffer_init(&b); + if ((b = sshbuf_new()) == NULL) + fatal("%s: sshbuf_new failed", __func__); if (major_status != NULL) *major_status = ctxt->major; @@ -105,8 +108,9 @@ ssh_gssapi_last_error(Gssctxt *ctxt, OM_uint32 *major_status, gss_display_status(&lmin, ctxt->major, GSS_C_GSS_CODE, ctxt->oid, &ctx, &msg); - buffer_append(&b, msg.value, msg.length); - buffer_put_char(&b, '\n'); + if ((r = sshbuf_put(b, msg.value, msg.length)) != 0 || + (r = sshbuf_put_u8(b, '\n')) != 0) + fatal("%s: buffer error: %s", __func__, ssh_err(r)); gss_release_buffer(&lmin, &msg); } while (ctx != 0); @@ -116,16 +120,17 @@ ssh_gssapi_last_error(Gssctxt *ctxt, OM_uint32 *major_status, gss_display_status(&lmin, ctxt->minor, GSS_C_MECH_CODE, ctxt->oid, &ctx, &msg); - buffer_append(&b, msg.value, msg.length); - buffer_put_char(&b, '\n'); + if ((r = sshbuf_put(b, msg.value, msg.length)) != 0 || + (r = sshbuf_put_u8(b, '\n')) != 0) + fatal("%s: buffer error: %s", __func__, ssh_err(r)); gss_release_buffer(&lmin, &msg); } while (ctx != 0); - buffer_put_char(&b, '\0'); - ret = xmalloc(buffer_len(&b)); - buffer_get(&b, ret, buffer_len(&b)); - buffer_free(&b); + if ((r = sshbuf_put_u8(b, '\n')) != 0) + fatal("%s: buffer error: %s", __func__, ssh_err(r)); + ret = xstrdup((const char *)sshbuf_ptr(b)); + sshbuf_free(b); return (ret); } @@ -233,15 +238,18 @@ ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_t buffer, gss_buffer_t hash) } void -ssh_gssapi_buildmic(Buffer *b, const char *user, const char *service, +ssh_gssapi_buildmic(struct sshbuf *b, const char *user, const char *service, const char *context) { - buffer_init(b); - buffer_put_string(b, session_id2, session_id2_len); - buffer_put_char(b, SSH2_MSG_USERAUTH_REQUEST); - buffer_put_cstring(b, user); - buffer_put_cstring(b, service); - buffer_put_cstring(b, context); + int r; + + sshbuf_reset(b); + if ((r = sshbuf_put_string(b, session_id2, session_id2_len)) != 0 || + (r = sshbuf_put_u8(b, SSH2_MSG_USERAUTH_REQUEST)) != 0 || + (r = sshbuf_put_cstring(b, user)) != 0 || + (r = sshbuf_put_cstring(b, service)) != 0 || + (r = sshbuf_put_cstring(b, context)) != 0) + fatal("%s: buffer error: %s", __func__, ssh_err(r)); } int diff --git a/usr.bin/ssh/gss-serv-krb5.c b/usr.bin/ssh/gss-serv-krb5.c index 530216bf25f..f857500f04a 100644 --- a/usr.bin/ssh/gss-serv-krb5.c +++ b/usr.bin/ssh/gss-serv-krb5.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gss-serv-krb5.c,v 1.8 2013/07/20 01:55:13 djm Exp $ */ +/* $OpenBSD: gss-serv-krb5.c,v 1.9 2018/07/09 21:37:55 markus Exp $ */ /* * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved. @@ -30,12 +30,11 @@ #include <sys/types.h> #include "xmalloc.h" -#include "key.h" +#include "sshkey.h" #include "hostfile.h" #include "auth.h" #include "log.h" -#include "buffer.h" #include "ssh-gss.h" #include <krb5.h> diff --git a/usr.bin/ssh/gss-serv.c b/usr.bin/ssh/gss-serv.c index add350db382..b4f4208b526 100644 --- a/usr.bin/ssh/gss-serv.c +++ b/usr.bin/ssh/gss-serv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gss-serv.c,v 1.30 2017/06/24 06:34:38 djm Exp $ */ +/* $OpenBSD: gss-serv.c,v 1.31 2018/07/09 21:37:55 markus Exp $ */ /* * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved. @@ -32,8 +32,7 @@ #include <string.h> #include "xmalloc.h" -#include "buffer.h" -#include "key.h" +#include "sshkey.h" #include "hostfile.h" #include "auth.h" #include "log.h" |