aboutsummaryrefslogtreecommitdiff
path: root/src/lib/krb5/krb/auth_con.c
blob: bcde9c2a89a8d906552267282a3f037c409abf2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307

#include "k5-int.h"
#include "auth_con.h"

krb5_error_code
krb5_auth_con_init(context, auth_context)
    krb5_context      	  context;
    krb5_auth_context  ** auth_context;
{
    if (*auth_context = (krb5_auth_context *)malloc(sizeof(krb5_auth_context))){
	memset(*auth_context, 0, sizeof(krb5_auth_context));

	/* Default flags, do time not seq */
	(*auth_context)->auth_context_flags = 
	  KRB5_AUTH_CONTEXT_DO_TIME |  KRB5_AUTH_CONN_INITIALIZED;

	(*auth_context)->cksumtype = CKSUMTYPE_RSA_MD4_DES;
	/* (*auth_context)->cksumtype = CKSUMTYPE_CRC32; */
	return 0;
    }
    return ENOMEM;
}

krb5_error_code
krb5_auth_con_free(context, auth_context)
    krb5_context      	  context;
    krb5_auth_context 	* auth_context;
{
    if (auth_context->authentp) 
	krb5_free_authenticator(context, auth_context->authentp);
    if (auth_context->keyblock) 
	krb5_free_keyblock(context, auth_context->keyblock);
    if (auth_context->local_subkey) 
	krb5_free_keyblock(context, auth_context->local_subkey);
    if (auth_context->remote_subkey) 
	krb5_free_keyblock(context, auth_context->remote_subkey);
    free(auth_context);
    return 0;
}

krb5_error_code
krb5_auth_con_setaddrs(context, auth_context, local_addr, remote_addr)
    krb5_context      	  context;
    krb5_auth_context 	* auth_context;
    krb5_address      	* local_addr;
    krb5_address      	* remote_addr;
{
    /* Free old addresses */
    if (auth_context->local_addr) 
	free(auth_context->local_addr);
    if (auth_context->remote_addr) 
	free(auth_context->remote_addr);

    if (local_addr) {
	if ((auth_context->local_addr = (krb5_address *)
		malloc(sizeof(krb5_address) + local_addr->length)) == NULL) {
	    return ENOMEM;
	}
	auth_context->local_addr->addrtype = local_addr->addrtype;
	auth_context->local_addr->length = local_addr->length;
	auth_context->local_addr->contents = (krb5_octet *)
	  auth_context->local_addr + sizeof(krb5_address);
	memcpy(auth_context->local_addr->contents,
	       local_addr->contents, local_addr->length);
    } else {
	auth_context->local_addr = NULL;
    }

    if (remote_addr) {
	if ((auth_context->remote_addr = (krb5_address *)
		malloc(sizeof(krb5_address) + remote_addr->length)) == NULL) {
	    if (auth_context->local_addr)
		free(auth_context->local_addr);
	    return ENOMEM;
	}
	auth_context->remote_addr->addrtype = remote_addr->addrtype;
	auth_context->remote_addr->length = remote_addr->length;
	auth_context->remote_addr->contents = (krb5_octet *)
	  auth_context->remote_addr + sizeof(krb5_address);
	memcpy(auth_context->remote_addr->contents,
	       remote_addr->contents, remote_addr->length);
    } else {
	auth_context->remote_addr = NULL;
    }
    return 0;
}

krb5_error_code
krb5_auth_con_getaddrs(context, auth_context, local_addr, remote_addr)
    krb5_context      	  context;
    krb5_auth_context 	* auth_context;
    krb5_address       ** local_addr;
    krb5_address       ** remote_addr;
{
    krb5_address	* tmp_addr;

    if (local_addr && auth_context->local_addr) {
	if ((tmp_addr = (krb5_address *)malloc(sizeof(krb5_address))) == NULL)
	    return ENOMEM;
	if (tmp_addr->contents = malloc(auth_context->local_addr->length)) {
	    memcpy(tmp_addr->contents, auth_context->local_addr->contents,
		   auth_context->local_addr->length);
	    tmp_addr->addrtype = auth_context->local_addr->addrtype;
	    tmp_addr->length = auth_context->local_addr->length;
	    *local_addr = tmp_addr;
	} else {
	    free(tmp_addr);
	    return ENOMEM;
	}
    }
    if ((remote_addr) && auth_context->remote_addr) {
	if ((tmp_addr = (krb5_address *)malloc(sizeof(krb5_address))) == NULL) {
	    if (local_addr && auth_context->local_addr) {
		krb5_free_address(context, *local_addr);
	    }
	    return ENOMEM;
	}
	if (tmp_addr->contents = malloc(auth_context->remote_addr->length)) {
	    memcpy(tmp_addr->contents, auth_context->remote_addr->contents,
		   auth_context->remote_addr->length);
	    tmp_addr->addrtype = auth_context->remote_addr->addrtype;
	    tmp_addr->length = auth_context->remote_addr->length;
	    *remote_addr = tmp_addr;
	} else {
	    if (local_addr && auth_context->local_addr) {
		krb5_free_address(context, *local_addr);
	    }
	    free(tmp_addr);
	    return ENOMEM;
	}
    }
    return 0 ;
}

