xref: /illumos-gate/usr/src/lib/gss_mechs/mech_krb5/krb5/krb/decode_kdc.c (revision 55fea89dcaa64928bed4327112404dcb3e07b79f)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * lib/krb5/krb/decode_kdc.c
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * Copyright 1990 by the Massachusetts Institute of Technology.
57c478bd9Sstevel@tonic-gate  * All Rights Reserved.
67c478bd9Sstevel@tonic-gate  *
77c478bd9Sstevel@tonic-gate  * Export of this software from the United States of America may
87c478bd9Sstevel@tonic-gate  *   require a specific license from the United States Government.
97c478bd9Sstevel@tonic-gate  *   It is the responsibility of any person or organization contemplating
107c478bd9Sstevel@tonic-gate  *   export to obtain such a license before exporting.
117c478bd9Sstevel@tonic-gate  *
127c478bd9Sstevel@tonic-gate  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
137c478bd9Sstevel@tonic-gate  * distribute this software and its documentation for any purpose and
147c478bd9Sstevel@tonic-gate  * without fee is hereby granted, provided that the above copyright
157c478bd9Sstevel@tonic-gate  * notice appear in all copies and that both that copyright notice and
167c478bd9Sstevel@tonic-gate  * this permission notice appear in supporting documentation, and that
177c478bd9Sstevel@tonic-gate  * the name of M.I.T. not be used in advertising or publicity pertaining
187c478bd9Sstevel@tonic-gate  * to distribution of the software without specific, written prior
197c478bd9Sstevel@tonic-gate  * permission.  Furthermore if you modify this software you must label
207c478bd9Sstevel@tonic-gate  * your software as modified software and not distribute it in such a
217c478bd9Sstevel@tonic-gate  * fashion that it might be confused with the original M.I.T. software.
227c478bd9Sstevel@tonic-gate  * M.I.T. makes no representations about the suitability of
237c478bd9Sstevel@tonic-gate  * this software for any purpose.  It is provided "as is" without express
247c478bd9Sstevel@tonic-gate  * or implied warranty.
257c478bd9Sstevel@tonic-gate  *
267c478bd9Sstevel@tonic-gate  *
277c478bd9Sstevel@tonic-gate  * krb5_decode_kdc_rep() function.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
30*159d09a2SMark Phalan #include "k5-int.h"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate  Takes a KDC_REP message and decrypts encrypted part using etype and
347c478bd9Sstevel@tonic-gate  *key, putting result in *rep.
357c478bd9Sstevel@tonic-gate  dec_rep->client,ticket,session,last_req,server,caddrs
367c478bd9Sstevel@tonic-gate  are all set to allocated storage which should be freed by the caller
377c478bd9Sstevel@tonic-gate  when finished with the response.
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate  If the response isn't a KDC_REP (tgs or as), it returns an error from
407c478bd9Sstevel@tonic-gate  the decoding routines.
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate  returns errors from encryption routines, system errors
437c478bd9Sstevel@tonic-gate  */
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate krb5_error_code
krb5_decode_kdc_rep(krb5_context context,krb5_data * enc_rep,const krb5_keyblock * key,krb5_kdc_rep ** dec_rep)46505d05c7Sgtb krb5_decode_kdc_rep(krb5_context context, krb5_data *enc_rep, const krb5_keyblock *key, krb5_kdc_rep **dec_rep)
477c478bd9Sstevel@tonic-gate {
487c478bd9Sstevel@tonic-gate     krb5_error_code retval;
497c478bd9Sstevel@tonic-gate     krb5_kdc_rep *local_dec_rep;
507c478bd9Sstevel@tonic-gate     krb5_keyusage usage;
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate     if (krb5_is_as_rep(enc_rep)) {
537c478bd9Sstevel@tonic-gate 	usage = KRB5_KEYUSAGE_AS_REP_ENCPART;
547c478bd9Sstevel@tonic-gate 	retval = decode_krb5_as_rep(enc_rep, &local_dec_rep);
557c478bd9Sstevel@tonic-gate     } else if (krb5_is_tgs_rep(enc_rep)) {
567c478bd9Sstevel@tonic-gate 	usage = KRB5_KEYUSAGE_TGS_REP_ENCPART_SESSKEY;
577c478bd9Sstevel@tonic-gate 	/* KRB5_KEYUSAGE_TGS_REP_ENCPART_SUBKEY would go here, except
587c478bd9Sstevel@tonic-gate 	   that this client code base doesn't ever put a subkey in the
597c478bd9Sstevel@tonic-gate 	   tgs_req authenticator, so the tgs_rep is never encrypted in
607c478bd9Sstevel@tonic-gate 	   one.  (Check send_tgs.c:krb5_send_tgs_basic(), near the top
617c478bd9Sstevel@tonic-gate 	   where authent.subkey is set to 0) */
627c478bd9Sstevel@tonic-gate 	retval = decode_krb5_tgs_rep(enc_rep, &local_dec_rep);
637c478bd9Sstevel@tonic-gate     } else {
647c478bd9Sstevel@tonic-gate 	return KRB5KRB_AP_ERR_MSG_TYPE;
657c478bd9Sstevel@tonic-gate     }
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate     if (retval)
687c478bd9Sstevel@tonic-gate 	return retval;
697c478bd9Sstevel@tonic-gate 
70505d05c7Sgtb     if ((retval = krb5_kdc_rep_decrypt_proc(context, key, &usage,
71505d05c7Sgtb 					    local_dec_rep)))
727c478bd9Sstevel@tonic-gate 	krb5_free_kdc_rep(context, local_dec_rep);
737c478bd9Sstevel@tonic-gate     else
747c478bd9Sstevel@tonic-gate     	*dec_rep = local_dec_rep;
757c478bd9Sstevel@tonic-gate     return(retval);
767c478bd9Sstevel@tonic-gate }
777c478bd9Sstevel@tonic-gate 
78