xref: /illumos-gate/usr/src/lib/libgss/g_seal.c (revision d8d810637042c2a73a269f125dee75e8ed1421d1)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  *  glue routine for gss_seal
28  */
29 
30 #include <mechglueP.h>
31 
32 static OM_uint32
33 val_seal_args(
34 	OM_uint32 *minor_status,
35 	gss_ctx_id_t context_handle,
36 	gss_buffer_t input_message_buffer,
37 	gss_buffer_t output_message_buffer)
38 {
39 
40 	/* Initialize outputs. */
41 
42 	if (minor_status != NULL)
43 		*minor_status = 0;
44 
45 	if (output_message_buffer != GSS_C_NO_BUFFER) {
46 		output_message_buffer->length = 0;
47 		output_message_buffer->value = NULL;
48 	}
49 
50 	/* Validate arguments. */
51 
52 	if (minor_status == NULL)
53 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
54 
55 	if (context_handle == GSS_C_NO_CONTEXT)
56 		return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_NO_CONTEXT);
57 
58 	if (input_message_buffer == GSS_C_NO_BUFFER)
59 		return (GSS_S_CALL_INACCESSIBLE_READ);
60 
61 	if (output_message_buffer == GSS_C_NO_BUFFER)
62 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
63 
64 	return (GSS_S_COMPLETE);
65 }
66 
67 /*ARGSUSED*/
68 OM_uint32
69 gss_seal(minor_status,
70 		context_handle,
71 		conf_req_flag,
72 		qop_req,
73 		input_message_buffer,
74 		conf_state,
75 		output_message_buffer)
76 
77 OM_uint32 *			minor_status;
78 gss_ctx_id_t			context_handle;
79 int				conf_req_flag;
80 int				qop_req;
81 gss_buffer_t			input_message_buffer;
82 int *				conf_state;
83 gss_buffer_t			output_message_buffer;
84 {
85 /* EXPORT DELETE START */
86 
87 	OM_uint32		status;
88 	gss_union_ctx_id_t	ctx;
89 	gss_mechanism		mech;
90 
91 	status = val_seal_args(minor_status,
92 			context_handle,
93 			input_message_buffer,
94 			output_message_buffer);
95 	if (status != GSS_S_COMPLETE)
96 		return (status);
97 
98 	/*
99 	 * select the approprate underlying mechanism routine and
100 	 * call it.
101 	 */
102 
103 	ctx = (gss_union_ctx_id_t) context_handle;
104 	mech = __gss_get_mechanism(ctx->mech_type);
105 
106 	if (mech) {
107 		if (mech->gss_seal)
108 			status = mech->gss_seal(
109 						mech->context,
110 						minor_status,
111 						ctx->internal_ctx_id,
112 						conf_req_flag,
113 						qop_req,
114 						input_message_buffer,
115 						conf_state,
116 						output_message_buffer);
117 		else
118 			status = GSS_S_UNAVAILABLE;
119 
120 		return (status);
121 	}
122 /* EXPORT DELETE END */
123 
124 	return (GSS_S_BAD_MECH);
125 }
126 
127 OM_uint32
128 gss_wrap(minor_status,
129 		context_handle,
130 		conf_req_flag,
131 		qop_req,
132 		input_message_buffer,
133 		conf_state,
134 		output_message_buffer)
135 
136 OM_uint32 *			minor_status;
137 const gss_ctx_id_t		context_handle;
138 int				conf_req_flag;
139 gss_qop_t			qop_req;
140 const gss_buffer_t		input_message_buffer;
141 int *				conf_state;
142 gss_buffer_t			output_message_buffer;
143 
144 {
145 	return gss_seal(minor_status, (gss_ctx_id_t)context_handle,
146 			conf_req_flag, (int) qop_req,
147 			(gss_buffer_t)input_message_buffer, conf_state,
148 			output_message_buffer);
149 }
150 
151 /*
152  * New for V2
153  */
154 OM_uint32
155 gss_wrap_size_limit(minor_status, context_handle, conf_req_flag,
156 				qop_req, req_output_size, max_input_size)
157 	OM_uint32		*minor_status;
158 	const gss_ctx_id_t	context_handle;
159 	int			conf_req_flag;
160 	gss_qop_t		qop_req;
161 	OM_uint32		req_output_size;
162 	OM_uint32		*max_input_size;
163 {
164 	gss_union_ctx_id_t	ctx;
165 	gss_mechanism		mech;
166 
167 	if (minor_status == NULL)
168 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
169 	*minor_status = 0;
170 
171 	if (context_handle == GSS_C_NO_CONTEXT)
172 		return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_NO_CONTEXT);
173 
174 	if (max_input_size == NULL)
175 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
176 
177 	/*
178 	 * select the approprate underlying mechanism routine and
179 	 * call it.
180 	 */
181 
182 	ctx = (gss_union_ctx_id_t) context_handle;
183 	mech = __gss_get_mechanism(ctx->mech_type);
184 
185 	if (!mech)
186 		return (GSS_S_BAD_MECH);
187 
188 	if (!mech->gss_wrap_size_limit)
189 		return (GSS_S_UNAVAILABLE);
190 
191 	return (mech->gss_wrap_size_limit(mech->context, minor_status,
192 				ctx->internal_ctx_id, conf_req_flag, qop_req,
193 				req_output_size, max_input_size));
194 }
195