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: #include <openssl/opensslconf.h>
70:
71: #define _XOPEN_SOURCE 500
72: #include <time.h>
73: #if 0
74: #undef _XOPEN_SOURCE
75: #endif
76: #include <string.h>
77:
78: #define KRB5_PRIVATE 1
79:
80: #include <openssl/ssl.h>
81: #include <openssl/evp.h>
82: #include <openssl/objects.h>
83: #include <openssl/krb5_asn.h>
84:
85: #ifndef OPENSSL_NO_KRB5
86:
87: #ifndef ENOMEM
88: #define ENOMEM KRB5KRB_ERR_GENERIC
89: #endif
90:
91:
92:
93:
94:
95:
96:
97:
98: #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
99:
100:
101:
102:
103:
104:
105:
106:
107:
108: #ifdef krb5_cc_get_principal
109: #define NO_DEF_KRB5_CCACHE
110: #undef krb5_cc_get_principal
111: #endif
112: #define krb5_cc_get_principal kssl_krb5_cc_get_principal
113:
114: #define krb5_free_data_contents kssl_krb5_free_data_contents
115: #define krb5_free_context kssl_krb5_free_context
116: #define krb5_auth_con_free kssl_krb5_auth_con_free
117: #define krb5_free_principal kssl_krb5_free_principal
118: #define krb5_mk_req_extended kssl_krb5_mk_req_extended
119: #define krb5_get_credentials kssl_krb5_get_credentials
120: #define krb5_cc_default kssl_krb5_cc_default
121: #define krb5_sname_to_principal kssl_krb5_sname_to_principal
122: #define krb5_init_context kssl_krb5_init_context
123: #define krb5_free_ticket kssl_krb5_free_ticket
124: #define krb5_rd_req kssl_krb5_rd_req
125: #define krb5_kt_default kssl_krb5_kt_default
126: #define krb5_kt_resolve kssl_krb5_kt_resolve
127:
128: #ifndef krb5_kt_close
129: #define krb5_kt_close kssl_krb5_kt_close
130: #endif
131: #ifndef krb5_kt_get_entry
132: #define krb5_kt_get_entry kssl_krb5_kt_get_entry
133: #endif
134: #define krb5_auth_con_init kssl_krb5_auth_con_init
135:
136: #define krb5_principal_compare kssl_krb5_principal_compare
137: #define krb5_decrypt_tkt_part kssl_krb5_decrypt_tkt_part
138: #define krb5_timeofday kssl_krb5_timeofday
139: #define krb5_rc_default kssl_krb5_rc_default
140:
141: #ifdef krb5_rc_initialize
142: #undef krb5_rc_initialize
143: #endif
144: #define krb5_rc_initialize kssl_krb5_rc_initialize
145:
146: #ifdef krb5_rc_get_lifespan
147: #undef krb5_rc_get_lifespan
148: #endif
149: #define krb5_rc_get_lifespan kssl_krb5_rc_get_lifespan
150:
151: #ifdef krb5_rc_destroy
152: #undef krb5_rc_destroy
153: #endif
154: #define krb5_rc_destroy kssl_krb5_rc_destroy
155:
156: #define valid_cksumtype kssl_valid_cksumtype
157: #define krb5_checksum_size kssl_krb5_checksum_size
158: #define krb5_kt_free_entry kssl_krb5_kt_free_entry
159: #define krb5_auth_con_setrcache kssl_krb5_auth_con_setrcache
160: #define krb5_auth_con_getrcache kssl_krb5_auth_con_getrcache
161: #define krb5_get_server_rcache kssl_krb5_get_server_rcache
162:
163:
164: void kssl_krb5_free_data_contents(krb5_context, krb5_data *);
165: void kssl_krb5_free_principal(krb5_context, krb5_principal );
166: krb5_error_code kssl_krb5_kt_resolve(krb5_context,
167: krb5_const char *,
168: krb5_keytab *);
169: krb5_error_code kssl_krb5_kt_default(krb5_context,
170: krb5_keytab *);
171: krb5_error_code kssl_krb5_free_ticket(krb5_context, krb5_ticket *);
172: krb5_error_code kssl_krb5_rd_req(krb5_context, krb5_auth_context *,
173: krb5_const krb5_data *,
174: krb5_const_principal, krb5_keytab,
175: krb5_flags *,krb5_ticket **);
176:
177: krb5_boolean kssl_krb5_principal_compare(krb5_context, krb5_const_principal,
178: krb5_const_principal);
179: krb5_error_code kssl_krb5_mk_req_extended(krb5_context,
180: krb5_auth_context *,
181: krb5_const krb5_flags,
182: krb5_data *,
183: krb5_creds *,
184: krb5_data * );
185: krb5_error_code kssl_krb5_init_context(krb5_context *);
186: void kssl_krb5_free_context(krb5_context);
187: krb5_error_code kssl_krb5_cc_default(krb5_context,krb5_ccache *);
188: krb5_error_code kssl_krb5_sname_to_principal(krb5_context,
189: krb5_const char *,
190: krb5_const char *,
191: krb5_int32,
192: krb5_principal *);
193: krb5_error_code kssl_krb5_get_credentials(krb5_context,
194: krb5_const krb5_flags,
195: krb5_ccache,
196: krb5_creds *,
197: krb5_creds * *);
198: krb5_error_code kssl_krb5_auth_con_init(krb5_context,
199: krb5_auth_context *);
200: krb5_error_code kssl_krb5_cc_get_principal(krb5_context context,
201: krb5_ccache cache,
202: krb5_principal *principal);
203: krb5_error_code kssl_krb5_auth_con_free(krb5_context,krb5_auth_context);
204: size_t kssl_krb5_checksum_size(krb5_context context,krb5_cksumtype ctype);
205: krb5_boolean kssl_valid_cksumtype(krb5_cksumtype ctype);
206: krb5_error_code krb5_kt_free_entry(krb5_context,krb5_keytab_entry FAR * );
207: krb5_error_code kssl_krb5_auth_con_setrcache(krb5_context,
208: krb5_auth_context,
209: krb5_rcache);
210: krb5_error_code kssl_krb5_get_server_rcache(krb5_context,
211: krb5_const krb5_data *,
212: krb5_rcache *);
213: krb5_error_code kssl_krb5_auth_con_getrcache(krb5_context,
214: krb5_auth_context,
215: krb5_rcache *);
216:
217:
218: static void (_stdcall *p_krb5_free_data_contents)(krb5_context, krb5_data *)
219: =NULL;
220: static void (_stdcall *p_krb5_free_principal)(krb5_context, krb5_principal )
221: =NULL;
222: static krb5_error_code(_stdcall *p_krb5_kt_resolve)
223: (krb5_context, krb5_const char *, krb5_keytab *)=NULL;
224: static krb5_error_code (_stdcall *p_krb5_kt_default)(krb5_context,
225: krb5_keytab *)=NULL;
226: static krb5_error_code (_stdcall *p_krb5_free_ticket)(krb5_context,
227: krb5_ticket *)=NULL;
228: static krb5_error_code (_stdcall *p_krb5_rd_req)(krb5_context,
229: krb5_auth_context *,
230: krb5_const krb5_data *,
231: krb5_const_principal,
232: krb5_keytab, krb5_flags *,
233: krb5_ticket **)=NULL;
234: static krb5_error_code (_stdcall *p_krb5_mk_req_extended)
235: (krb5_context, krb5_auth_context *,
236: krb5_const krb5_flags, krb5_data *, krb5_creds *,
237: krb5_data * )=NULL;
238: static krb5_error_code (_stdcall *p_krb5_init_context)(krb5_context *)=NULL;
239: static void (_stdcall *p_krb5_free_context)(krb5_context)=NULL;
240: static krb5_error_code (_stdcall *p_krb5_cc_default)(krb5_context,
241: krb5_ccache *)=NULL;
242: static krb5_error_code (_stdcall *p_krb5_sname_to_principal)
243: (krb5_context, krb5_const char *, krb5_const char *,
244: krb5_int32, krb5_principal *)=NULL;
245: static krb5_error_code (_stdcall *p_krb5_get_credentials)
246: (krb5_context, krb5_const krb5_flags, krb5_ccache,
247: krb5_creds *, krb5_creds **)=NULL;
248: static krb5_error_code (_stdcall *p_krb5_auth_con_init)
249: (krb5_context, krb5_auth_context *)=NULL;
250: static krb5_error_code (_stdcall *p_krb5_cc_get_principal)
251: (krb5_context context, krb5_ccache cache,
252: krb5_principal *principal)=NULL;
253: static krb5_error_code (_stdcall *p_krb5_auth_con_free)
254: (krb5_context, krb5_auth_context)=NULL;
255: static krb5_error_code (_stdcall *p_krb5_decrypt_tkt_part)
256: (krb5_context, krb5_const krb5_keyblock *,
257: krb5_ticket *)=NULL;
258: static krb5_error_code (_stdcall *p_krb5_timeofday)
259: (krb5_context context, krb5_int32 *timeret)=NULL;
260: static krb5_error_code (_stdcall *p_krb5_rc_default)
261: (krb5_context context, krb5_rcache *rc)=NULL;
262: static krb5_error_code (_stdcall *p_krb5_rc_initialize)
263: (krb5_context context, krb5_rcache rc,
264: krb5_deltat lifespan)=NULL;
265: static krb5_error_code (_stdcall *p_krb5_rc_get_lifespan)
266: (krb5_context context, krb5_rcache rc,
267: krb5_deltat *lifespan)=NULL;
268: static krb5_error_code (_stdcall *p_krb5_rc_destroy)
269: (krb5_context context, krb5_rcache rc)=NULL;
270: static krb5_boolean (_stdcall *p_krb5_principal_compare)
271: (krb5_context, krb5_const_principal, krb5_const_principal)=NULL;
272: static size_t (_stdcall *p_krb5_checksum_size)(krb5_context context,krb5_cksumtype ctype)=NULL;
273: static krb5_boolean (_stdcall *p_valid_cksumtype)(krb5_cksumtype ctype)=NULL;
274: static krb5_error_code (_stdcall *p_krb5_kt_free_entry)
275: (krb5_context,krb5_keytab_entry * )=NULL;
276: static krb5_error_code (_stdcall * p_krb5_auth_con_setrcache)(krb5_context,
277: krb5_auth_context,
278: krb5_rcache)=NULL;
279: static krb5_error_code (_stdcall * p_krb5_get_server_rcache)(krb5_context,
280: krb5_const krb5_data *,
281: krb5_rcache *)=NULL;
282: static krb5_error_code (* p_krb5_auth_con_getrcache)(krb5_context,
283: krb5_auth_context,
284: krb5_rcache *)=NULL;
285: static krb5_error_code (_stdcall * p_krb5_kt_close)(krb5_context context,
286: krb5_keytab keytab)=NULL;
287: static krb5_error_code (_stdcall * p_krb5_kt_get_entry)(krb5_context context,
288: krb5_keytab keytab,
289: krb5_const_principal principal, krb5_kvno vno,
290: krb5_enctype enctype, krb5_keytab_entry *entry)=NULL;
291: static int krb5_loaded = 0;
292:
293:
294: void
295: load_krb5_dll(void)
296: {
297: HANDLE hKRB5_32;
298:
299: krb5_loaded++;
300: hKRB5_32 = LoadLibrary(TEXT("KRB5_32"));
301: if (!hKRB5_32)
302: return;
303:
304: (FARPROC) p_krb5_free_data_contents =
305: GetProcAddress( hKRB5_32, "krb5_free_data_contents" );
306: (FARPROC) p_krb5_free_context =
307: GetProcAddress( hKRB5_32, "krb5_free_context" );
308: (FARPROC) p_krb5_auth_con_free =
309: GetProcAddress( hKRB5_32, "krb5_auth_con_free" );
310: (FARPROC) p_krb5_free_principal =
311: GetProcAddress( hKRB5_32, "krb5_free_principal" );
312: (FARPROC) p_krb5_mk_req_extended =
313: GetProcAddress( hKRB5_32, "krb5_mk_req_extended" );
314: (FARPROC) p_krb5_get_credentials =
315: GetProcAddress( hKRB5_32, "krb5_get_credentials" );
316: (FARPROC) p_krb5_cc_get_principal =
317: GetProcAddress( hKRB5_32, "krb5_cc_get_principal" );
318: (FARPROC) p_krb5_cc_default =
319: GetProcAddress( hKRB5_32, "krb5_cc_default" );
320: (FARPROC) p_krb5_sname_to_principal =
321: GetProcAddress( hKRB5_32, "krb5_sname_to_principal" );
322: (FARPROC) p_krb5_init_context =
323: GetProcAddress( hKRB5_32, "krb5_init_context" );
324: (FARPROC) p_krb5_free_ticket =
325: GetProcAddress( hKRB5_32, "krb5_free_ticket" );
326: (FARPROC) p_krb5_rd_req =
327: GetProcAddress( hKRB5_32, "krb5_rd_req" );
328: (FARPROC) p_krb5_principal_compare =
329: GetProcAddress( hKRB5_32, "krb5_principal_compare" );
330: (FARPROC) p_krb5_decrypt_tkt_part =
331: GetProcAddress( hKRB5_32, "krb5_decrypt_tkt_part" );
332: (FARPROC) p_krb5_timeofday =
333: GetProcAddress( hKRB5_32, "krb5_timeofday" );
334: (FARPROC) p_krb5_rc_default =
335: GetProcAddress( hKRB5_32, "krb5_rc_default" );
336: (FARPROC) p_krb5_rc_initialize =
337: GetProcAddress( hKRB5_32, "krb5_rc_initialize" );
338: (FARPROC) p_krb5_rc_get_lifespan =
339: GetProcAddress( hKRB5_32, "krb5_rc_get_lifespan" );
340: (FARPROC) p_krb5_rc_destroy =
341: GetProcAddress( hKRB5_32, "krb5_rc_destroy" );
342: (FARPROC) p_krb5_kt_default =
343: GetProcAddress( hKRB5_32, "krb5_kt_default" );
344: (FARPROC) p_krb5_kt_resolve =
345: GetProcAddress( hKRB5_32, "krb5_kt_resolve" );
346: (FARPROC) p_krb5_auth_con_init =
347: GetProcAddress( hKRB5_32, "krb5_auth_con_init" );
348: (FARPROC) p_valid_cksumtype =
349: GetProcAddress( hKRB5_32, "valid_cksumtype" );
350: (FARPROC) p_krb5_checksum_size =
351: GetProcAddress( hKRB5_32, "krb5_checksum_size" );
352: (FARPROC) p_krb5_kt_free_entry =
353: GetProcAddress( hKRB5_32, "krb5_kt_free_entry" );
354: (FARPROC) p_krb5_auth_con_setrcache =
355: GetProcAddress( hKRB5_32, "krb5_auth_con_setrcache" );
356: (FARPROC) p_krb5_get_server_rcache =
357: GetProcAddress( hKRB5_32, "krb5_get_server_rcache" );
358: (FARPROC) p_krb5_auth_con_getrcache =
359: GetProcAddress( hKRB5_32, "krb5_auth_con_getrcache" );
360: (FARPROC) p_krb5_kt_close =
361: GetProcAddress( hKRB5_32, "krb5_kt_close" );
362: (FARPROC) p_krb5_kt_get_entry =
363: GetProcAddress( hKRB5_32, "krb5_kt_get_entry" );
364: }
365:
366:
367: void
368: kssl_krb5_free_data_contents(krb5_context CO, krb5_data * data)
369: {
370: if (!krb5_loaded)
371: load_krb5_dll();
372:
373: if ( p_krb5_free_data_contents )
374: p_krb5_free_data_contents(CO,data);
375: }
376:
377: krb5_error_code
378: kssl_krb5_mk_req_extended (krb5_context CO,
379: krb5_auth_context * pACO,
380: krb5_const krb5_flags F,
381: krb5_data * pD1,
382: krb5_creds * pC,
383: krb5_data * pD2)
384: {
385: if (!krb5_loaded)
386: load_krb5_dll();
387:
388: if ( p_krb5_mk_req_extended )
389: return(p_krb5_mk_req_extended(CO,pACO,F,pD1,pC,pD2));
390: else
391: return KRB5KRB_ERR_GENERIC;
392: }
393: krb5_error_code
394: kssl_krb5_auth_con_init(krb5_context CO,
395: krb5_auth_context * pACO)
396: {
397: if (!krb5_loaded)
398: load_krb5_dll();
399:
400: if ( p_krb5_auth_con_init )
401: return(p_krb5_auth_con_init(CO,pACO));
402: else
403: return KRB5KRB_ERR_GENERIC;
404: }
405: krb5_error_code
406: kssl_krb5_auth_con_free (krb5_context CO,
407: krb5_auth_context ACO)
408: {
409: if (!krb5_loaded)
410: load_krb5_dll();
411:
412: if ( p_krb5_auth_con_free )
413: return(p_krb5_auth_con_free(CO,ACO));
414: else
415: return KRB5KRB_ERR_GENERIC;
416: }
417: krb5_error_code
418: kssl_krb5_get_credentials(krb5_context CO,
419: krb5_const krb5_flags F,
420: krb5_ccache CC,
421: krb5_creds * pCR,
422: krb5_creds ** ppCR)
423: {
424: if (!krb5_loaded)
425: load_krb5_dll();
426:
427: if ( p_krb5_get_credentials )
428: return(p_krb5_get_credentials(CO,F,CC,pCR,ppCR));
429: else
430: return KRB5KRB_ERR_GENERIC;
431: }
432: krb5_error_code
433: kssl_krb5_sname_to_principal(krb5_context CO,
434: krb5_const char * pC1,
435: krb5_const char * pC2,
436: krb5_int32 I,
437: krb5_principal * pPR)
438: {
439: if (!krb5_loaded)
440: load_krb5_dll();
441:
442: if ( p_krb5_sname_to_principal )
443: return(p_krb5_sname_to_principal(CO,pC1,pC2,I,pPR));
444: else
445: return KRB5KRB_ERR_GENERIC;
446: }
447:
448: krb5_error_code
449: kssl_krb5_cc_default(krb5_context CO,
450: krb5_ccache * pCC)
451: {
452: if (!krb5_loaded)
453: load_krb5_dll();
454:
455: if ( p_krb5_cc_default )
456: return(p_krb5_cc_default(CO,pCC));
457: else
458: return KRB5KRB_ERR_GENERIC;
459: }
460:
461: krb5_error_code
462: kssl_krb5_init_context(krb5_context * pCO)
463: {
464: if (!krb5_loaded)
465: load_krb5_dll();
466:
467: if ( p_krb5_init_context )
468: return(p_krb5_init_context(pCO));
469: else
470: return KRB5KRB_ERR_GENERIC;
471: }
472:
473: void
474: kssl_krb5_free_context(krb5_context CO)
475: {
476: if (!krb5_loaded)
477: load_krb5_dll();
478:
479: if ( p_krb5_free_context )
480: p_krb5_free_context(CO);
481: }
482:
483: void
484: kssl_krb5_free_principal(krb5_context c, krb5_principal p)
485: {
486: if (!krb5_loaded)
487: load_krb5_dll();
488:
489: if ( p_krb5_free_principal )
490: p_krb5_free_principal(c,p);
491: }
492:
493: krb5_error_code
494: kssl_krb5_kt_resolve(krb5_context con,
495: krb5_const char * sz,
496: krb5_keytab * kt)
497: {
498: if (!krb5_loaded)
499: load_krb5_dll();
500:
501: if ( p_krb5_kt_resolve )
502: return(p_krb5_kt_resolve(con,sz,kt));
503: else
504: return KRB5KRB_ERR_GENERIC;
505: }
506:
507: krb5_error_code
508: kssl_krb5_kt_default(krb5_context con,
509: krb5_keytab * kt)
510: {
511: if (!krb5_loaded)
512: load_krb5_dll();
513:
514: if ( p_krb5_kt_default )
515: return(p_krb5_kt_default(con,kt));
516: else
517: return KRB5KRB_ERR_GENERIC;
518: }
519:
520: krb5_error_code
521: kssl_krb5_free_ticket(krb5_context con,
522: krb5_ticket * kt)
523: {
524: if (!krb5_loaded)
525: load_krb5_dll();
526:
527: if ( p_krb5_free_ticket )
528: return(p_krb5_free_ticket(con,kt));
529: else
530: return KRB5KRB_ERR_GENERIC;
531: }
532:
533: krb5_error_code
534: kssl_krb5_rd_req(krb5_context con, krb5_auth_context * pacon,
535: krb5_const krb5_data * data,
536: krb5_const_principal princ, krb5_keytab keytab,
537: krb5_flags * flags, krb5_ticket ** pptkt)
538: {
539: if (!krb5_loaded)
540: load_krb5_dll();
541:
542: if ( p_krb5_rd_req )
543: return(p_krb5_rd_req(con,pacon,data,princ,keytab,flags,pptkt));
544: else
545: return KRB5KRB_ERR_GENERIC;
546: }
547: