From 8db40b6c2a66810ea63345b14165756697e28c00 Mon Sep 17 00:00:00 2001 From: Assar Westerlund Date: Mon, 14 Jul 1997 11:34:10 +0000 Subject: [PATCH] removed all krb5 calls git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@2267 ec53bebd-3082-4978-b11e-865c3cabbd6b --- appl/test/gssapi_client.c | 85 ++++++++++++++++++++++----------------- appl/test/gssapi_server.c | 79 +++++++++++++++++++----------------- 2 files changed, 90 insertions(+), 74 deletions(-) diff --git a/appl/test/gssapi_client.c b/appl/test/gssapi_client.c index 38bd1fc9e..11b0b278d 100644 --- a/appl/test/gssapi_client.c +++ b/appl/test/gssapi_client.c @@ -20,24 +20,19 @@ proto (int sock, const char *hostname, const char *service) gss_buffer_desc real_input_token, real_output_token; OM_uint32 maj_stat, min_stat; u_int32_t len, net_len; + gss_name_t server; + gss_buffer_desc name_token; + char *n; - krb5_context context; - krb5_principal server; - krb5_error_code status; + name_token.length = asprintf ((char **)&name_token.value, + "%s@%s", service, hostname); - status = krb5_init_context(&context); - if (status) - errx (1, "krb5_init_context: %s", - krb5_get_err_text(context, status)); - - status = krb5_sname_to_principal (context, - hostname, - service, - KRB5_NT_SRV_INST, - &server); - if (status) - errx (1, "krb5_sname_to_principal: %s", - krb5_get_err_text(context, status)); + maj_stat = gss_import_name (&min_stat, + &name_token, + GSS_C_NT_HOSTBASED_SERVICE, + &server); + if (GSS_ERROR(maj_stat)) + abort (); addrlen = sizeof(local); if (getsockname (sock, (struct sockaddr *)&local, &addrlen) < 0 @@ -72,19 +67,8 @@ proto (int sock, const char *hostname, const char *service) NULL); if (GSS_ERROR(maj_stat)) abort (); - if (output_token->length != 0) { - len = output_token->length; - - net_len = htonl(len); - - if (write (sock, &net_len, 4) != 4) - err (1, "write"); - if (write (sock, output_token->value, len) != len) - err (1, "write"); - - gss_release_buffer (&min_stat, - output_token); - } + if (output_token->length != 0) + write_token (sock, output_token); if (GSS_ERROR(maj_stat)) { if (context_hdl != GSS_C_NO_CONTEXT) gss_delete_sec_context (&min_stat, @@ -93,18 +77,47 @@ proto (int sock, const char *hostname, const char *service) break; } if (maj_stat & GSS_S_CONTINUE_NEEDED) { - if (read(sock, &net_len, 4) != 4) - err (1, "read"); - len = ntohl(net_len); - input_token->length = len; - input_token->value = malloc(len); - if (read (sock, input_token->value, len) != len) - err (1, "read"); + read_token (sock, input_token); } else { context_established = 1; } } + + /* get_mic */ + + input_token->length = 3; + input_token->value = strdup("hej"); + + maj_stat = gss_get_mic(&min_stat, + context_hdl, + GSS_C_QOP_DEFAULT, + input_token, + output_token); + if (GSS_ERROR(maj_stat)) + abort (); + + write_token (sock, input_token); + write_token (sock, output_token); + + /* wrap */ + + input_token->length = 7; + input_token->value = "hemligt"; + + + maj_stat = gss_wrap (&min_stat, + context_hdl, + 1, + GSS_C_QOP_DEFAULT, + input_token, + NULL, + output_token); + if (GSS_ERROR(maj_stat)) + abort (); + + write_token (sock, output_token); + return 0; } diff --git a/appl/test/gssapi_server.c b/appl/test/gssapi_server.c index 9c6c4eb6e..579474a83 100644 --- a/appl/test/gssapi_server.c +++ b/appl/test/gssapi_server.c @@ -19,11 +19,7 @@ proto (int sock, const char *service) OM_uint32 maj_stat, min_stat; gss_name_t client_name; u_int32_t len, net_len; - char *name; - - krb5_context context; - krb5_principal server; - krb5_error_code status; + gss_buffer_desc name_token; addrlen = sizeof(local); if (getsockname (sock, (struct sockaddr *)&local, &addrlen) < 0 @@ -35,22 +31,11 @@ proto (int sock, const char *service) || addrlen != sizeof(remote)) err (1, "getpeername"); - status = krb5_init_context(&context); - if (status) - errx (1, "krb5_init_context: %s", - krb5_get_err_text(context, status)); - input_token = &real_input_token; output_token = &real_output_token; do { - if (read(sock, &net_len, 4) != 4) - err (1, "read"); - len = ntohl(net_len); - input_token->length = len; - input_token->value = malloc(len); - if (read (sock, input_token->value, len) != len) - err (1, "read"); + read_token (sock, input_token); maj_stat = gss_accept_sec_context (&min_stat, &context_hdl, @@ -65,19 +50,8 @@ proto (int sock, const char *service) NULL); if(GSS_ERROR(maj_stat)) abort (); - if (output_token->length != 0) { - len = output_token->length; - - net_len = htonl(len); - - if (write (sock, &net_len, 4) != 4) - err (1, "write"); - if (write (sock, output_token->value, len) != len) - err (1, "write"); - - gss_release_buffer (&min_stat, - output_token); - } + if (output_token->length != 0) + write_token (sock, output_token); if (GSS_ERROR(maj_stat)) { if (context_hdl != GSS_C_NO_CONTEXT) gss_delete_sec_context (&min_stat, @@ -87,15 +61,44 @@ proto (int sock, const char *service) } } while(maj_stat & GSS_S_CONTINUE_NEEDED); - status = krb5_unparse_name (context, - client_name, - &name); - if (status) - errx (1, "krb5_unparse_name: %s", - krb5_get_err_text(context, status)); + maj_stat = gss_display_name (&min_stat, + client_name, + &name_token, + NULL); + if (GSS_ERROR(maj_stat)) + abort (); - printf ("User is `%s'\n", name); - free (name); + printf ("User is `%.*s'\n", name_token.length, name_token.value); + + /* gss_verify_mic */ + + read_token (sock, input_token); + read_token (sock, output_token); + + maj_stat = gss_verify_mic (&min_stat, + context_hdl, + input_token, + output_token, + NULL); + if (GSS_ERROR(maj_stat)) + abort (); + + printf ("gss_verify_mic: %.*s\n", input_token->length, input_token->value); + + /* gss_unwrap */ + + read_token (sock, input_token); + + maj_stat = gss_unwrap (&min_stat, + context_hdl, + input_token, + output_token, + NULL, + NULL); + if(GSS_ERROR(maj_stat)) + abort (); + + printf ("gss_unwrap: %.*s\n", output_token->length, output_token->value); return 0; }