Release 0.0r
[heimdal.git] / lib / gssapi / krb5 / encapsulate.c
blob77c69a271cb1f5a31ec1af7b3c8db692ebfddc40
1 /*
2 * Copyright (c) 1997 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. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Kungliga Tekniska
20 * Högskolan and its contributors.
22 * 4. Neither the name of the Institute nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
39 #include "gssapi_locl.h"
41 RCSID("$Id$");
43 void
44 gssapi_krb5_encap_length (size_t data_len,
45 size_t *len,
46 size_t *total_len)
48 size_t len_len;
50 *len = 1 + 1 + GSS_KRB5_MECHANISM->length + 2 + data_len;
52 len_len = length_len(*len);
54 *total_len = 1 + len_len + *len;
57 u_char *
58 gssapi_krb5_make_header (u_char *p,
59 size_t len,
60 u_char *type)
62 int e;
63 size_t len_len, foo;
65 *p++ = 0x60;
66 len_len = length_len(len);
67 e = der_put_length (p + len_len - 1, len_len, len, &foo);
68 if(e || foo != len_len)
69 abort ();
70 p += len_len;
71 *p++ = 0x06;
72 *p++ = GSS_KRB5_MECHANISM->length;
73 memcpy (p, GSS_KRB5_MECHANISM->elements, GSS_KRB5_MECHANISM->length);
74 p += GSS_KRB5_MECHANISM->length;
75 memcpy (p, type, 2);
76 p += 2;
77 return p;
81 * Give it a krb5_data and it will encapsulate with extra GSS-API wrappings.
84 OM_uint32
85 gssapi_krb5_encapsulate(
86 krb5_data *in_data,
87 gss_buffer_t output_token,
88 u_char *type
91 size_t len, outer_len;
92 u_char *p;
94 gssapi_krb5_encap_length (in_data->length, &len, &outer_len);
96 output_token->length = outer_len;
97 output_token->value = malloc (outer_len);
98 if (output_token->value == NULL)
99 return GSS_S_FAILURE;
101 p = gssapi_krb5_make_header (output_token->value, len, type);
102 memcpy (p, in_data->data, in_data->length);
103 krb5_data_free (in_data);
104 return GSS_S_COMPLETE;