73 #define KRB5_PRIVATE 1
81 #ifndef OPENSSL_NO_KRB5
84 #define ENOMEM KRB5KRB_ERR_GENERIC
94 #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
104 #ifdef krb5_cc_get_principal
105 #define NO_DEF_KRB5_CCACHE
106 #undef krb5_cc_get_principal
108 #define krb5_cc_get_principal kssl_krb5_cc_get_principal
110 #define krb5_free_data_contents kssl_krb5_free_data_contents
111 #define krb5_free_context kssl_krb5_free_context
112 #define krb5_auth_con_free kssl_krb5_auth_con_free
113 #define krb5_free_principal kssl_krb5_free_principal
114 #define krb5_mk_req_extended kssl_krb5_mk_req_extended
115 #define krb5_get_credentials kssl_krb5_get_credentials
116 #define krb5_cc_default kssl_krb5_cc_default
117 #define krb5_sname_to_principal kssl_krb5_sname_to_principal
118 #define krb5_init_context kssl_krb5_init_context
119 #define krb5_free_ticket kssl_krb5_free_ticket
120 #define krb5_rd_req kssl_krb5_rd_req
121 #define krb5_kt_default kssl_krb5_kt_default
122 #define krb5_kt_resolve kssl_krb5_kt_resolve
124 #ifndef krb5_kt_close
125 #define krb5_kt_close kssl_krb5_kt_close
127 #ifndef krb5_kt_get_entry
128 #define krb5_kt_get_entry kssl_krb5_kt_get_entry
130 #define krb5_auth_con_init kssl_krb5_auth_con_init
132 #define krb5_principal_compare kssl_krb5_principal_compare
133 #define krb5_decrypt_tkt_part kssl_krb5_decrypt_tkt_part
134 #define krb5_timeofday kssl_krb5_timeofday
135 #define krb5_rc_default kssl_krb5_rc_default
137 #ifdef krb5_rc_initialize
138 #undef krb5_rc_initialize
140 #define krb5_rc_initialize kssl_krb5_rc_initialize
142 #ifdef krb5_rc_get_lifespan
143 #undef krb5_rc_get_lifespan
145 #define krb5_rc_get_lifespan kssl_krb5_rc_get_lifespan
147 #ifdef krb5_rc_destroy
148 #undef krb5_rc_destroy
150 #define krb5_rc_destroy kssl_krb5_rc_destroy
152 #define valid_cksumtype kssl_valid_cksumtype
153 #define krb5_checksum_size kssl_krb5_checksum_size
154 #define krb5_kt_free_entry kssl_krb5_kt_free_entry
155 #define krb5_auth_con_setrcache kssl_krb5_auth_con_setrcache
156 #define krb5_auth_con_getrcache kssl_krb5_auth_con_getrcache
157 #define krb5_get_server_rcache kssl_krb5_get_server_rcache
161 void kssl_krb5_free_principal(krb5_context, krb5_principal );
162 krb5_error_code kssl_krb5_kt_resolve(krb5_context,
165 krb5_error_code kssl_krb5_kt_default(krb5_context,
167 krb5_error_code kssl_krb5_free_ticket(krb5_context, krb5_ticket *);
168 krb5_error_code kssl_krb5_rd_req(krb5_context, krb5_auth_context *,
169 krb5_const krb5_data *,
170 krb5_const_principal, krb5_keytab,
171 krb5_flags *,krb5_ticket **);
173 krb5_boolean kssl_krb5_principal_compare(krb5_context, krb5_const_principal,
174 krb5_const_principal);
175 krb5_error_code kssl_krb5_mk_req_extended(krb5_context,
177 krb5_const krb5_flags,
181 krb5_error_code kssl_krb5_init_context(krb5_context *);
182 void kssl_krb5_free_context(krb5_context);
183 krb5_error_code kssl_krb5_cc_default(krb5_context,krb5_ccache *);
184 krb5_error_code kssl_krb5_sname_to_principal(krb5_context,
189 krb5_error_code kssl_krb5_get_credentials(krb5_context,
190 krb5_const krb5_flags,
194 krb5_error_code kssl_krb5_auth_con_init(krb5_context,
195 krb5_auth_context *);
196 krb5_error_code kssl_krb5_cc_get_principal(krb5_context context,
198 krb5_principal *principal);
199 krb5_error_code kssl_krb5_auth_con_free(krb5_context,krb5_auth_context);
200 size_t kssl_krb5_checksum_size(krb5_context context,krb5_cksumtype ctype);
201 krb5_boolean kssl_valid_cksumtype(krb5_cksumtype ctype);
202 krb5_error_code krb5_kt_free_entry(krb5_context,krb5_keytab_entry
FAR * );
203 krb5_error_code kssl_krb5_auth_con_setrcache(krb5_context,
206 krb5_error_code kssl_krb5_get_server_rcache(krb5_context,
207 krb5_const krb5_data *,
209 krb5_error_code kssl_krb5_auth_con_getrcache(krb5_context,
214 static void (_stdcall *p_krb5_free_data_contents)(krb5_context, krb5_data *)
216 static void (_stdcall *p_krb5_free_principal)(krb5_context, krb5_principal )
218 static krb5_error_code(_stdcall *p_krb5_kt_resolve)
219 (krb5_context, krb5_const
char *, krb5_keytab *)=NULL;
220 static krb5_error_code (_stdcall *p_krb5_kt_default)(krb5_context,
222 static krb5_error_code (_stdcall *p_krb5_free_ticket)(krb5_context,
224 static krb5_error_code (_stdcall *p_krb5_rd_req)(krb5_context,
226 krb5_const krb5_data *,
227 krb5_const_principal,
228 krb5_keytab, krb5_flags *,
229 krb5_ticket **)=NULL;
230 static krb5_error_code (_stdcall *p_krb5_mk_req_extended)
231 (krb5_context, krb5_auth_context *,
232 krb5_const krb5_flags, krb5_data *, krb5_creds *,
234 static krb5_error_code (_stdcall *p_krb5_init_context)(krb5_context *)=NULL;
235 static void (_stdcall *p_krb5_free_context)(krb5_context)=NULL;
236 static krb5_error_code (_stdcall *p_krb5_cc_default)(krb5_context,
238 static krb5_error_code (_stdcall *p_krb5_sname_to_principal)
239 (krb5_context, krb5_const
char *, krb5_const
char *,
240 krb5_int32, krb5_principal *)=NULL;
241 static krb5_error_code (_stdcall *p_krb5_get_credentials)
242 (krb5_context, krb5_const krb5_flags, krb5_ccache,
243 krb5_creds *, krb5_creds **)=NULL;
244 static krb5_error_code (_stdcall *p_krb5_auth_con_init)
245 (krb5_context, krb5_auth_context *)=NULL;
246 static krb5_error_code (_stdcall *p_krb5_cc_get_principal)
247 (krb5_context context, krb5_ccache cache,
248 krb5_principal *principal)=NULL;
249 static krb5_error_code (_stdcall *p_krb5_auth_con_free)
250 (krb5_context, krb5_auth_context)=NULL;
251 static krb5_error_code (_stdcall *p_krb5_decrypt_tkt_part)
252 (krb5_context, krb5_const krb5_keyblock *,
254 static krb5_error_code (_stdcall *p_krb5_timeofday)
255 (krb5_context context, krb5_int32 *timeret)=NULL;
256 static krb5_error_code (_stdcall *p_krb5_rc_default)
257 (krb5_context context, krb5_rcache *rc)=NULL;
258 static krb5_error_code (_stdcall *p_krb5_rc_initialize)
259 (krb5_context context, krb5_rcache rc,
260 krb5_deltat lifespan)=NULL;
261 static krb5_error_code (_stdcall *p_krb5_rc_get_lifespan)
262 (krb5_context context, krb5_rcache rc,
263 krb5_deltat *lifespan)=NULL;
264 static krb5_error_code (_stdcall *p_krb5_rc_destroy)
265 (krb5_context context, krb5_rcache rc)=NULL;
266 static krb5_boolean (_stdcall *p_krb5_principal_compare)
267 (krb5_context, krb5_const_principal, krb5_const_principal)=NULL;
268 static size_t (_stdcall *p_krb5_checksum_size)(krb5_context context,krb5_cksumtype ctype)=NULL;
269 static krb5_boolean (_stdcall *p_valid_cksumtype)(krb5_cksumtype ctype)=NULL;
270 static krb5_error_code (_stdcall *p_krb5_kt_free_entry)
271 (krb5_context,krb5_keytab_entry * )=NULL;
272 static krb5_error_code (_stdcall * p_krb5_auth_con_setrcache)(krb5_context,
275 static krb5_error_code (_stdcall * p_krb5_get_server_rcache)(krb5_context,
276 krb5_const krb5_data *,
278 static krb5_error_code (* p_krb5_auth_con_getrcache)(krb5_context,
281 static krb5_error_code (_stdcall * p_krb5_kt_close)(krb5_context context,
282 krb5_keytab keytab)=NULL;
283 static krb5_error_code (_stdcall * p_krb5_kt_get_entry)(krb5_context context,
285 krb5_const_principal principal, krb5_kvno vno,
286 krb5_enctype enctype, krb5_keytab_entry *entry)=NULL;
287 static int krb5_loaded = 0;
296 hKRB5_32 = LoadLibrary(TEXT(
"KRB5_32"));
300 (FARPROC) p_krb5_free_data_contents =
301 GetProcAddress( hKRB5_32,
"krb5_free_data_contents" );
302 (FARPROC) p_krb5_free_context =
303 GetProcAddress( hKRB5_32,
"krb5_free_context" );
304 (FARPROC) p_krb5_auth_con_free =
305 GetProcAddress( hKRB5_32,
"krb5_auth_con_free" );
306 (FARPROC) p_krb5_free_principal =
307 GetProcAddress( hKRB5_32,
"krb5_free_principal" );
308 (FARPROC) p_krb5_mk_req_extended =
309 GetProcAddress( hKRB5_32,
"krb5_mk_req_extended" );
310 (FARPROC) p_krb5_get_credentials =
311 GetProcAddress( hKRB5_32,
"krb5_get_credentials" );
312 (FARPROC) p_krb5_cc_get_principal =
313 GetProcAddress( hKRB5_32,
"krb5_cc_get_principal" );
314 (FARPROC) p_krb5_cc_default =
315 GetProcAddress( hKRB5_32,
"krb5_cc_default" );
316 (FARPROC) p_krb5_sname_to_principal =
317 GetProcAddress( hKRB5_32,
"krb5_sname_to_principal" );
318 (FARPROC) p_krb5_init_context =
319 GetProcAddress( hKRB5_32,
"krb5_init_context" );
320 (FARPROC) p_krb5_free_ticket =
321 GetProcAddress( hKRB5_32,
"krb5_free_ticket" );
322 (FARPROC) p_krb5_rd_req =
323 GetProcAddress( hKRB5_32,
"krb5_rd_req" );
324 (FARPROC) p_krb5_principal_compare =
325 GetProcAddress( hKRB5_32,
"krb5_principal_compare" );
326 (FARPROC) p_krb5_decrypt_tkt_part =
327 GetProcAddress( hKRB5_32,
"krb5_decrypt_tkt_part" );
328 (FARPROC) p_krb5_timeofday =
329 GetProcAddress( hKRB5_32,
"krb5_timeofday" );
330 (FARPROC) p_krb5_rc_default =
331 GetProcAddress( hKRB5_32,
"krb5_rc_default" );
332 (FARPROC) p_krb5_rc_initialize =
333 GetProcAddress( hKRB5_32,
"krb5_rc_initialize" );
334 (FARPROC) p_krb5_rc_get_lifespan =
335 GetProcAddress( hKRB5_32,
"krb5_rc_get_lifespan" );
336 (FARPROC) p_krb5_rc_destroy =
337 GetProcAddress( hKRB5_32,
"krb5_rc_destroy" );
338 (FARPROC) p_krb5_kt_default =
339 GetProcAddress( hKRB5_32,
"krb5_kt_default" );
340 (FARPROC) p_krb5_kt_resolve =
341 GetProcAddress( hKRB5_32,
"krb5_kt_resolve" );
342 (FARPROC) p_krb5_auth_con_init =
343 GetProcAddress( hKRB5_32,
"krb5_auth_con_init" );
344 (FARPROC) p_valid_cksumtype =
345 GetProcAddress( hKRB5_32,
"valid_cksumtype" );
346 (FARPROC) p_krb5_checksum_size =
347 GetProcAddress( hKRB5_32,
"krb5_checksum_size" );
348 (FARPROC) p_krb5_kt_free_entry =
349 GetProcAddress( hKRB5_32,
"krb5_kt_free_entry" );
350 (FARPROC) p_krb5_auth_con_setrcache =
351 GetProcAddress( hKRB5_32,
"krb5_auth_con_setrcache" );
352 (FARPROC) p_krb5_get_server_rcache =
353 GetProcAddress( hKRB5_32,
"krb5_get_server_rcache" );
354 (FARPROC) p_krb5_auth_con_getrcache =
355 GetProcAddress( hKRB5_32,
"krb5_auth_con_getrcache" );
356 (FARPROC) p_krb5_kt_close =
357 GetProcAddress( hKRB5_32,
"krb5_kt_close" );
358 (FARPROC) p_krb5_kt_get_entry =
359 GetProcAddress( hKRB5_32,
"krb5_kt_get_entry" );
369 if ( p_krb5_free_data_contents )
370 p_krb5_free_data_contents(CO,data);
374 kssl_krb5_mk_req_extended (krb5_context CO,
375 krb5_auth_context * pACO,
376 krb5_const krb5_flags
F,
384 if ( p_krb5_mk_req_extended )
385 return(p_krb5_mk_req_extended(CO,pACO,F,pD1,pC,pD2));
387 return KRB5KRB_ERR_GENERIC;
390 kssl_krb5_auth_con_init(krb5_context CO,
391 krb5_auth_context * pACO)
396 if ( p_krb5_auth_con_init )
397 return(p_krb5_auth_con_init(CO,pACO));
399 return KRB5KRB_ERR_GENERIC;
402 kssl_krb5_auth_con_free (krb5_context CO,
403 krb5_auth_context ACO)
408 if ( p_krb5_auth_con_free )
409 return(p_krb5_auth_con_free(CO,ACO));
411 return KRB5KRB_ERR_GENERIC;
414 kssl_krb5_get_credentials(krb5_context CO,
415 krb5_const krb5_flags F,
423 if ( p_krb5_get_credentials )
424 return(p_krb5_get_credentials(CO,F,CC,pCR,ppCR));
426 return KRB5KRB_ERR_GENERIC;
429 kssl_krb5_sname_to_principal(krb5_context CO,
430 krb5_const
char * pC1,
431 krb5_const
char * pC2,
433 krb5_principal * pPR)
438 if ( p_krb5_sname_to_principal )
439 return(p_krb5_sname_to_principal(CO,pC1,pC2,I,pPR));
441 return KRB5KRB_ERR_GENERIC;
445 kssl_krb5_cc_default(krb5_context CO,
451 if ( p_krb5_cc_default )
452 return(p_krb5_cc_default(CO,pCC));
454 return KRB5KRB_ERR_GENERIC;
458 kssl_krb5_init_context(krb5_context * pCO)
463 if ( p_krb5_init_context )
464 return(p_krb5_init_context(pCO));
466 return KRB5KRB_ERR_GENERIC;
470 kssl_krb5_free_context(krb5_context CO)
475 if ( p_krb5_free_context )
476 p_krb5_free_context(CO);
480 kssl_krb5_free_principal(krb5_context c, krb5_principal
p)
485 if ( p_krb5_free_principal )
486 p_krb5_free_principal(c,p);
490 kssl_krb5_kt_resolve(krb5_context con,
491 krb5_const
char * sz,
497 if ( p_krb5_kt_resolve )
498 return(p_krb5_kt_resolve(con,sz,kt));
500 return KRB5KRB_ERR_GENERIC;
504 kssl_krb5_kt_default(krb5_context con,
510 if ( p_krb5_kt_default )
511 return(p_krb5_kt_default(con,kt));
513 return KRB5KRB_ERR_GENERIC;
517 kssl_krb5_free_ticket(krb5_context con,
523 if ( p_krb5_free_ticket )
524 return(p_krb5_free_ticket(con,kt));
526 return KRB5KRB_ERR_GENERIC;
530 kssl_krb5_rd_req(krb5_context con, krb5_auth_context * pacon,
531 krb5_const krb5_data * data,
532 krb5_const_principal princ, krb5_keytab keytab,
533 krb5_flags *
flags, krb5_ticket ** pptkt)
539 return(p_krb5_rd_req(con,pacon,data,princ,keytab,flags,pptkt));
541 return KRB5KRB_ERR_GENERIC;
545 krb5_principal_compare(krb5_context con, krb5_const_principal princ1,
546 krb5_const_principal princ2)
551 if ( p_krb5_principal_compare )
552 return(p_krb5_principal_compare(con,princ1,princ2));
554 return KRB5KRB_ERR_GENERIC;
558 krb5_decrypt_tkt_part(krb5_context con, krb5_const krb5_keyblock *keys,
564 if ( p_krb5_decrypt_tkt_part )
565 return(p_krb5_decrypt_tkt_part(con,keys,ticket));
567 return KRB5KRB_ERR_GENERIC;
571 krb5_timeofday(krb5_context con, krb5_int32 *timeret)
576 if ( p_krb5_timeofday )
577 return(p_krb5_timeofday(con,timeret));
579 return KRB5KRB_ERR_GENERIC;
583 krb5_rc_default(krb5_context con, krb5_rcache *rc)
588 if ( p_krb5_rc_default )
589 return(p_krb5_rc_default(con,rc));
591 return KRB5KRB_ERR_GENERIC;
595 krb5_rc_initialize(krb5_context con, krb5_rcache rc, krb5_deltat lifespan)
600 if ( p_krb5_rc_initialize )
601 return(p_krb5_rc_initialize(con, rc, lifespan));
603 return KRB5KRB_ERR_GENERIC;
607 krb5_rc_get_lifespan(krb5_context con, krb5_rcache rc, krb5_deltat *lifespanp)
612 if ( p_krb5_rc_get_lifespan )
613 return(p_krb5_rc_get_lifespan(con, rc, lifespanp));
615 return KRB5KRB_ERR_GENERIC;
619 krb5_rc_destroy(krb5_context con, krb5_rcache rc)
624 if ( p_krb5_rc_destroy )
625 return(p_krb5_rc_destroy(con, rc));
627 return KRB5KRB_ERR_GENERIC;
631 krb5_checksum_size(krb5_context context,krb5_cksumtype ctype)
636 if ( p_krb5_checksum_size )
637 return(p_krb5_checksum_size(context, ctype));
639 return KRB5KRB_ERR_GENERIC;
643 valid_cksumtype(krb5_cksumtype ctype)
648 if ( p_valid_cksumtype )
649 return(p_valid_cksumtype(ctype));
651 return KRB5KRB_ERR_GENERIC;
655 krb5_kt_free_entry(krb5_context con,krb5_keytab_entry * entry)
660 if ( p_krb5_kt_free_entry )
661 return(p_krb5_kt_free_entry(con,entry));
663 return KRB5KRB_ERR_GENERIC;
667 #ifndef NO_DEF_KRB5_CCACHE
669 #define krb5_x(ptr,args) ((ptr)?((*(ptr)) args):(abort(),1))
670 #define krb5_xc(ptr,args) ((ptr)?((*(ptr)) args):(abort(),(char*)0))
673 typedef krb5_pointer krb5_cc_cursor;
675 typedef struct _krb5_ccache
678 struct _krb5_cc_ops
FAR *ops;
682 typedef struct _krb5_cc_ops
686 char * (KRB5_CALLCONV *get_name)
687 (krb5_context, krb5_ccache);
688 krb5_error_code (KRB5_CALLCONV *resolve)
689 (krb5_context, krb5_ccache *,
const char *);
690 krb5_error_code (KRB5_CALLCONV *gen_new)
691 (krb5_context, krb5_ccache *);
692 krb5_error_code (KRB5_CALLCONV *init)
693 (krb5_context, krb5_ccache, krb5_principal);
694 krb5_error_code (KRB5_CALLCONV *destroy)
695 (krb5_context, krb5_ccache);
696 krb5_error_code (KRB5_CALLCONV *close)
697 (krb5_context, krb5_ccache);
698 krb5_error_code (KRB5_CALLCONV *store)
699 (krb5_context, krb5_ccache, krb5_creds *);
700 krb5_error_code (KRB5_CALLCONV *retrieve)
701 (krb5_context, krb5_ccache,
702 krb5_flags, krb5_creds *, krb5_creds *);
703 krb5_error_code (KRB5_CALLCONV *get_princ)
704 (krb5_context, krb5_ccache, krb5_principal *);
705 krb5_error_code (KRB5_CALLCONV *get_first)
706 (krb5_context, krb5_ccache, krb5_cc_cursor *);
707 krb5_error_code (KRB5_CALLCONV *get_next)
708 (krb5_context, krb5_ccache,
709 krb5_cc_cursor *, krb5_creds *);
710 krb5_error_code (KRB5_CALLCONV *end_get)
711 (krb5_context, krb5_ccache, krb5_cc_cursor *);
712 krb5_error_code (KRB5_CALLCONV *remove_cred)
713 (krb5_context, krb5_ccache,
714 krb5_flags, krb5_creds *);
715 krb5_error_code (KRB5_CALLCONV *set_flags)
716 (krb5_context, krb5_ccache, krb5_flags);
721 kssl_krb5_cc_get_principal
722 (krb5_context context, krb5_ccache cache,
723 krb5_principal *principal)
725 if ( p_krb5_cc_get_principal )
726 return(p_krb5_cc_get_principal(context,cache,principal));
729 ((cache)->ops->get_princ,(context, cache, principal)));
733 kssl_krb5_auth_con_setrcache(krb5_context con, krb5_auth_context acon,
736 if ( p_krb5_auth_con_setrcache )
737 return(p_krb5_auth_con_setrcache(con,acon,rcache));
739 return KRB5KRB_ERR_GENERIC;
743 kssl_krb5_get_server_rcache(krb5_context con, krb5_const krb5_data * data,
744 krb5_rcache * rcache)
746 if ( p_krb5_get_server_rcache )
747 return(p_krb5_get_server_rcache(con,data,rcache));
749 return KRB5KRB_ERR_GENERIC;
753 kssl_krb5_auth_con_getrcache(krb5_context con, krb5_auth_context acon,
754 krb5_rcache * prcache)
756 if ( p_krb5_auth_con_getrcache )
757 return(p_krb5_auth_con_getrcache(con,acon, prcache));
759 return KRB5KRB_ERR_GENERIC;
763 kssl_krb5_kt_close(krb5_context context, krb5_keytab keytab)
765 if ( p_krb5_kt_close )
766 return(p_krb5_kt_close(context,keytab));
768 return KRB5KRB_ERR_GENERIC;
772 kssl_krb5_kt_get_entry(krb5_context context, krb5_keytab keytab,
773 krb5_const_principal principal, krb5_kvno vno,
774 krb5_enctype enctype, krb5_keytab_entry *entry)
776 if ( p_krb5_kt_get_entry )
777 return(p_krb5_kt_get_entry(context,keytab,principal,vno,enctype,entry));
779 return KRB5KRB_ERR_GENERIC;
786 static void* kssl_calloc(
size_t nmemb,
size_t size)
792 memset(p, 0, nmemb*size);
797 #define kssl_malloc(size) OPENSSL_malloc((size))
798 #define kssl_realloc(ptr, size) OPENSSL_realloc(ptr, size)
799 #define kssl_free(ptr) OPENSSL_free((ptr))
805 static char *null =
"[NULL]";
807 return ((
string == NULL)? null:
string);
820 case ENCTYPE_DES_HMAC_SHA1:
821 case ENCTYPE_DES_CBC_CRC:
822 case ENCTYPE_DES_CBC_MD4:
823 case ENCTYPE_DES_CBC_MD5:
824 case ENCTYPE_DES_CBC_RAW:
827 case ENCTYPE_DES3_CBC_SHA1:
828 case ENCTYPE_DES3_CBC_SHA:
829 case ENCTYPE_DES3_CBC_RAW:
832 default:
return NULL;
843 static int kssl_test_confound(
unsigned char *p)
848 if (*p++ != 0x62)
return 0;
849 if (*p > 0x82)
return 0;
851 case 0x82: p++; xx = (*p++ << 8); xx += *p++;
break;
852 case 0x81: p++; xx = *p++;
break;
854 default: xx = *p++;
break;
856 if (*p++ != 0x30)
return 0;
857 if (*p > 0x82)
return 0;
859 case 0x82: p++; len+=2; yy = (*p++ << 8); yy += *p++;
break;
860 case 0x81: p++; len++; yy = *p++;
break;
862 default: yy = *p++;
break;
865 return (xx - len == yy)? 1: 0;
878 static size_t *populate_cksumlens(
void)
881 static size_t *cklens = NULL;
883 #ifdef KRB5_MIT_OLD11
890 if (!cklens && !(cklens = (
size_t *) calloc(
sizeof(
int),n+1)))
return NULL;
892 for (i=0; i < n; i++) {
893 if (!valid_cksumtype(i))
continue;
894 for (j=0; j < n; j++) {
895 if (cklens[j] == 0) {
896 cklens[j] = krb5_checksum_size(NULL,i);
899 if (cklens[j] == krb5_checksum_size(NULL,i)) {
920 static size_t *cksumlens = NULL;
921 unsigned char *test_auth;
923 conlen = (etype)? 8: 0;
925 if (!cksumlens && !(cksumlens = populate_cksumlens()))
return NULL;
926 for (i=0; (cklen = cksumlens[i]) != 0; i++)
928 test_auth = a + conlen + cklen;
929 if (kssl_test_confound(test_auth))
return test_auth;
942 if (kssl_err == NULL)
return;
944 kssl_err->
reason = reason;
957 printf(
"%s[%d] ", label, kdata->length);
958 for (i=0; i < (int)kdata->length; i++)
960 if (0 && isprint((
int) kdata->data[i]))
961 printf(
"%c ", kdata->data[i]);
963 printf(
"%02x ", (
unsigned char) kdata->data[i]);
976 printf(
"%s, authdata==0\n", label);
979 printf(
"%s [%p]\n", label, (
void *)adata);
983 printf(
"%s[at%d:%d] ", label, adata->ad_type, adata->length);
984 for (i=0; i < adata->length; i++)
986 printf((isprint(adata->contents[i]))?
"%c ":
"%02x",
1004 printf(
"%s, keyblk==0\n", label);
1008 printf(
"%s\n\t[et%d:%d]: ", label, keyblk->keytype,
1009 keyblk->keyvalue->length);
1010 for (i=0; i < (int)keyblk->keyvalue->length; i++)
1012 printf(
"%02x",(
unsigned char *)(keyblk->keyvalue->contents)[i]);
1016 printf(
"%s\n\t[et%d:%d]: ", label, keyblk->enctype, keyblk->length);
1017 for (i=0; i < (int)keyblk->length; i++)
1019 printf(
"%02x",keyblk->contents[i]);
1030 print_krb5_princ(
char *label, krb5_principal_data *princ)
1034 printf(
"%s principal Realm: ", label);
1035 if (princ == NULL)
return;
1036 for (ui=0; ui < (int)princ->realm.length; ui++) putchar(princ->realm.data[ui]);
1037 printf(
" (nametype %d) has %d strings:\n", princ->type,princ->length);
1038 for (i=0; i < (int)princ->length; i++)
1040 printf(
"\t%d [%d]: ", i, princ->data[i].length);
1041 for (uj=0; uj < (int)princ->data[i].length; uj++) {
1042 putchar(princ->data[i].data[uj]);
1062 krb5_data **enc_ticketp,
1066 krb5_error_code krb5rc = KRB5KRB_ERR_GENERIC;
1067 krb5_context krb5context = NULL;
1068 krb5_auth_context krb5auth_context = NULL;
1069 krb5_ccache krb5ccdef = NULL;
1070 krb5_creds krb5creds, *krb5credsp = NULL;
1071 krb5_data krb5_app_req;
1074 memset((
char *)&krb5creds, 0,
sizeof(krb5creds));
1079 "No kssl_ctx defined.\n");
1085 "kssl_ctx service_host undefined.\n");
1089 if ((krb5rc = krb5_init_context(&krb5context)) != 0)
1092 "krb5_init_context() fails: %d\n", krb5rc);
1097 if ((krb5rc = krb5_sname_to_principal(krb5context,
1100 KRB5_NT_SRV_HST, &krb5creds.server)) != 0)
1103 "krb5_sname_to_principal() fails for %s/%s\n",
1111 if ((krb5rc = krb5_cc_default(krb5context, &krb5ccdef)) != 0)
1114 "krb5_cc_default fails.\n");
1118 if ((krb5rc = krb5_cc_get_principal(krb5context, krb5ccdef,
1119 &krb5creds.client)) != 0)
1122 "krb5_cc_get_principal() fails.\n");
1126 if ((krb5rc = krb5_get_credentials(krb5context, 0, krb5ccdef,
1127 &krb5creds, &krb5credsp)) != 0)
1130 "krb5_get_credentials() fails.\n");
1134 *enc_ticketp = &krb5credsp->ticket;
1136 kssl_ctx->
enctype = krb5credsp->session.keytype;
1138 kssl_ctx->
enctype = krb5credsp->keyblock.enctype;
1141 krb5rc = KRB5KRB_ERR_GENERIC;
1146 krb5_app_req.length = 0;
1149 krb5_data krb5in_data;
1150 const unsigned char *
p;
1154 authenp->length = 0;
1155 krb5in_data.data = NULL;
1156 krb5in_data.length = 0;
1157 if ((krb5rc = krb5_mk_req_extended(krb5context,
1158 &krb5auth_context, 0, &krb5in_data, krb5credsp,
1159 &krb5_app_req)) != 0)
1162 "krb5_mk_req_extended() fails.\n");
1166 arlen = krb5_app_req.length;
1167 p = (
unsigned char *)krb5_app_req.data;
1171 authenp->length = i2d_KRB5_ENCDATA(
1173 if (authenp->length &&
1174 (authenp->data = malloc(authenp->length)))
1176 unsigned char *adp = (
unsigned char *)authenp->data;
1177 authenp->length = i2d_KRB5_ENCDATA(
1182 if (ap_req) KRB5_APREQ_free((KRB5_APREQ *) ap_req);
1183 if (krb5_app_req.length)
1190 "kssl_ctx_setkey() fails.\n");
1196 "kssl_ctx_setkey() fails.\n");
1206 if (krb5creds.client) krb5_free_principal(krb5context,
1208 if (krb5creds.server) krb5_free_principal(krb5context,
1210 if (krb5auth_context) krb5_auth_con_free(krb5context,
1212 if (krb5context) krb5_free_context(krb5context);
1228 static krb5_error_code
1229 kssl_TKT2tkt( krb5_context krb5context,
1231 krb5_ticket **krb5ticket,
1234 krb5_error_code krb5rc = KRB5KRB_ERR_GENERIC;
1235 krb5_ticket *new5ticket = NULL;
1240 if (asn1ticket == NULL || asn1ticket->
realm == NULL ||
1241 asn1ticket->
sname == NULL ||
1245 "Null field in asn1ticket.\n");
1247 return KRB5KRB_ERR_GENERIC;
1250 if ((new5ticket = (krb5_ticket *) calloc(1,
sizeof(krb5_ticket)))==NULL)
1253 "Unable to allocate new krb5_ticket.\n");
1262 &new5ticket->server,
1265 gstr_host->
length, (
char *)gstr_host->
data)) != 0)
1269 "Error building ticket server principal.\n");
1274 krb5_princ_type(krb5context, new5ticket->server) =
1278 new5ticket->enc_part.ciphertext.length =
1280 if ((new5ticket->enc_part.ciphertext.data =
1285 "Error allocating cipher in krb5ticket.\n");
1287 return KRB5KRB_ERR_GENERIC;
1291 memcpy(new5ticket->enc_part.ciphertext.data,
1296 *krb5ticket = new5ticket;
1311 krb5_ticket_times *ttimes,
1314 krb5_error_code krb5rc = KRB5KRB_ERR_GENERIC;
1315 static krb5_context krb5context = NULL;
1316 static krb5_auth_context krb5auth_context = NULL;
1317 krb5_ticket *krb5ticket = NULL;
1319 const unsigned char *
p;
1320 krb5_keytab krb5keytab = NULL;
1321 krb5_keytab_entry kt_entry;
1322 krb5_principal krb5server;
1323 krb5_rcache rcache = NULL;
1330 "No kssl_ctx defined.\n");
1338 if (!krb5context && (krb5rc = krb5_init_context(&krb5context)))
1341 "krb5_init_context() fails.\n");
1344 if (krb5auth_context &&
1345 (krb5rc = krb5_auth_con_free(krb5context, krb5auth_context)))
1348 "krb5_auth_con_free() fails.\n");
1351 else krb5auth_context = NULL;
1352 if (!krb5auth_context &&
1353 (krb5rc = krb5_auth_con_init(krb5context, &krb5auth_context)))
1356 "krb5_auth_con_init() fails.\n");
1361 if ((krb5rc = krb5_auth_con_getrcache(krb5context, krb5auth_context,
1365 "krb5_auth_con_getrcache() fails.\n");
1369 if ((krb5rc = krb5_sname_to_principal(krb5context, NULL,
1371 KRB5_NT_SRV_HST, &krb5server)) != 0)
1374 "krb5_sname_to_principal() fails.\n");
1380 if ((krb5rc = krb5_get_server_rcache(krb5context,
1381 krb5_princ_component(krb5context, krb5server, 0),
1385 "krb5_get_server_rcache() fails.\n");
1390 if ((krb5rc = krb5_auth_con_setrcache(krb5context, krb5auth_context, rcache)))
1393 "krb5_auth_con_setrcache() fails.\n");
1402 krb5rc = krb5_kt_resolve(krb5context, kssl_ctx->
keytab_file,
1407 "krb5_kt_resolve() fails.\n");
1413 krb5rc = krb5_kt_default(krb5context,&krb5keytab);
1417 "krb5_kt_default() fails.\n");
1436 p = (
unsigned char *)indata->data;
1438 (
long) indata->length)) == NULL)
1441 "d2i_KRB5_TICKET() ASN.1 decode failure.\n");
1447 if ((krb5rc = kssl_TKT2tkt(krb5context, asn1ticket, &krb5ticket,
1451 "Error converting ASN.1 ticket to krb5_ticket.\n");
1456 if (! krb5_principal_compare(krb5context, krb5server,
1457 krb5ticket->server)) {
1458 krb5rc = KRB5_PRINC_NOMATCH;
1460 "server principal != ticket principal\n");
1464 if ((krb5rc = krb5_kt_get_entry(krb5context, krb5keytab,
1465 krb5ticket->server, krb5ticket->enc_part.kvno,
1466 krb5ticket->enc_part.enctype, &kt_entry)) != 0) {
1468 "krb5_kt_get_entry() fails with %x.\n", krb5rc);
1472 if ((krb5rc = krb5_decrypt_tkt_part(krb5context, &kt_entry.key,
1473 krb5ticket)) != 0) {
1475 "krb5_decrypt_tkt_part() failed.\n");
1480 krb5_kt_free_entry(krb5context, &kt_entry);
1483 int i; krb5_address **paddr = krb5ticket->enc_part2->caddrs;
1484 printf(
"Decrypted ticket fields:\n");
1485 printf(
"\tflags: %X, transit-type: %X",
1486 krb5ticket->enc_part2->flags,
1487 krb5ticket->enc_part2->transited.tr_type);
1489 &(krb5ticket->enc_part2->transited.tr_contents));
1490 printf(
"\tcaddrs: %p, authdata: %p\n",
1491 krb5ticket->enc_part2->caddrs,
1492 krb5ticket->enc_part2->authorization_data);
1495 printf(
"\tcaddrs:\n");
1496 for (i=0; paddr[i] != NULL; i++)
1499 d.length=paddr[i]->length;
1500 d.data=paddr[i]->contents;
1504 printf(
"\tstart/auth/end times: %d / %d / %d\n",
1505 krb5ticket->enc_part2->times.starttime,
1506 krb5ticket->enc_part2->times.authtime,
1507 krb5ticket->enc_part2->times.endtime);
1512 krb5rc = KRB5_NO_TKT_SUPPLIED;
1513 if (!krb5ticket || !krb5ticket->enc_part2 ||
1514 !krb5ticket->enc_part2->client ||
1515 !krb5ticket->enc_part2->client->data ||
1516 !krb5ticket->enc_part2->session)
1519 "bad ticket from krb5_rd_req.\n");
1522 &krb5ticket->enc_part2->client->realm,
1523 krb5ticket->enc_part2->client->data,
1524 krb5ticket->enc_part2->client->length))
1527 "kssl_ctx_setprinc() fails.\n");
1532 "kssl_ctx_setkey() fails.\n");
1534 else if (krb5ticket->enc_part2->flags & TKT_FLG_INVALID)
1536 krb5rc = KRB5KRB_AP_ERR_TKT_INVALID;
1538 "invalid ticket from krb5_rd_req.\n");
1542 kssl_ctx->
enctype = krb5ticket->enc_part.enctype;
1543 ttimes->authtime = krb5ticket->enc_part2->times.authtime;
1544 ttimes->starttime = krb5ticket->enc_part2->times.starttime;
1545 ttimes->endtime = krb5ticket->enc_part2->times.endtime;
1546 ttimes->renew_till = krb5ticket->enc_part2->times.renew_till;
1553 if (asn1ticket) KRB5_TICKET_free((KRB5_TICKET *) asn1ticket);
1554 if (krb5keytab) krb5_kt_close(krb5context, krb5keytab);
1555 if (krb5ticket) krb5_free_ticket(krb5context, krb5ticket);
1556 if (krb5server) krb5_free_principal(krb5context, krb5server);
1576 if (kssl_ctx == NULL)
return kssl_ctx;
1597 krb5_data *realm, krb5_data *entity,
int nentities)
1603 if (kssl_ctx == NULL || entity == NULL)
return KSSL_CTX_ERR;
1615 for (i=0; i < nentities; i++)
1617 length += entity[i].length;
1620 length += nentities-1;
1622 length += ((realm)? realm->length + 2: 1);
1624 if ((*princ = kssl_calloc(1, length)) == NULL)
1628 for (i = 0; i < nentities; i++)
1630 strncat(*princ, entity[i].data, entity[i].length);
1631 if (i < nentities-1)
1633 strcat (*princ,
"/");
1638 strcat (*princ,
"@");
1639 (
void) strncat(*princ, realm->data, realm->length);
1675 if ((*
string = kssl_calloc(1, strlen(text) + 1)) == NULL)
1678 strcpy(*
string, text);
1691 krb5_enctype enctype;
1692 krb5_octet
FAR *contents = NULL;
1706 length = session->keyvalue->length;
1707 enctype = session->keytype;
1708 contents = session->keyvalue->contents;
1710 length = session->length;
1711 enctype = session->enctype;
1712 contents = session->contents;
1719 kssl_ctx->
enctype = ENCTYPE_UNKNOWN;
1724 if ((kssl_ctx->
key =
1725 (krb5_octet
FAR *) kssl_calloc(1, kssl_ctx->
length)) == NULL)
1731 memcpy(kssl_ctx->
key, contents, length);
1744 printf(
"kssl_ctx: ");
1745 if (kssl_ctx == NULL)
1751 printf(
"%p\n", (
void *)kssl_ctx);
1753 printf(
"\tservice:\t%s\n",
1755 printf(
"\tclient:\t%s\n",
1757 printf(
"\tserver:\t%s\n",
1759 printf(
"\tkeytab:\t%s\n",
1761 printf(
"\tkey [%d:%d]:\t",
1764 for (i=0; i < kssl_ctx->
length && kssl_ctx->
key; i++)
1766 printf(
"%02x", kssl_ctx->
key[i]);
1775 krb5_context krb5context = NULL;
1776 krb5_keytab krb5keytab = NULL;
1777 krb5_keytab_entry entry;
1778 krb5_principal princ = NULL;
1779 krb5_error_code krb5rc = KRB5KRB_ERR_GENERIC;
1782 if ((krb5rc = krb5_init_context(&krb5context)))
1789 krb5rc = krb5_kt_resolve(krb5context, kssl_ctx->
keytab_file,
1796 krb5rc = krb5_kt_default(krb5context,&krb5keytab);
1802 krb5rc = krb5_sname_to_principal(krb5context, NULL,
1804 KRB5_NT_SRV_HST, &princ);
1809 krb5rc = krb5_kt_get_entry(krb5context, krb5keytab,
1814 if ( krb5rc == KRB5_KT_NOTFOUND ) {
1817 }
else if ( krb5rc )
1820 krb5_kt_free_entry(krb5context, &entry);
1824 if (krb5keytab) krb5_kt_close(krb5context, krb5keytab);
1825 if (princ) krb5_free_principal(krb5context, princ);
1826 if (krb5context) krb5_free_context(krb5context);
1833 krb5_error_code krb5rc = KRB5KRB_ERR_GENERIC;
1834 krb5_context krb5context = NULL;
1835 krb5_ccache krb5ccdef = NULL;
1836 krb5_creds krb5creds, *krb5credsp = NULL;
1839 memset((
char *)&krb5creds, 0,
sizeof(krb5creds));
1847 if ((krb5rc = krb5_init_context(&krb5context)) != 0)
1850 if ((krb5rc = krb5_sname_to_principal(krb5context,
1853 KRB5_NT_SRV_HST, &krb5creds.server)) != 0)
1856 if ((krb5rc = krb5_cc_default(krb5context, &krb5ccdef)) != 0)
1859 if ((krb5rc = krb5_cc_get_principal(krb5context, krb5ccdef,
1860 &krb5creds.client)) != 0)
1863 if ((krb5rc = krb5_get_credentials(krb5context, 0, krb5ccdef,
1864 &krb5creds, &krb5credsp)) != 0)
1874 if (krb5creds.client) krb5_free_principal(krb5context, krb5creds.client);
1875 if (krb5creds.server) krb5_free_principal(krb5context, krb5creds.server);
1876 if (krb5context) krb5_free_context(krb5context);
1880 #if !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_WIN32)
1887 #elif defined(KRB5_MIT_OLD11)
1889 krb5_xfree(data->data);
1893 krb5_free_data_contents(NULL, data);
1910 if (!k_tm)
return NULL;
1911 if (gtime == NULL || gtime->
length < 14)
return NULL;
1912 if (gtime->
data == NULL)
return NULL;
1914 p = (
char *)>ime->
data[14];
1916 c = *p; *p =
'\0'; p -= 2; k_tm->tm_sec = atoi(p); *(p+2) = c;
1917 c = *
p; *p =
'\0'; p -= 2; k_tm->tm_min = atoi(p); *(p+2) = c;
1918 c = *
p; *p =
'\0'; p -= 2; k_tm->tm_hour = atoi(p); *(p+2) = c;
1919 c = *
p; *p =
'\0'; p -= 2; k_tm->tm_mday = atoi(p); *(p+2) = c;
1920 c = *
p; *p =
'\0'; p -= 2; k_tm->tm_mon = atoi(p)-1; *(p+2) = c;
1921 c = *
p; *p =
'\0'; p -= 4; k_tm->tm_year = atoi(p)-1900; *(p+4) = c;
1932 static krb5_deltat get_rc_clockskew(krb5_context context)
1935 krb5_deltat clockskew;
1939 if (krb5_rc_get_lifespan(context, rc, &clockskew)) {
1942 (
void) krb5_rc_destroy(context, rc);
1958 krb5_ticket_times *ttimes)
1961 krb5_timestamp start, now;
1963 krb5_context context;
1966 skew = get_rc_clockskew(context);
1968 krb5_free_context(context);
1972 if (! ttimes)
return 0;
1974 start = (ttimes->starttime != 0)? ttimes->starttime: ttimes->authtime;
1979 printf(
"kssl_validate_times: %d |<- | %d - %d | < %d ->| %d\n",
1980 start, atime, now, skew, ttimes->endtime);
1996 krb5_data *authentp,
1997 krb5_timestamp *atimep,
2000 krb5_error_code krb5rc = 0;
2003 krb5_enctype enctype;
2007 const unsigned char *
p;
2008 unsigned char *unenc_authent;
2009 int outl, unencbufsize;
2010 struct tm tm_time, *tm_l, *tm_g;
2011 time_t now, tl, tg, tr, tz_offset;
2017 #ifndef KRB5CHECKAUTH
2020 #if KRB5CHECKAUTH == 0
2025 if (authentp == NULL || authentp->length == 0)
return 0;
2030 printf(
"kssl_check_authent: authenticator[%d]:\n",authentp->length);
2032 for (ui=0; ui < authentp->length; ui++) printf(
"%02x ",p[ui]);
2037 unencbufsize = 2 * authentp->length;
2038 if ((unenc_authent = calloc(1, unencbufsize)) == NULL)
2041 "Unable to allocate authenticator buffer.\n");
2042 krb5rc = KRB5KRB_ERR_GENERIC;
2046 p = (
unsigned char *)authentp->data;
2047 if ((dec_authent = d2i_KRB5_ENCDATA(NULL, &p,
2048 (
long) authentp->length)) == NULL)
2051 "Error decoding authenticator.\n");
2052 krb5rc = KRB5KRB_AP_ERR_BAD_INTEGRITY;
2057 #if !defined(KRB5_MIT_OLD11)
2058 switch ( enctype ) {
2059 case ENCTYPE_DES3_CBC_SHA1:
2060 case ENCTYPE_DES3_CBC_SHA:
2061 case ENCTYPE_DES3_CBC_RAW:
2067 memset(iv, 0,
sizeof iv);
2081 "EVP_CipherInit error decrypting authenticator.\n");
2082 krb5rc = KRB5KRB_AP_ERR_BAD_INTEGRITY;
2089 "EVP_Cipher error decrypting authenticator.\n");
2090 krb5rc = KRB5KRB_AP_ERR_BAD_INTEGRITY;
2098 printf(
"kssl_check_authent: decrypted authenticator[%d] =\n", outl);
2099 for (padl=0; padl < outl; padl++) printf(
"%02x ",unenc_authent[padl]);
2107 "confounded by authenticator.\n");
2108 krb5rc = KRB5KRB_AP_ERR_BAD_INTEGRITY;
2111 outl -= p - unenc_authent;
2114 (
long) outl))==NULL)
2117 "Error decoding authenticator body.\n");
2118 krb5rc = KRB5KRB_AP_ERR_BAD_INTEGRITY;
2122 memset(&tm_time,0,
sizeof(
struct tm));
2123 if (k_gmtime(auth->
ctime, &tm_time) &&
2124 ((tr = mktime(&tm_time)) != (time_t)(-1)))
2127 tm_l = localtime(&now); tl = mktime(tm_l);
2128 tm_g = gmtime(&now); tg = mktime(tm_g);
2129 tz_offset = tg - tl;
2131 *atimep = (krb5_timestamp)(tr - tz_offset);
2135 printf(
"kssl_check_authent: returns %d for client time ", *atimep);
2138 else printf(
"NULL\n");
2142 if (auth) KRB5_AUTHENT_free((KRB5_AUTHENT *) auth);
2143 if (dec_authent) KRB5_ENCDATA_free(dec_authent);
2144 if (unenc_authent) free(unenc_authent);
2156 krb5_context context,
2157 krb5_principal *princ,
2158 int rlen,
const char *realm,
2159 int slen,
const char *svc,
2160 int hlen,
const char *host)
2162 krb5_data *p_data = NULL;
2163 krb5_principal new_p = NULL;
2166 if ((p_data = (krb5_data *) calloc(2,
sizeof(krb5_data))) == NULL ||
2167 (new_p = (krb5_principal) calloc(1,
sizeof(krb5_principal_data)))
2170 new_p->data = p_data;
2172 if ((new_r = calloc(1, rlen + 1)) == NULL)
goto err;
2173 memcpy(new_r, realm, rlen);
2174 krb5_princ_set_realm_length(context, new_p, rlen);
2175 krb5_princ_set_realm_data(context, new_p, new_r);
2177 if ((new_p->data[0].data = calloc(1, slen + 1)) == NULL)
goto err;
2178 memcpy(new_p->data[0].data, svc, slen);
2179 new_p->data[0].length = slen;
2181 if ((new_p->data[1].data = calloc(1, hlen + 1)) == NULL)
goto err;
2182 memcpy(new_p->data[1].data, host, hlen);
2183 new_p->data[1].length = hlen;
2185 krb5_princ_type(context, new_p) = KRB5_NT_UNKNOWN;
2190 if (new_p && new_p[0].data) free(new_p[0].data);
2191 if (new_p && new_p[1].data) free(new_p[1].data);
2192 if (new_p) free(new_p);
2193 if (new_r) free(new_r);
2216 #if defined(PEDANTIC) || defined(OPENSSL_SYS_VMS)
2217 static void *dummy=&dummy;