xref: /illumos-gate/usr/src/uts/common/gssapi/mechs/krb5/mech/sign.c (revision 355b4669e025ff377602b6fc7caaf30dbc218371)
1 /*
2  * Copyright 2001-2002 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #pragma ident	"%Z%%M%	%I%	%E% SMI"
7 
8 /*
9  * Copyright 1993 by OpenVision Technologies, Inc.
10  *
11  * Permission to use, copy, modify, distribute, and sell this software
12  * and its documentation for any purpose is hereby granted without fee,
13  * provided that the above copyright notice appears in all copies and
14  * that both that copyright notice and this permission notice appear in
15  * supporting documentation, and that the name of OpenVision not be used
16  * in advertising or publicity pertaining to distribution of the software
17  * without specific, written prior permission. OpenVision makes no
18  * representations about the suitability of this software for any
19  * purpose.  It is provided "as is" without express or implied warranty.
20  *
21  * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
22  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
23  * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
24  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
25  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
26  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
27  * PERFORMANCE OF THIS SOFTWARE.
28  */
29 
30 #include <gssapiP_krb5.h>
31 
32 /*
33  * $Id: sign.c,v 1.11 1996/07/22 20:34:35 marc Exp $
34  */
35 /*ARGSUSED*/
36 
37 OM_uint32
38 krb5_gss_sign(ctx, minor_status, context_handle,
39 	      qop_req, message_buffer,
40 	      message_token
41 #ifdef	 _KERNEL
42 		, gssd_ctx_verifier
43 #endif
44 	)
45      void      *ctx;
46      OM_uint32 *minor_status;
47      gss_ctx_id_t context_handle;
48      int qop_req;
49      gss_buffer_t message_buffer;
50      gss_buffer_t message_token;
51 #ifdef	 _KERNEL
52 	OM_uint32 gssd_ctx_verifier;
53 #endif
54 {
55    krb5_context context;
56    OM_uint32	status;
57 
58    /* Solaris Kerberos:  for MT safety, we avoid the use of a default
59     * context via kg_get_context() */
60 #if 0
61    if (GSS_ERROR(kg_get_context(minor_status, &context)))
62       return(GSS_S_FAILURE);
63 #endif
64 
65    mutex_lock(&krb5_mutex);
66 
67    context = ctx;
68    status = kg_seal(context, minor_status, context_handle, 0,
69 		  qop_req, message_buffer, NULL,
70 		  message_token, KG_TOK_SIGN_MSG);
71    mutex_unlock(&krb5_mutex);
72    return(status);
73 }
74 
75 /* V2 interface */
76 OM_uint32
77 krb5_gss_get_mic(ctx, minor_status, context_handle, qop_req,
78 		 message_buffer, message_token)
79     void                *ctx;
80     OM_uint32		*minor_status;
81     gss_ctx_id_t	context_handle;
82     gss_qop_t		qop_req;
83     gss_buffer_t	message_buffer;
84     gss_buffer_t	message_token;
85 {
86    krb5_context context;
87    OM_uint32	status;
88 
89    /* Solaris Kerberos:  for MT safety, we avoid the use of a default
90     * context via kg_get_context() */
91 #if 0
92    if (GSS_ERROR(kg_get_context(minor_status, &context)))
93       return(GSS_S_FAILURE);
94 #endif
95 
96    mutex_lock(&krb5_mutex);
97 
98    context = ctx;
99 
100    status = kg_seal(context, minor_status, context_handle, 0,
101 		   (int) qop_req, message_buffer, NULL,
102 		   message_token, KG_TOK_MIC_MSG);
103    mutex_unlock(&krb5_mutex);
104    return(status);
105 }
106