Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-5]: src/crypto/dist/heimdal/lib/gssapi Pull up revisions 1.3-1....



details:   https://anonhg.NetBSD.org/src/rev/d280dc72aafb
branches:  netbsd-1-5
changeset: 491175:d280dc72aafb
user:      he <he%NetBSD.org@localhost>
date:      Thu Apr 05 23:28:10 2001 +0000

description:
Pull up revisions 1.3-1.4 (via patch, requested by assar):
  Upgrade Heimdal to version 0.3e.

diffstat:

 crypto/dist/heimdal/lib/gssapi/init_sec_context.c |  374 +++++++++++++++------
 1 files changed, 265 insertions(+), 109 deletions(-)

diffs (truncated from 493 to 300 lines):

diff -r 62c9693d7ba8 -r d280dc72aafb crypto/dist/heimdal/lib/gssapi/init_sec_context.c
--- a/crypto/dist/heimdal/lib/gssapi/init_sec_context.c Thu Apr 05 23:27:47 2001 +0000
+++ b/crypto/dist/heimdal/lib/gssapi/init_sec_context.c Thu Apr 05 23:28:10 2001 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 1998, 1999 Kungliga Tekniska Högskolan
+ * Copyright (c) 1997 - 2001 Kungliga Tekniska Högskolan
  * (Royal Institute of Technology, Stockholm, Sweden). 
  * All rights reserved. 
  *
@@ -33,24 +33,163 @@
 
 #include "gssapi_locl.h"
 
