17c478bd9Sstevel@tonic-gate /*
2*ab9b2e15Sgtb * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
37c478bd9Sstevel@tonic-gate * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate */
57c478bd9Sstevel@tonic-gate
67c478bd9Sstevel@tonic-gate /*
77c478bd9Sstevel@tonic-gate * Copyright 2000 by the Massachusetts Institute of Technology.
87c478bd9Sstevel@tonic-gate * All Rights Reserved.
97c478bd9Sstevel@tonic-gate *
107c478bd9Sstevel@tonic-gate * Export of this software from the United States of America may
117c478bd9Sstevel@tonic-gate * require a specific license from the United States Government.
127c478bd9Sstevel@tonic-gate * It is the responsibility of any person or organization contemplating
137c478bd9Sstevel@tonic-gate * export to obtain such a license before exporting.
147c478bd9Sstevel@tonic-gate *
157c478bd9Sstevel@tonic-gate * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
167c478bd9Sstevel@tonic-gate * distribute this software and its documentation for any purpose and
177c478bd9Sstevel@tonic-gate * without fee is hereby granted, provided that the above copyright
187c478bd9Sstevel@tonic-gate * notice appear in all copies and that both that copyright notice and
197c478bd9Sstevel@tonic-gate * this permission notice appear in supporting documentation, and that
207c478bd9Sstevel@tonic-gate * the name of M.I.T. not be used in advertising or publicity pertaining
217c478bd9Sstevel@tonic-gate * to distribution of the software without specific, written prior
227c478bd9Sstevel@tonic-gate * permission. Furthermore if you modify this software you must label
237c478bd9Sstevel@tonic-gate * your software as modified software and not distribute it in such a
247c478bd9Sstevel@tonic-gate * fashion that it might be confused with the original M.I.T. software.
257c478bd9Sstevel@tonic-gate * M.I.T. makes no representations about the suitability of
267c478bd9Sstevel@tonic-gate * this software for any purpose. It is provided "as is" without express
277c478bd9Sstevel@tonic-gate * or implied warranty.
287c478bd9Sstevel@tonic-gate *
297c478bd9Sstevel@tonic-gate */
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate * Copyright 1993 by OpenVision Technologies, Inc.
327c478bd9Sstevel@tonic-gate *
337c478bd9Sstevel@tonic-gate * Permission to use, copy, modify, distribute, and sell this software
347c478bd9Sstevel@tonic-gate * and its documentation for any purpose is hereby granted without fee,
357c478bd9Sstevel@tonic-gate * provided that the above copyright notice appears in all copies and
367c478bd9Sstevel@tonic-gate * that both that copyright notice and this permission notice appear in
377c478bd9Sstevel@tonic-gate * supporting documentation, and that the name of OpenVision not be used
387c478bd9Sstevel@tonic-gate * in advertising or publicity pertaining to distribution of the software
397c478bd9Sstevel@tonic-gate * without specific, written prior permission. OpenVision makes no
407c478bd9Sstevel@tonic-gate * representations about the suitability of this software for any
417c478bd9Sstevel@tonic-gate * purpose. It is provided "as is" without express or implied warranty.
427c478bd9Sstevel@tonic-gate *
437c478bd9Sstevel@tonic-gate * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
447c478bd9Sstevel@tonic-gate * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
457c478bd9Sstevel@tonic-gate * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
467c478bd9Sstevel@tonic-gate * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
477c478bd9Sstevel@tonic-gate * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
487c478bd9Sstevel@tonic-gate * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
497c478bd9Sstevel@tonic-gate * PERFORMANCE OF THIS SOFTWARE.
507c478bd9Sstevel@tonic-gate */
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate /*
537c478bd9Sstevel@tonic-gate * Copyright (C) 1998 by the FundsXpress, INC.
547c478bd9Sstevel@tonic-gate *
557c478bd9Sstevel@tonic-gate * All rights reserved.
567c478bd9Sstevel@tonic-gate *
577c478bd9Sstevel@tonic-gate * Export of this software from the United States of America may require
587c478bd9Sstevel@tonic-gate * a specific license from the United States Government. It is the
597c478bd9Sstevel@tonic-gate * responsibility of any person or organization contemplating export to
607c478bd9Sstevel@tonic-gate * obtain such a license before exporting.
617c478bd9Sstevel@tonic-gate *
627c478bd9Sstevel@tonic-gate * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
637c478bd9Sstevel@tonic-gate * distribute this software and its documentation for any purpose and
647c478bd9Sstevel@tonic-gate * without fee is hereby granted, provided that the above copyright
657c478bd9Sstevel@tonic-gate * notice appear in all copies and that both that copyright notice and
667c478bd9Sstevel@tonic-gate * this permission notice appear in supporting documentation, and that
677c478bd9Sstevel@tonic-gate * the name of FundsXpress. not be used in advertising or publicity pertaining
687c478bd9Sstevel@tonic-gate * to distribution of the software without specific, written prior
697c478bd9Sstevel@tonic-gate * permission. FundsXpress makes no representations about the suitability of
707c478bd9Sstevel@tonic-gate * this software for any purpose. It is provided "as is" without express
717c478bd9Sstevel@tonic-gate * or implied warranty.
727c478bd9Sstevel@tonic-gate *
737c478bd9Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
747c478bd9Sstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
757c478bd9Sstevel@tonic-gate * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
767c478bd9Sstevel@tonic-gate */
777c478bd9Sstevel@tonic-gate
78*ab9b2e15Sgtb #include "gssapiP_krb5.h"
797c478bd9Sstevel@tonic-gate
80*ab9b2e15Sgtb size_t KRB5_CALLCONV krb5_encrypt_size(size_t, krb5_enctype);
81*ab9b2e15Sgtb
82*ab9b2e15Sgtb /* SUNW15resync - XXX find new home for this func */
83*ab9b2e15Sgtb #ifdef _KERNEL
84*ab9b2e15Sgtb size_t KRB5_CALLCONV
krb5_encrypt_size(size_t length,krb5_enctype crypto)85*ab9b2e15Sgtb krb5_encrypt_size(size_t length, krb5_enctype crypto)
86*ab9b2e15Sgtb {
87*ab9b2e15Sgtb size_t ret;
88*ab9b2e15Sgtb
89*ab9b2e15Sgtb if (krb5_c_encrypt_length(/* XXX */ 0, crypto, length, &ret))
90*ab9b2e15Sgtb /*LINTED*/
91*ab9b2e15Sgtb return(-1); /* XXX */
92*ab9b2e15Sgtb
93*ab9b2e15Sgtb return(ret);
94*ab9b2e15Sgtb }
95*ab9b2e15Sgtb #endif
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate /* V2 interface */
987c478bd9Sstevel@tonic-gate OM_uint32
krb5_gss_wrap_size_limit(minor_status,context_handle,conf_req_flag,qop_req,req_output_size,max_input_size)99*ab9b2e15Sgtb krb5_gss_wrap_size_limit(minor_status, context_handle, conf_req_flag,
1007c478bd9Sstevel@tonic-gate qop_req, req_output_size, max_input_size)
1017c478bd9Sstevel@tonic-gate OM_uint32 *minor_status;
1027c478bd9Sstevel@tonic-gate gss_ctx_id_t context_handle;
1037c478bd9Sstevel@tonic-gate int conf_req_flag;
1047c478bd9Sstevel@tonic-gate gss_qop_t qop_req;
1057c478bd9Sstevel@tonic-gate OM_uint32 req_output_size;
1067c478bd9Sstevel@tonic-gate OM_uint32 *max_input_size;
1077c478bd9Sstevel@tonic-gate {
1087c478bd9Sstevel@tonic-gate krb5_gss_ctx_id_rec *ctx;
109*ab9b2e15Sgtb OM_uint32 data_size, conflen;
1107c478bd9Sstevel@tonic-gate OM_uint32 ohlen;
111*ab9b2e15Sgtb int overhead;
1127c478bd9Sstevel@tonic-gate
113*ab9b2e15Sgtb /* Solaris Kerb - check to make sure we aren't writing to a NULL pointer */
1147c478bd9Sstevel@tonic-gate if (!max_input_size)
1157c478bd9Sstevel@tonic-gate return(GSS_S_CALL_INACCESSIBLE_WRITE);
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate /* only default qop is allowed */
118*ab9b2e15Sgtb /*
119*ab9b2e15Sgtb * SUNW15resync
120*ab9b2e15Sgtb * mit 1.2-6: if (qop_req != GSS_C_QOP_DEFAULT) {
121*ab9b2e15Sgtb * Go with Solaris version here, though not sure which is
122*ab9b2e15Sgtb * correct and RFC 2743 does not make it clear.
123*ab9b2e15Sgtb */
1247c478bd9Sstevel@tonic-gate if ((qop_req & GSS_KRB5_CONF_C_QOP_MASK) != GSS_C_QOP_DEFAULT) {
1257c478bd9Sstevel@tonic-gate *minor_status = (OM_uint32) G_UNKNOWN_QOP;
126*ab9b2e15Sgtb /* SUNW15resync - RFC 2743 is clear here but
127*ab9b2e15Sgtb this is still GSS_S_FAILURE in MIT */
1287c478bd9Sstevel@tonic-gate return(GSS_S_BAD_QOP);
1297c478bd9Sstevel@tonic-gate }
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate /* validate the context handle */
1327c478bd9Sstevel@tonic-gate if (! kg_validate_ctx_id(context_handle)) {
1337c478bd9Sstevel@tonic-gate *minor_status = (OM_uint32) G_VALIDATE_FAILED;
1347c478bd9Sstevel@tonic-gate return(GSS_S_NO_CONTEXT);
1357c478bd9Sstevel@tonic-gate }
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate ctx = (krb5_gss_ctx_id_rec *) context_handle;
1387c478bd9Sstevel@tonic-gate if (! ctx->established) {
1397c478bd9Sstevel@tonic-gate *minor_status = KG_CTX_INCOMPLETE;
1407c478bd9Sstevel@tonic-gate return(GSS_S_NO_CONTEXT);
1417c478bd9Sstevel@tonic-gate }
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate if (ctx->proto == 1) {
1447c478bd9Sstevel@tonic-gate /* No pseudo-ASN.1 wrapper overhead, so no sequence length and
1457c478bd9Sstevel@tonic-gate OID. */
1467c478bd9Sstevel@tonic-gate OM_uint32 sz = req_output_size;
147*ab9b2e15Sgtb /* Token header: 16 octets. */
1487c478bd9Sstevel@tonic-gate if (conf_req_flag) {
149*ab9b2e15Sgtb while (sz > 0 && krb5_encrypt_size(sz, ctx->enc->enctype) + 16 > req_output_size)
1507c478bd9Sstevel@tonic-gate sz--;
151*ab9b2e15Sgtb /* Allow for encrypted copy of header. */
152*ab9b2e15Sgtb if (sz > 16)
153*ab9b2e15Sgtb sz -= 16;
154*ab9b2e15Sgtb else
155*ab9b2e15Sgtb sz = 0;
156*ab9b2e15Sgtb #ifdef CFX_EXERCISE
157*ab9b2e15Sgtb /* Allow for EC padding. In the MIT implementation, only
158*ab9b2e15Sgtb added while testing. */
159*ab9b2e15Sgtb if (sz > 65535)
160*ab9b2e15Sgtb sz -= 65535;
161*ab9b2e15Sgtb else
162*ab9b2e15Sgtb sz = 0;
163*ab9b2e15Sgtb #endif
1647c478bd9Sstevel@tonic-gate } else {
165*ab9b2e15Sgtb /* Allow for token header and checksum. */
1667c478bd9Sstevel@tonic-gate if (sz < 16 + ctx->cksum_size)
1677c478bd9Sstevel@tonic-gate sz = 0;
1687c478bd9Sstevel@tonic-gate else
1697c478bd9Sstevel@tonic-gate sz -= (16 + ctx->cksum_size);
1707c478bd9Sstevel@tonic-gate }
1717c478bd9Sstevel@tonic-gate
1727c478bd9Sstevel@tonic-gate *max_input_size = sz;
1737c478bd9Sstevel@tonic-gate *minor_status = 0;
174*ab9b2e15Sgtb return GSS_S_COMPLETE;
1757c478bd9Sstevel@tonic-gate }
1767c478bd9Sstevel@tonic-gate
177*ab9b2e15Sgtb /* Calculate the token size and subtract that from the output size */
178*ab9b2e15Sgtb overhead = 7 + ctx->mech_used->length;
1797c478bd9Sstevel@tonic-gate data_size = req_output_size;
180*ab9b2e15Sgtb conflen = kg_confounder_size(ctx->k5_context, ctx->enc);
181*ab9b2e15Sgtb data_size = (conflen + data_size + 8) & (~(OM_uint32)7);
182*ab9b2e15Sgtb ohlen = g_token_size(ctx->mech_used,
183*ab9b2e15Sgtb (unsigned int) (data_size + ctx->cksum_size + 14))
184*ab9b2e15Sgtb - req_output_size;
1857c478bd9Sstevel@tonic-gate
186*ab9b2e15Sgtb if (ohlen+overhead < req_output_size)
1877c478bd9Sstevel@tonic-gate /*
188*ab9b2e15Sgtb * Cannot have trailer length that will cause us to pad over our
189*ab9b2e15Sgtb * length.
1907c478bd9Sstevel@tonic-gate */
191*ab9b2e15Sgtb *max_input_size = (req_output_size - ohlen - overhead) & (~(OM_uint32)7);
192*ab9b2e15Sgtb else
193*ab9b2e15Sgtb *max_input_size = 0;
1947c478bd9Sstevel@tonic-gate
1957c478bd9Sstevel@tonic-gate *minor_status = 0;
1967c478bd9Sstevel@tonic-gate return(GSS_S_COMPLETE);
1977c478bd9Sstevel@tonic-gate }
198