xref: /illumos-gate/usr/src/lib/gss_mechs/mech_krb5/krb5/krb/kdc_rep_dc.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
3*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
4*7c478bd9Sstevel@tonic-gate  */
5*7c478bd9Sstevel@tonic-gate 
6*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
7*7c478bd9Sstevel@tonic-gate 
8*7c478bd9Sstevel@tonic-gate /*
9*7c478bd9Sstevel@tonic-gate  * lib/krb5/krb/kdc_rep_dc.c
10*7c478bd9Sstevel@tonic-gate  *
11*7c478bd9Sstevel@tonic-gate  * Copyright 1990 by the Massachusetts Institute of Technology.
12*7c478bd9Sstevel@tonic-gate  * All Rights Reserved.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * Export of this software from the United States of America may
15*7c478bd9Sstevel@tonic-gate  *   require a specific license from the United States Government.
16*7c478bd9Sstevel@tonic-gate  *   It is the responsibility of any person or organization contemplating
17*7c478bd9Sstevel@tonic-gate  *   export to obtain such a license before exporting.
18*7c478bd9Sstevel@tonic-gate  *
19*7c478bd9Sstevel@tonic-gate  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
20*7c478bd9Sstevel@tonic-gate  * distribute this software and its documentation for any purpose and
21*7c478bd9Sstevel@tonic-gate  * without fee is hereby granted, provided that the above copyright
22*7c478bd9Sstevel@tonic-gate  * notice appear in all copies and that both that copyright notice and
23*7c478bd9Sstevel@tonic-gate  * this permission notice appear in supporting documentation, and that
24*7c478bd9Sstevel@tonic-gate  * the name of M.I.T. not be used in advertising or publicity pertaining
25*7c478bd9Sstevel@tonic-gate  * to distribution of the software without specific, written prior
26*7c478bd9Sstevel@tonic-gate  * permission.  Furthermore if you modify this software you must label
27*7c478bd9Sstevel@tonic-gate  * your software as modified software and not distribute it in such a
28*7c478bd9Sstevel@tonic-gate  * fashion that it might be confused with the original M.I.T. software.
29*7c478bd9Sstevel@tonic-gate  * M.I.T. makes no representations about the suitability of
30*7c478bd9Sstevel@tonic-gate  * this software for any purpose.  It is provided "as is" without express
31*7c478bd9Sstevel@tonic-gate  * or implied warranty.
32*7c478bd9Sstevel@tonic-gate  *
33*7c478bd9Sstevel@tonic-gate  *
34*7c478bd9Sstevel@tonic-gate  * krb5_kdc_rep_decrypt_proc()
35*7c478bd9Sstevel@tonic-gate  */
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #include <k5-int.h>
38*7c478bd9Sstevel@tonic-gate 
39*7c478bd9Sstevel@tonic-gate /*
40*7c478bd9Sstevel@tonic-gate  * Decrypt the encrypted portion of the KDC_REP message, using the key
41*7c478bd9Sstevel@tonic-gate  * passed.
42*7c478bd9Sstevel@tonic-gate  *
43*7c478bd9Sstevel@tonic-gate  */
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
46*7c478bd9Sstevel@tonic-gate krb5_error_code
47*7c478bd9Sstevel@tonic-gate krb5_kdc_rep_decrypt_proc(context, key, decryptarg, dec_rep)
48*7c478bd9Sstevel@tonic-gate     krb5_context context;
49*7c478bd9Sstevel@tonic-gate     const krb5_keyblock * key;
50*7c478bd9Sstevel@tonic-gate     krb5_const_pointer decryptarg;
51*7c478bd9Sstevel@tonic-gate     krb5_kdc_rep * dec_rep;
52*7c478bd9Sstevel@tonic-gate {
53*7c478bd9Sstevel@tonic-gate     krb5_error_code retval;
54*7c478bd9Sstevel@tonic-gate     krb5_data scratch;
55*7c478bd9Sstevel@tonic-gate     krb5_enc_kdc_rep_part *local_encpart;
56*7c478bd9Sstevel@tonic-gate     krb5_keyusage usage;
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate     if (decryptarg) {
59*7c478bd9Sstevel@tonic-gate 	usage = *(const krb5_keyusage *) decryptarg;
60*7c478bd9Sstevel@tonic-gate     } else {
61*7c478bd9Sstevel@tonic-gate 	usage = KRB5_KEYUSAGE_AS_REP_ENCPART;
62*7c478bd9Sstevel@tonic-gate     }
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate     /* set up scratch decrypt/decode area */
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate     scratch.length = dec_rep->enc_part.ciphertext.length;
67*7c478bd9Sstevel@tonic-gate     if (!(scratch.data = malloc(dec_rep->enc_part.ciphertext.length))) {
68*7c478bd9Sstevel@tonic-gate 	return(ENOMEM);
69*7c478bd9Sstevel@tonic-gate     }
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate     (void) (dec_rep->enc_part.enctype);
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate     retval = krb5_c_decrypt(context, key, usage, 0, &dec_rep->enc_part,
74*7c478bd9Sstevel@tonic-gate 				 &scratch);
75*7c478bd9Sstevel@tonic-gate     if (retval) {
76*7c478bd9Sstevel@tonic-gate 	free(scratch.data);
77*7c478bd9Sstevel@tonic-gate 	return(retval);
78*7c478bd9Sstevel@tonic-gate     }
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate #define clean_scratch() {memset(scratch.data, 0, scratch.length); \
81*7c478bd9Sstevel@tonic-gate free(scratch.data);}
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate     /* and do the decode */
84*7c478bd9Sstevel@tonic-gate     retval = decode_krb5_enc_kdc_rep_part(&scratch, &local_encpart);
85*7c478bd9Sstevel@tonic-gate     clean_scratch();
86*7c478bd9Sstevel@tonic-gate     if (retval)
87*7c478bd9Sstevel@tonic-gate 	return retval;
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate     dec_rep->enc_part2 = local_encpart;
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate     return 0;
92*7c478bd9Sstevel@tonic-gate }
93