-RCSID("$Id: init_sec_context.c,v 1.1.1.1.2.3 2001/01/25 16:06:21 jhawk Exp $");
+RCSID("$Id: init_sec_context.c,v 1.1.1.1.2.4 2001/04/05 23:28:10 he Exp $");
+
+/*
+ * copy the addresses from `input_chan_bindings' (if any) to
+ * the auth context `ac'
+ */
+
+static OM_uint32
+set_addresses (krb5_auth_context ac,
+              const gss_channel_bindings_t input_chan_bindings)               
+{
+    /* Port numbers are expected to be in application_data.value, 
+     * initator's port first */ 
+
+    krb5_address initiator_addr, acceptor_addr;
+    krb5_error_code kret;
+       
+    if (input_chan_bindings == GSS_C_NO_CHANNEL_BINDINGS
+       || input_chan_bindings->application_data.length !=
+       2 * sizeof(ac->local_port))
+       return 0;
+
+    memset(&initiator_addr, 0, sizeof(initiator_addr));
+    memset(&acceptor_addr, 0, sizeof(acceptor_addr));
+       
+    ac->local_port =
+       *(int16_t *) input_chan_bindings->application_data.value;
+       
+    ac->remote_port =
+       *((int16_t *) input_chan_bindings->application_data.value + 1);
+       
+    kret = gss_address_to_krb5addr(input_chan_bindings->acceptor_addrtype,
+                                  &input_chan_bindings->acceptor_address,
+                                  ac->remote_port,
+                                  &acceptor_addr);
+    if (kret)
+       return kret;
+           
+    kret = gss_address_to_krb5addr(input_chan_bindings->initiator_addrtype,
+                                  &input_chan_bindings->initiator_address,
+                                  ac->local_port,
+                                  &initiator_addr);
+    if (kret) {
+       krb5_free_address (gssapi_krb5_context, &acceptor_addr);
+       return kret;
+    }
+       
+    kret = krb5_auth_con_setaddrs(gssapi_krb5_context,
+                                 ac,
+                                 &initiator_addr,  /* local address */
+                                 &acceptor_addr);  /* remote address */
+       
+    krb5_free_address (gssapi_krb5_context, &initiator_addr);
+    krb5_free_address (gssapi_krb5_context, &acceptor_addr);
+       
+#if 0
+    free(input_chan_bindings->application_data.value);
+    input_chan_bindings->application_data.value = NULL;
+    input_chan_bindings->application_data.length = 0;
+#endif
+
+    return kret;
+}
+
+/*
+ * handle delegated creds in init-sec-context
+ */
+
+static void
+do_delegation (krb5_auth_context ac,
+              krb5_ccache ccache,
+              krb5_creds *cred,
+              const gss_name_t target_name,
+              krb5_data *fwd_data,
+              int *flags)
+{
+    krb5_creds creds;
+    krb5_kdc_flags fwd_flags;
+    krb5_keyblock *subkey;
+    krb5_error_code kret;
+       
+    memset (&creds, 0, sizeof(creds));
+    krb5_data_zero (fwd_data);
+       
+    kret = krb5_generate_subkey (gssapi_krb5_context, &cred->session, &subkey);
+    if (kret)
+       goto out;
+       
+    kret = krb5_auth_con_setlocalsubkey(gssapi_krb5_context, ac, subkey);
+    krb5_free_keyblock (gssapi_krb5_context, subkey);
+    if (kret)
+       goto out;
+       
+    kret = krb5_cc_get_principal(gssapi_krb5_context, ccache, &creds.client);
+    if (kret) 
+       goto out;
+       
+    kret = krb5_build_principal(gssapi_krb5_context,
+                               &creds.server,
+                               strlen(creds.client->realm),
+                               creds.client->realm,
+                               KRB5_TGS_NAME,
+                               creds.client->realm,
+                               NULL);
+    if (kret)
+       goto out; 
+       
+    creds.times.endtime = 0;
+       
+    fwd_flags.i = 0;
+    fwd_flags.b.forwarded = 1;
+    fwd_flags.b.forwardable = 1;
+       
+    if ( /*target_name->name.name_type != KRB5_NT_SRV_HST ||*/
+       target_name->name.name_string.len < 2) 
+       goto out;
+       
+    kret = krb5_get_forwarded_creds(gssapi_krb5_context,
+                                   ac,
+                                   ccache,
+                                   fwd_flags.i,
+                                   target_name->name.name_string.val[1],
+                                   &creds,
+                                   fwd_data);
+       
+ out:
+    if (kret)
+       *flags &= ~GSS_C_DELEG_FLAG;
+    else
+       *flags |= GSS_C_DELEG_FLAG;
+       
+    if (creds.client)
+       krb5_free_principal(gssapi_krb5_context, creds.client);
+    if (creds.server)
+       krb5_free_principal(gssapi_krb5_context, creds.server);
+}
+
+/*
+ * first stage of init-sec-context
+ */
 
 static OM_uint32
 init_auth
-           (OM_uint32 * minor_status,
-            const gss_cred_id_t initiator_cred_handle,
-            gss_ctx_id_t * context_handle,
-            const gss_name_t target_name,
-            const gss_OID mech_type,
-            OM_uint32 req_flags,
-            OM_uint32 time_req,
-            const gss_channel_bindings_t input_chan_bindings,
-            const gss_buffer_t input_token,
-            gss_OID * actual_mech_type,
-            gss_buffer_t output_token,
-            OM_uint32 * ret_flags,
-            OM_uint32 * time_rec
-           )
+(OM_uint32 * minor_status,
+ const gss_cred_id_t initiator_cred_handle,
+ gss_ctx_id_t * context_handle,
+ const gss_name_t target_name,
+ const gss_OID mech_type,
+ OM_uint32 req_flags,
+ OM_uint32 time_req,
+ const gss_channel_bindings_t input_chan_bindings,
+ const gss_buffer_t input_token,
+ gss_OID * actual_mech_type,
+ gss_buffer_t output_token,
+ OM_uint32 * ret_flags,
+ OM_uint32 * time_rec
+    )
 {
     OM_uint32 ret = GSS_S_FAILURE;
     krb5_error_code kret;
@@ -63,12 +202,13 @@
     krb5_data authenticator;
     Checksum cksum;
     krb5_enctype enctype;
+    krb5_data fwd_data;
 
     output_token->length = 0;
     output_token->value  = NULL;
 
-    outbuf.length = 0;
-    outbuf.data   = NULL;
+    krb5_data_zero(&outbuf);
+    krb5_data_zero(&fwd_data);
 
     *minor_status = 0;
 
@@ -78,12 +218,12 @@
        return GSS_S_FAILURE;
     }
 
