xref: /illumos-gate/usr/src/lib/libgss/g_sign.c (revision 69a119caa6570c7077699161b7c28b6ee9f8b0f4)
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 (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 /*
26  *  glue routine gss_sign
27  */
28 
29 #include <mechglueP.h>
30 #include "gssapiP_generic.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 			if (status != GSS_S_COMPLETE)
108 				map_error(minor_status, mech);
109 		} else
110 			status = GSS_S_UNAVAILABLE;
111 
112 		return (status);
113 	}
114 
115 	return (GSS_S_BAD_MECH);
116 }
117 
118 OM_uint32
119 gss_get_mic(minor_status,
120 		context_handle,
121 		qop_req,
122 		message_buffer,
123 		msg_token)
124 
125 OM_uint32 *		minor_status;
126 const gss_ctx_id_t	context_handle;
127 gss_qop_t		qop_req;
128 const gss_buffer_t	message_buffer;
129 gss_buffer_t		msg_token;
130 
131 {
132 	return (gss_sign(minor_status, (gss_ctx_id_t)context_handle,
133 		(int) qop_req, (gss_buffer_t)message_buffer, msg_token));
134 }
135