summaryrefslogtreecommitdiff
path: root/gss-genr.c
diff options
context:
space:
mode:
Diffstat (limited to 'gss-genr.c')
-rw-r--r--gss-genr.c61
1 files changed, 42 insertions, 19 deletions
diff --git a/gss-genr.c b/gss-genr.c
index 62559ed9e..d56257b4a 100644
--- a/gss-genr.c
+++ b/gss-genr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: gss-genr.c,v 1.24 2016/09/12 01:22:38 deraadt Exp $ */ 1/* $OpenBSD: gss-genr.c,v 1.26 2018/07/10 09:13:30 djm Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved. 4 * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved.
@@ -37,7 +37,8 @@
37#include <unistd.h> 37#include <unistd.h>
38 38
39#include "xmalloc.h" 39#include "xmalloc.h"
40#include "buffer.h" 40#include "ssherr.h"
41#include "sshbuf.h"
41#include "log.h" 42#include "log.h"
42#include "ssh2.h" 43#include "ssh2.h"
43 44
@@ -46,6 +47,21 @@
46extern u_char *session_id2; 47extern u_char *session_id2;
47extern u_int session_id2_len; 48extern u_int session_id2_len;
48 49
50/* sshbuf_get for gss_buffer_desc */
51int
52ssh_gssapi_get_buffer_desc(struct sshbuf *b, gss_buffer_desc *g)
53{
54 int r;
55 u_char *p;
56 size_t len;
57
58 if ((r = sshbuf_get_string(b, &p, &len)) != 0)
59 return r;
60 g->value = p;
61 g->length = len;
62 return 0;
63}
64
49/* Check that the OID in a data stream matches that in the context */ 65/* Check that the OID in a data stream matches that in the context */
50int 66int
51ssh_gssapi_check_oid(Gssctxt *ctx, void *data, size_t len) 67ssh_gssapi_check_oid(Gssctxt *ctx, void *data, size_t len)
@@ -94,10 +110,12 @@ ssh_gssapi_last_error(Gssctxt *ctxt, OM_uint32 *major_status,
94 OM_uint32 lmin; 110 OM_uint32 lmin;
95 gss_buffer_desc msg = GSS_C_EMPTY_BUFFER; 111 gss_buffer_desc msg = GSS_C_EMPTY_BUFFER;
96 OM_uint32 ctx; 112 OM_uint32 ctx;
97 Buffer b; 113 struct sshbuf *b;
98 char *ret; 114 char *ret;
115 int r;
99 116
100 buffer_init(&b); 117 if ((b = sshbuf_new()) == NULL)
118 fatal("%s: sshbuf_new failed", __func__);
101 119
102 if (major_status != NULL) 120 if (major_status != NULL)
103 *major_status = ctxt->major; 121 *major_status = ctxt->major;
@@ -110,8 +128,9 @@ ssh_gssapi_last_error(Gssctxt *ctxt, OM_uint32 *major_status,
110 gss_display_status(&lmin, ctxt->major, 128 gss_display_status(&lmin, ctxt->major,
111 GSS_C_GSS_CODE, ctxt->oid, &ctx, &msg); 129 GSS_C_GSS_CODE, ctxt->oid, &ctx, &msg);
112 130
113 buffer_append(&b, msg.value, msg.length); 131 if ((r = sshbuf_put(b, msg.value, msg.length)) != 0 ||
114 buffer_put_char(&b, '\n'); 132 (r = sshbuf_put_u8(b, '\n')) != 0)
133 fatal("%s: buffer error: %s", __func__, ssh_err(r));
115 134
116 gss_release_buffer(&lmin, &msg); 135 gss_release_buffer(&lmin, &msg);
117 } while (ctx != 0); 136 } while (ctx != 0);
@@ -121,16 +140,17 @@ ssh_gssapi_last_error(Gssctxt *ctxt, OM_uint32 *major_status,
121 gss_display_status(&lmin, ctxt->minor, 140 gss_display_status(&lmin, ctxt->minor,
122 GSS_C_MECH_CODE, ctxt->oid, &ctx, &msg); 141 GSS_C_MECH_CODE, ctxt->oid, &ctx, &msg);
123 142
124 buffer_append(&b, msg.value, msg.length); 143 if ((r = sshbuf_put(b, msg.value, msg.length)) != 0 ||
125 buffer_put_char(&b, '\n'); 144 (r = sshbuf_put_u8(b, '\n')) != 0)
145 fatal("%s: buffer error: %s", __func__, ssh_err(r));
126 146
127 gss_release_buffer(&lmin, &msg); 147 gss_release_buffer(&lmin, &msg);
128 } while (ctx != 0); 148 } while (ctx != 0);
129 149
130 buffer_put_char(&b, '\0'); 150 if ((r = sshbuf_put_u8(b, '\n')) != 0)
131 ret = xmalloc(buffer_len(&b)); 151 fatal("%s: buffer error: %s", __func__, ssh_err(r));
132 buffer_get(&b, ret, buffer_len(&b)); 152 ret = xstrdup((const char *)sshbuf_ptr(b));
133 buffer_free(&b); 153 sshbuf_free(b);
134 return (ret); 154 return (ret);
135} 155}
136 156
@@ -238,15 +258,18 @@ ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_t buffer, gss_buffer_t hash)
238} 258}
239 259
240void 260void
241ssh_gssapi_buildmic(Buffer *b, const char *user, const char *service, 261ssh_gssapi_buildmic(struct sshbuf *b, const char *user, const char *service,
242 const char *context) 262 const char *context)
243{ 263{
244 buffer_init(b); 264 int r;
245 buffer_put_string(b, session_id2, session_id2_len); 265
246 buffer_put_char(b, SSH2_MSG_USERAUTH_REQUEST); 266 sshbuf_reset(b);
247 buffer_put_cstring(b, user); 267 if ((r = sshbuf_put_string(b, session_id2, session_id2_len)) != 0 ||
248 buffer_put_cstring(b, service); 268 (r = sshbuf_put_u8(b, SSH2_MSG_USERAUTH_REQUEST)) != 0 ||
249 buffer_put_cstring(b, context); 269 (r = sshbuf_put_cstring(b, user)) != 0 ||
270 (r = sshbuf_put_cstring(b, service)) != 0 ||
271 (r = sshbuf_put_cstring(b, context)) != 0)
272 fatal("%s: buffer error: %s", __func__, ssh_err(r));
250} 273}
251 274
252int 275int