Release 0.3c
[heimdal.git] / lib / gssapi / krb5 / export_sec_context.c
blob69b00a6658347ad44b6f5560a3823cc6c01dbd6a
1 /*
2 * Copyright (c) 1999 - 2000 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 #include "gssapi_locl.h"
36 RCSID("$Id$");
38 OM_uint32
39 gss_export_sec_context (
40 OM_uint32 * minor_status,
41 gss_ctx_id_t * context_handle,
42 gss_buffer_t interprocess_token
45 krb5_storage *sp;
46 krb5_auth_context ac;
47 int ret;
48 krb5_data data;
49 gss_buffer_desc buffer;
50 int flags;
52 gssapi_krb5_init ();
53 if (!((*context_handle)->flags & GSS_C_TRANS_FLAG))
54 return GSS_S_UNAVAILABLE;
56 sp = krb5_storage_emem ();
57 if (sp == NULL) {
58 *minor_status = ENOMEM;
59 return GSS_S_FAILURE;
61 ac = (*context_handle)->auth_context;
63 /* flagging included fields */
65 flags = 0;
66 if (ac->local_address)
67 flags |= SC_LOCAL_ADDRESS;
68 if (ac->remote_address)
69 flags |= SC_REMOTE_ADDRESS;
70 if (ac->keyblock)
71 flags |= SC_KEYBLOCK;
72 if (ac->local_subkey)
73 flags |= SC_LOCAL_SUBKEY;
74 if (ac->remote_subkey)
75 flags |= SC_REMOTE_SUBKEY;
77 krb5_store_int32 (sp, flags);
79 /* marshall auth context */
81 krb5_store_int32 (sp, ac->flags);
82 if (ac->local_address)
83 krb5_store_address (sp, *ac->local_address);
84 if (ac->remote_address)
85 krb5_store_address (sp, *ac->remote_address);
86 krb5_store_int16 (sp, ac->local_port);
87 krb5_store_int16 (sp, ac->remote_port);
88 if (ac->keyblock)
89 krb5_store_keyblock (sp, *ac->keyblock);
90 if (ac->local_subkey)
91 krb5_store_keyblock (sp, *ac->local_subkey);
92 if (ac->remote_subkey)
93 krb5_store_keyblock (sp, *ac->remote_subkey);
94 krb5_store_int32 (sp, ac->local_seqnumber);
95 krb5_store_int32 (sp, ac->remote_seqnumber);
97 #if 0
99 size_t sz;
100 unsigned char auth_buf[1024];
102 ret = encode_Authenticator (auth_buf, sizeof(auth_buf),
103 ac->authenticator, &sz);
104 if (ret) {
105 krb5_storage_free (sp);
106 *minor_status = ret;
107 return GSS_S_FAILURE;
109 data.data = auth_buf;
110 data.length = sz;
111 krb5_store_data (sp, data);
113 #endif
114 krb5_store_int32 (sp, ac->keytype);
115 krb5_store_int32 (sp, ac->cksumtype);
117 /* names */
119 gss_export_name (minor_status, (*context_handle)->source, &buffer);
120 data.data = buffer.value;
121 data.length = buffer.length;
122 krb5_store_data (sp, data);
124 gss_export_name (minor_status, (*context_handle)->target, &buffer);
125 data.data = buffer.value;
126 data.length = buffer.length;
127 krb5_store_data (sp, data);
129 krb5_store_int32 (sp, (*context_handle)->flags);
130 krb5_store_int32 (sp, (*context_handle)->more_flags);
132 ret = krb5_storage_to_data (sp, &data);
133 krb5_storage_free (sp);
134 if (ret) {
135 *minor_status = ret;
136 return GSS_S_FAILURE;
138 interprocess_token->length = data.length;
139 interprocess_token->value = data.data;
140 ret = gss_delete_sec_context (minor_status, context_handle,
141 GSS_C_NO_BUFFER);
142 if (ret != GSS_S_COMPLETE)
143 gss_release_buffer (NULL, interprocess_token);
144 return ret;