xref: /illumos-gate/usr/src/lib/libgss/g_unseal.c (revision 694c35fa)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5503a2b89SPeter Shoults  * Common Development and Distribution License (the "License").
6503a2b89SPeter Shoults  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*5e01956fSGlenn Barry  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
267c478bd9Sstevel@tonic-gate  *  glue routine gss_unseal
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <mechglueP.h>
30*5e01956fSGlenn Barry #include "gssapiP_generic.h"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate OM_uint32
gss_unseal(minor_status,context_handle,input_message_buffer,output_message_buffer,conf_state,qop_state)337c478bd9Sstevel@tonic-gate gss_unseal(minor_status,
347c478bd9Sstevel@tonic-gate 		context_handle,
357c478bd9Sstevel@tonic-gate 		input_message_buffer,
367c478bd9Sstevel@tonic-gate 		output_message_buffer,
377c478bd9Sstevel@tonic-gate 		conf_state,
387c478bd9Sstevel@tonic-gate 		qop_state)
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate OM_uint32 *		minor_status;
417c478bd9Sstevel@tonic-gate gss_ctx_id_t		context_handle;
427c478bd9Sstevel@tonic-gate gss_buffer_t		input_message_buffer;
437c478bd9Sstevel@tonic-gate gss_buffer_t		output_message_buffer;
447c478bd9Sstevel@tonic-gate int *			conf_state;
457c478bd9Sstevel@tonic-gate int *			qop_state;
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate {
487c478bd9Sstevel@tonic-gate 	OM_uint32		status;
497c478bd9Sstevel@tonic-gate 	gss_union_ctx_id_t	ctx;
507c478bd9Sstevel@tonic-gate 	gss_mechanism		mech;
517c478bd9Sstevel@tonic-gate 
52503a2b89SPeter Shoults 	if (minor_status != NULL)
53503a2b89SPeter Shoults 		*minor_status = 0;
54503a2b89SPeter Shoults 
55503a2b89SPeter Shoults 	if (output_message_buffer != GSS_C_NO_BUFFER) {
56503a2b89SPeter Shoults 		output_message_buffer->length = 0;
57503a2b89SPeter Shoults 		output_message_buffer->value = NULL;
58503a2b89SPeter Shoults 	}
59503a2b89SPeter Shoults 
607c478bd9Sstevel@tonic-gate 	if (minor_status == NULL)
617c478bd9Sstevel@tonic-gate 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate 	if (context_handle == GSS_C_NO_CONTEXT)
647c478bd9Sstevel@tonic-gate 		return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_NO_CONTEXT);
657c478bd9Sstevel@tonic-gate 
66503a2b89SPeter Shoults 	if (input_message_buffer == GSS_C_NO_BUFFER ||
67503a2b89SPeter Shoults 	    GSS_EMPTY_BUFFER(input_message_buffer))
687c478bd9Sstevel@tonic-gate 		return (GSS_S_CALL_INACCESSIBLE_READ);
697c478bd9Sstevel@tonic-gate 
70503a2b89SPeter Shoults 	if (output_message_buffer == GSS_C_NO_BUFFER)
717c478bd9Sstevel@tonic-gate 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 	/*
747c478bd9Sstevel@tonic-gate 	 * select the approprate underlying mechanism routine and
757c478bd9Sstevel@tonic-gate 	 * call it.
767c478bd9Sstevel@tonic-gate 	 */
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate 	ctx = (gss_union_ctx_id_t) context_handle;
797c478bd9Sstevel@tonic-gate 	mech = __gss_get_mechanism(ctx->mech_type);
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	if (mech) {
82*5e01956fSGlenn Barry 		if (mech->gss_unseal) {
837c478bd9Sstevel@tonic-gate 			status = mech->gss_unseal(
847c478bd9Sstevel@tonic-gate 						mech->context,
857c478bd9Sstevel@tonic-gate 						minor_status,
867c478bd9Sstevel@tonic-gate 						ctx->internal_ctx_id,
877c478bd9Sstevel@tonic-gate 						input_message_buffer,
887c478bd9Sstevel@tonic-gate 						output_message_buffer,
897c478bd9Sstevel@tonic-gate 						conf_state,
907c478bd9Sstevel@tonic-gate 						qop_state);
91*5e01956fSGlenn Barry 			if (status != GSS_S_COMPLETE)
92*5e01956fSGlenn Barry 				map_error(minor_status, mech);
93*5e01956fSGlenn Barry 		} else
947c478bd9Sstevel@tonic-gate 			status = GSS_S_UNAVAILABLE;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 		return (status);
977c478bd9Sstevel@tonic-gate 	}
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate 	return (GSS_S_BAD_MECH);
1007c478bd9Sstevel@tonic-gate }
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate OM_uint32
gss_unwrap(minor_status,context_handle,input_message_buffer,output_message_buffer,conf_state,qop_state)1037c478bd9Sstevel@tonic-gate gss_unwrap(minor_status,
1047c478bd9Sstevel@tonic-gate 		context_handle,
1057c478bd9Sstevel@tonic-gate 		input_message_buffer,
1067c478bd9Sstevel@tonic-gate 		output_message_buffer,
1077c478bd9Sstevel@tonic-gate 		conf_state,
1087c478bd9Sstevel@tonic-gate 		qop_state)
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate OM_uint32 *		minor_status;
1117c478bd9Sstevel@tonic-gate const gss_ctx_id_t	context_handle;
1127c478bd9Sstevel@tonic-gate const gss_buffer_t	input_message_buffer;
1137c478bd9Sstevel@tonic-gate gss_buffer_t		output_message_buffer;
1147c478bd9Sstevel@tonic-gate int *			conf_state;
1157c478bd9Sstevel@tonic-gate gss_qop_t *		qop_state;
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate {
1187c478bd9Sstevel@tonic-gate 	return (gss_unseal(minor_status, (gss_ctx_id_t)context_handle,
1197c478bd9Sstevel@tonic-gate 			(gss_buffer_t)input_message_buffer,
1207c478bd9Sstevel@tonic-gate 			output_message_buffer, conf_state, (int *) qop_state));
1217c478bd9Sstevel@tonic-gate }
122