-    (*context_handle)->auth_context =  NULL;
-    (*context_handle)->source = NULL;
-    (*context_handle)->target = NULL;
-    (*context_handle)->flags = 0;
-    (*context_handle)->more_flags = 0;
-    (*context_handle)->ticket = NULL;
+    (*context_handle)->auth_context = NULL;
+    (*context_handle)->source       = NULL;
+    (*context_handle)->target       = NULL;
+    (*context_handle)->flags        = 0;
+    (*context_handle)->more_flags   = 0;
+    (*context_handle)->ticket       = NULL;
 
     kret = krb5_auth_con_init (gssapi_krb5_context,
                               &(*context_handle)->auth_context);
@@ -93,6 +233,14 @@
        goto failure;
     }
 
+    kret = set_addresses ((*context_handle)->auth_context,
+                         input_chan_bindings);
+    if (kret) {
+       *minor_status = kret;
+       ret = GSS_S_BAD_BINDINGS;
+       goto failure;
+    }
+       
     {
        int32_t tmp;
 
@@ -108,33 +256,9 @@
     if (actual_mech_type)
        *actual_mech_type = GSS_KRB5_MECHANISM;
 
-    flags = 0;
-    ap_options = 0;
-    if (req_flags & GSS_C_DELEG_FLAG)
-       ;                               /* XXX */
-    if (req_flags & GSS_C_MUTUAL_FLAG) {
-       flags |= GSS_C_MUTUAL_FLAG;
-       ap_options |= AP_OPTS_MUTUAL_REQUIRED;
-    }
-    if (req_flags & GSS_C_REPLAY_FLAG)
-       ;                               /* XXX */
-    if (req_flags & GSS_C_SEQUENCE_FLAG)
-       ;                               /* XXX */
-    if (req_flags & GSS_C_ANON_FLAG)
-       ;                               /* XXX */
-    flags |= GSS_C_CONF_FLAG;
-    flags |= GSS_C_INTEG_FLAG;
-    flags |= GSS_C_SEQUENCE_FLAG;
-    flags |= GSS_C_TRANS_FLAG;
-
-    if (ret_flags)
-       *ret_flags = flags;
-    (*context_handle)->flags = flags;
-    (*context_handle)->more_flags = LOCAL;
-
     if (initiator_cred_handle == GSS_C_NO_CREDENTIAL) {
-        kret = krb5_cc_default (gssapi_krb5_context, &ccache);
-        if (kret) {
+       kret = krb5_cc_default (gssapi_krb5_context, &ccache);
+       if (kret) {
            *minor_status = kret;
            ret = GSS_S_FAILURE;
            goto failure;
@@ -163,8 +287,14 @@
     memset(&this_cred, 0, sizeof(this_cred));
     this_cred.client          = (*context_handle)->source;
     this_cred.server          = (*context_handle)->target;
-    this_cred.times.endtime   = 0;
-    this_cred.session.keytype = ETYPE_DES_CBC_CRC;
+    if (time_req) {
+       krb5_timestamp ts;
+
+       krb5_timeofday (gssapi_krb5_context, &ts);
+       this_cred.times.endtime = ts + time_req;
+    } else
+       this_cred.times.endtime   = 0;
+    this_cred.session.keytype = 0;
   
     kret = krb5_get_credentials (gssapi_krb5_context,
                                 KRB5_TC_MATCH_KEYTYPE,
@@ -182,9 +312,38 @@
                         (*context_handle)->auth_context, 
                         &cred->session);
   
+    flags = 0;
+    ap_options = 0;
+    if (req_flags & GSS_C_DELEG_FLAG)
+       do_delegation ((*context_handle)->auth_context,



Home | Main Index | Thread Index | Old Index