/* XXX this call is a hack. Fixed when I do the servers. */
krb5_error_code
krb5_auth_con_setkey(context, auth_context, keyblock)
    krb5_context      	  context;
    krb5_auth_context 	* auth_context;
    krb5_keyblock       * keyblock;		
{
    if (auth_context->keyblock)
	krb5_free_keyblock(context, auth_context->keyblock);
    return(krb5_copy_keyblock(context, keyblock, &(auth_context->keyblock)));
}

/*
 * This function overloads the keyblock field. It is only useful prior to
 * a krb5_rd_req_decode() call for user to user authentication where the
 * server has the key and needs to use it to decrypt the incoming request.
 * Once decrypted this key is no longer necessary and is then overwritten
 * with the session key sent by the client.
 */
krb5_error_code
krb5_auth_con_setuseruserkey(context, auth_context, keyblock)
    krb5_context      	  context;
    krb5_auth_context 	* auth_context;
    krb5_keyblock       * keyblock;		
{
    if (auth_context->keyblock)
	krb5_free_keyblock(context, auth_context->keyblock);
    return(krb5_copy_keyblock(context, keyblock, &(auth_context->keyblock)));
}

krb5_error_code
krb5_auth_con_getkey(context, auth_context, keyblock)
    krb5_context      	  context;
    krb5_auth_context 	* auth_context;
    krb5_keyblock      ** keyblock;		
{
    if (auth_context->keyblock)
    	return krb5_copy_keyblock(context, auth_context->keyblock, keyblock);
    *keyblock = NULL;
    return 0;
}

krb5_error_code
krb5_auth_con_getlocalsubkey(context, auth_context, keyblock)
    krb5_context      	  context;
    krb5_auth_context 	* auth_context;
    krb5_keyblock      ** keyblock;		
{
    if (auth_context->local_subkey)
    	return krb5_copy_keyblock(context,auth_context->local_subkey,keyblock);
    *keyblock = NULL;
    return 0;
}

krb5_error_code
krb5_auth_con_getremotesubkey(context, auth_context, keyblock)
    krb5_context      	  context;
    krb5_auth_context 	* auth_context;
    krb5_keyblock      ** keyblock;		
{
    if (auth_context->remote_subkey)
    	return krb5_copy_keyblock(context,auth_context->remote_subkey,keyblock);
    *keyblock = NULL;
    return 0;
}

krb5_error_code
krb5_auth_con_setcksumtype(context, auth_context, cksumtype)
    krb5_context      	  context;
    krb5_auth_context 	* auth_context;
    krb5_cksumtype	  cksumtype;		
{
    auth_context->cksumtype = cksumtype;
    return 0;
}

krb5_error_code
krb5_auth_con_getlocalseqnumber(context, auth_context, seqnumber)
    krb5_context      	  context;
    krb5_auth_context 	* auth_context;
    krb5_int32	  	* seqnumber;		
{
    *seqnumber = auth_context->local_seq_number;
    return 0;
}

krb5_error_code
krb5_auth_con_getauthenticator(context, auth_context, authenticator)
    krb5_context      	  context;
    krb5_auth_context 	* auth_context;
    krb5_authenticator ** authenticator;		
{
    return (krb5_copy_authenticator(context, auth_context->authentp,
				    authenticator));
}

krb5_error_code
krb5_auth_con_getremoteseqnumber(context, auth_context, seqnumber)
    krb5_context      	  context;
    krb5_auth_context 	* auth_context;
    krb5_int32	  	* seqnumber;		
{
    *seqnumber = auth_context->remote_seq_number;
    return 0;
}

krb5_error_code
krb5_auth_con_initivector(context, auth_context)
    krb5_context      	  context;
    krb5_auth_context 	* auth_context;
{
    if (auth_context->keyblock) {
	int size = krb5_keytype_array[auth_context->keyblock->keytype]->
		      system->block_length;

	if (auth_context->i_vector = (krb5_pointer)malloc(size)) {
	    memset(auth_context->i_vector, 0, size);
	    return 0;
	}
	return ENOMEM;
    }
    return EINVAL; /* XXX need an error for no keyblock */
}

krb5_error_code
krb5_auth_con_setivector(context, auth_context, ivector)
    krb5_context      	  context;
    krb5_auth_context 	* auth_context;
    krb5_pointer	  ivector;
{
    auth_context->i_vector = ivector;
    return 0;
}

krb5_error_code
krb5_auth_con_getivector(context, auth_context, ivector)
    krb5_context      	  context;
    krb5_auth_context 	* auth_context;
    krb5_pointer	* ivector;
{
    *ivector = auth_context->i_vector;
    return 0;
}

krb5_error_code
krb5_auth_con_setflags(context, auth_context, flags)
    krb5_context      	  context;
    krb5_auth_context 	* auth_context;
    krb5_int32		  flags;
{
    auth_context->auth_context_flags = flags;
    return 0;
}

krb5_error_code
krb5_auth_con_getflags(context, auth_context, flags)
    krb5_context      	  context;
    krb5_auth_context 	* auth_context;
    krb5_int32		* flags;
{
    *flags = auth_context->auth_context_flags;
    return 0;
}

krb5_error_code
krb5_auth_con_setrcache(context, auth_context, rcache)
    krb5_context      	  context;
    krb5_auth_context 	* auth_context;
    krb5_rcache		  rcache;
{
    auth_context->rcache = rcache;
    return 0;
}