xref: /illumos-gate/usr/src/lib/libgss/g_sign.c (revision aedf2b3bb56b025fcaf87b49ec6c8aeea07f16d7)
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 gss_sign
28  */
29 
30 #include <mechglueP.h>
31 
32 static OM_uint32
33 val_sign_args(
34 	OM_uint32 *minor_status,
35 	gss_ctx_id_t context_handle,
36 	gss_buffer_t message_buffer,
37 	gss_buffer_t msg_token)
38 {
39 
40 	/* Initialize outputs. */
41 
42 	if (minor_status != NULL)
43 		*minor_status = 0;
44 
45 	if (msg_token != GSS_C_NO_BUFFER) {
46 		msg_token->value = NULL;
47 		msg_token->length = 0;
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 (message_buffer == GSS_C_NO_BUFFER)
59 		return (GSS_S_CALL_INACCESSIBLE_READ);
60 
61 	if (msg_token == GSS_C_NO_BUFFER)
62 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
63 
64 	return (GSS_S_COMPLETE);
65 }
66 
67 OM_uint32
68 gss_sign(minor_status,
69 	context_handle,
70 	qop_req,
71 	message_buffer,
72 	msg_token)
73 
74 OM_uint32 *		minor_status;
75 gss_ctx_id_t		context_handle;
76 int			qop_req;
77 gss_buffer_t		message_buffer;
78 gss_buffer_t		msg_token;
79 
80 {
81 	OM_uint32		status;
82 	gss_union_ctx_id_t	ctx;
83 	gss_mechanism		mech;
84 
85 	status = val_sign_args(minor_status, context_handle,
86 			message_buffer, msg_token);
87 	if (status != GSS_S_COMPLETE)
88 		return (status);
89 
90 	/*
91 	 * select the approprate underlying mechanism routine and
92 	 * call it.
93 	 */
94 
95 	ctx = (gss_union_ctx_id_t) context_handle;
96 	mech = __gss_get_mechanism(ctx->mech_type);
97 
98 	if (mech) {
99 		if (mech->gss_sign)
100 			status = mech->gss_sign(
101 						mech->context,
102 						minor_status,
103 						ctx->internal_ctx_id,
104 						qop_req,
105 						message_buffer,
106 						msg_token);
107 		else
108 			status = GSS_S_UNAVAILABLE;
109 
110 		return (status);
111 	}
112 
113 	return (GSS_S_BAD_MECH);
114 }
115 
116 OM_uint32
117 gss_get_mic(minor_status,
118 		context_handle,
119 		qop_req,
120 		message_buffer,
121 		msg_token)
122 
123 OM_uint32 *		minor_status;
124 const gss_ctx_id_t	context_handle;
125 gss_qop_t		qop_req;
126 const gss_buffer_t	message_buffer;
127 gss_buffer_t		msg_token;
128 
129 {
130 	return (gss_sign(minor_status, (gss_ctx_id_t)context_handle,
131 		(int) qop_req, (gss_buffer_t)message_buffer, msg_token));
132 }
133