-/* $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.
#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"
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);
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) {
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);
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);
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,
* 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));
{
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))
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()) &&
-/* $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.
#include <limits.h>
#include "xmalloc.h"
-#include "buffer.h"
+#include "ssherr.h"
+#include "sshbuf.h"
#include "log.h"
#include "ssh2.h"
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;
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);
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);
}
}
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