📄 ckuath.c
字号:
char *ckathv = "Authentication, 8.0.232, 7 Feb 2004";/* C K U A T H . C -- Authentication for C-Kermit Copyright (C) 1999, 2004, Trustees of Columbia University in the City of New York. All rights reserved. See the C-Kermit COPYING.TXT file or the copyright text in the ckcmai.c module for disclaimer and permissions. Author: Jeffrey E Altman (jaltman@secure-endpoints.com) Secure Endpoints Inc., New York City*//* * Additional copyrights included with affected code. */#ifdef HEIMDAL/* Turned off User to User support Turned off KDESTROY support Turned off KLIST support Turned off krb5_prompter() support Turned off ticket validation Turned off ticket renewal Turned off alternative cache support in k5_get_ccache() Remaining link problems: ckuath.o: In function `ck_krb5_initTGT': ckuath.o(.text+0x50c2): undefined reference to `krb5_string_to_deltat' ckuath.o(.text+0x516d): undefined reference to `krb5_string_to_deltat' ckuath.o(.text+0x51ef): undefined reference to `krb5_string_to_deltat'*/#endif /* HEIMDAL *//* * Implements Kerberos 4/5, SRP, SSL, NTLM authentication and START_TLS */#include "ckcsym.h"#include "ckcdeb.h"#ifdef CK_SECURITY#define CKUATH_C#include "ckcker.h"#include "ckuusr.h"#include "ckucmd.h" /* For struct keytab */#include "ckcnet.h"#include "ckctel.h"char szUserNameRequested[UIDBUFLEN+1]; /* for incoming connections */char szUserNameAuthenticated[UIDBUFLEN+1];/* for incoming connections */char szHostName[UIDBUFLEN+1];char szUserName[UIDBUFLEN+1];static char szIP[16];static int validUser = AUTH_REJECT; /* User starts out invalid */int authentication_version = AUTHTYPE_NULL;int accept_complete = 0;#ifdef CK_AUTHENTICATION#ifdef CK_SSL#ifdef KRB5#define TLS_VERIFY#endif /* KRB5 */#endif /* CK_SSL */#ifdef CK_DES#ifdef CK_SSL#ifndef LIBDES#define LIBDES#endif /* LIBDES */#endif /* CK_SSL */#endif /* CK_DES */#ifdef CRYPT_DLL#ifndef LIBDES#define LIBDES#endif /* LIBDES */#ifdef OS2#ifdef NT#include <windows.h>#else /* NT */#define INCL_DOSMODULEMGR#include <os2.h>#endif /* NT */#endif /* OS2 */#endif /* CRYPT_DLL */#ifdef NT#define KRB5_AUTOCONF__#define NTLM#endif /* NT */#ifdef CK_KERBEROS#define KINIT#ifndef HEIMDAL#define KLIST#define KDESTROY#endif /* HEIMDAL */#define CHECKADDRS#else /* CK_KERBEROS */#ifdef KRB4#undef KRB4#endif /* KRB4 */#ifdef KRB5#undef KRB5#endif /* KRB5 */#ifdef KRB524#undef KRB524#endif /* KRB524 */#endif /* CK_KERBEROS */#include <stdlib.h>#include <string.h>#include <stdio.h>#include <time.h>#include <fcntl.h>#include <errno.h>#ifndef malloc#ifndef VMS#ifndef FREEBSD4#ifndef OpenBSD#include <malloc.h>#endif /* OpenBSD */#endif /* FREEBSD4 */#endif /* VMS */#endif /* malloc */#ifdef OS2#include <io.h>#endif /* OS2 */#ifdef KRB5#ifdef HEIMDAL#ifdef printf#define saveprintf printf#undef printf#endif /* printf */#include "krb5.h"#include "com_err.h"#ifdef saveprintf#define printf saveprintf#endif /* saveprintf */#else /* HEIMDAL */#include "krb5.h"#include "profile.h"#include "com_err.h"#ifdef KRB5_GET_INIT_CREDS_OPT_TKT_LIFE#define KRB5_HAVE_GET_INIT_CREDS#else#define krb5_free_unparsed_name(con,val) krb5_xfree((char *)(val))#endif#ifndef KRB5_HAVE_GET_INIT_CREDS#define krb5_free_data_contents(c,v) krb5_xfree((char *)(v)->data)#endif#endif /* HEIMDAL */#ifdef HAVE_PWD_H#include <pwd.h>#endif#endif /* KRB5 */#ifdef KRB4#define des_cblock Block#define const_des_cblock const Block#define des_key_schedule Schedule#ifdef KRB524#ifdef NT#define _WINDOWS#endif /* NT */#include "kerberosIV/krb.h"#ifndef OS2#ifdef KRB524_CONV#include "krb524.h"#endif /* KRB524_CONV */_PROTOTYP(const char * krb_get_err_text_entry, (int));#endif /* OS2 */#else /* KRB524 */#ifdef SOLARIS#ifndef sun/* for some reason the Makefile entries for the Solaris systems have -Usun */#define sun#endif /* sun */#endif /* SOLARIS */#include "krb.h"#define krb_get_err_text_entry krb_get_err_text#endif /* KRB524 */#else /* KRB4 */#ifdef CK_SSL#define des_cblock Block#ifdef COMMENT#define const_des_cblock const Block#endif /* COMMENT */#define des_key_schedule Schedule#endif /* CK_SSL */#endif /* KRB4 */#include "ckuath.h"#ifdef CK_KERBEROS#ifndef KRB5#define NOBLOCKDEF#else /* KRB5 */#ifdef KRB524#define NOBLOCKDEF#endif /* KRB524 */#endif /* KRB5 */#endif /* CK_KERBEROS */#include "ckuat2.h"#ifdef CK_SSL#ifdef LIBDES#ifdef OPENSSL_097#define OPENSSL_ENABLE_OLD_DES_SUPPORT#include <openssl/des.h>#endif /* OPENSSL_097 */#ifndef HEADER_DES_H#define HEADER_DES_H#endif /* HEADER_DES_H */#endif /* LIBDES */#include "ck_ssl.h"extern int ssl_finished_messages;#endif /* SSL */#define PWD_SZ 128#ifndef LIBDES#ifdef UNIX#define des_set_random_generator_seed(x) des_init_random_number_generator(x)#endif /* UNIX */#else /* LIBDES */#define des_fixup_key_parity des_set_odd_parity#endif /* LIBDES */#ifdef OS2#ifdef CK_ENCRYPTION#define MAP_DES#endif /* CK_ENCRYPTION */#ifdef KRB4#define MAP_KRB4#endif /* KRB4 */#ifdef SRPDLL#define MAP_SRP#endif /* SRPDLL */#ifdef KRB5#define MAP_KRB5#endif /* KRB5 */#ifdef CRYPT_DLL#define MAP_CRYPT#endif /* CRYPT_DLL */#define MAP_NTLM#include "ckoath.h"#include "ckosyn.h"#endif /* OS2 *//* * Globals */int auth_type_user[AUTHTYPLSTSZ] = {AUTHTYPE_AUTO, AUTHTYPE_NULL};int auth_how=0;int auth_crypt=0;int auth_fwd=0;/* These are state completion variables */static int mutual_complete = 0;#ifdef KRB4#ifdef OS2static LEASH_CREDENTIALS cred;#else /* OS2 */static CREDENTIALS cred;#endif /* OS2 */static KTEXT_ST k4_auth;static char k4_name[ANAME_SZ];static AUTH_DAT k4_adat = { 0 };static MSG_DAT k4_msg_data;#ifdef CK_ENCRYPTIONstatic Block k4_session_key = { 0 };static Schedule k4_sched;static Block k4_challenge = { 0 };#ifdef MIT_CURRENTstatic krb5_keyblock k4_krbkey;#endif /* MIT_CURRENT */#endif /* ENCRYPTION */#define KRB4_SERVICE_NAME "rcmd"_PROTOTYP(static int k4_auth_send,(VOID));_PROTOTYP(static int k4_auth_reply,(unsigned char *, int));_PROTOTYP(static int k4_auth_is,(unsigned char *, int));#endif /* KRB4 */#ifdef KRB5static krb5_data k5_auth;static krb5_auth_context auth_context;static krb5_keyblock *k5_session_key = NULL;static krb5_ticket *k5_ticket = NULL;#ifndef KRB5_SERVICE_NAME#define KRB5_SERVICE_NAME "host"#endif_PROTOTYP(static int k5_auth_send,(int,int,int));_PROTOTYP(static int k5_auth_reply,(int, unsigned char *, int));_PROTOTYP(static int k5_auth_is,(int,unsigned char *, int));_PROTOTYP(static int SendK5AuthSB,(int, void *, int));#ifdef TLS_VERIFYstatic int krb5_tls_verified = 0;#endif /* TLS_VERIFY */#endif /* KRB5 */#ifdef GSSAPI_KRB5#include <gssapi/gssapi.h>#include <gssapi/gssapi_generic.h>#include <gssapi/gssapi_krb5.h>static gss_ctx_id_t gcontext;#define GSS_BUFSIZ 4096static gss_buffer_desc gss_send_tok, gss_recv_tok, *gss_token_ptr;static char gss_stbuf[GSS_BUFSIZ];static gss_name_t gss_target_name;static struct gss_channel_bindings_struct gss_chan;_PROTOTYP(static int gssk5_auth_send,(int,int,int));_PROTOTYP(static int gssk5_auth_reply,(int, unsigned char *, int));_PROTOTYP(static int gssk5_auth_is,(int,unsigned char *, int));_PROTOTYP(static int SendGSSK5AuthSB,(int, void *, int));#endif /* GSSAPI_KRB5 */#ifdef CK_SRP#ifdef PRE_SRP_1_7_3_PROTOTYP(static int srp_reply,(int, unsigned char *, int));_PROTOTYP(static int srp_is,(int, unsigned char *, int));#else /* PRE_SRP_1_7_3 */_PROTOTYP(static int new_srp_reply,(int, unsigned char *, int));_PROTOTYP(static int new_srp_is,(int, unsigned char *, int));#endif /* PRE_SRP_1_7_3 */#endif /* SRP */#ifdef CK_ENCRYPTIONint encrypt_flag = 1;#endif#ifdef FORWARDint forward_flag = 0; /* forward tickets? */int forwardable_flag = 1; /* get forwardable tickets to forward? */int forwarded_tickets = 0; /* were tickets forwarded? */#endifstatic unsigned char str_data[4096] = { IAC, SB, TELOPT_AUTHENTICATION, 0, AUTHTYPE_KERBEROS_V5, };#define AUTHTMPBL 2048static char strTmp[AUTHTMPBL+1];static char szLocalHostName[UIDBUFLEN+1];static kstream g_kstream=NULL;#ifdef KRB5krb5_context k5_context=NULL;static krb5_creds * ret_cred=NULL;static krb5_context telnet_context=NULL;static char * telnet_krb5_realm = NULL;static krb5_principal fwd_server = NULL;#endif /* KRB5 */#ifdef CK_SRP#ifdef PRE_SRP_1_4_4#ifndef PRE_SRP_1_4_5#define PRE_SRP_1_4_5#endif /* PRE_SRP_1_4_5 */#endif /* PRE_SRP_1_4_5 */#ifdef PRE_SRP_1_4_5#ifndef PRE_SRP_1_7_3#define PRE_SRP_1_7_3#endif /* PRE_SRP_1_7_3 */#endif /* PRE_SRP_1_4_5 */#include <t_pwd.h>#include <t_client.h>#include <t_server.h>static struct t_server * ts = NULL;static struct t_client * tc = NULL;#ifdef PRE_SRP_1_4_4static struct t_pw * tpw = NULL;static struct t_conf * tconf = NULL;#endif /* PRE_SRP_1_4_4 */#ifndef PRE_SRP_1_7_3#ifndef STDC_HEADERS#define STDC_HEADERS 1#endif /* STDC_HEADERS */#include <srp.h>static SRP * s_srp = NULL;static cstr * s_key = NULL;static SRP * c_srp = NULL;static cstr * c_key = NULL;#endif /* PRE_SRP_1_7_3 */static int srp_waitresp = 0; /* Flag to indicate readiness for response */static char srp_passwd[PWD_SZ];#endif /* CK_SRP */#ifdef CK_KERBEROS#ifdef RLOGCODE#define OPTS_FORWARD_CREDS 0x00000020#define OPTS_FORWARDABLE_CREDS 0x00000010#define KCMD_KEYUSAGE 1026#define RLOG_BUFSIZ 5120static int rlog_encrypt = 0;char des_inbuf[2*RLOG_BUFSIZ]; /* needs to be > largest read size */char des_outpkt[2*RLOG_BUFSIZ+4]; /* needs to be > largest write size */#ifdef KRB5krb5_data desinbuf,desoutbuf;krb5_encrypt_block eblock; /* eblock for encrypt/decrypt */static krb5_data encivec_i[2], encivec_o[2];enum krb5_kcmd_proto { /* Old protocol: DES encryption only. No subkeys. No protection for cleartext length. No ivec supplied. OOB hacks used for rlogin. Checksum may be omitted at connection startup. */ KCMD_OLD_PROTOCOL = 1, /* New protocol: Any encryption scheme. Client-generated subkey required. Prepend cleartext-length to cleartext data (but don't include it in count). Starting ivec defined, chained. In-band signalling. Checksum required. */ KCMD_NEW_PROTOCOL, /* Hack: Get credentials, and use the old protocol iff the session key type is single-DES. */ KCMD_PROTOCOL_COMPAT_HACK, KCMD_UNKNOWN_PROTOCOL};enum krb5_kcmd_proto krb5_rlog_ver = KCMD_PROTOCOL_COMPAT_HACK;#endif /* KRB5 */#endif /* RLOGCODE */static char storage[65536]; /* storage for the decryption */static int nstored = 0;static char *store_ptr = storage;extern char * krb5_d_principal; /* Default principal */extern char * krb5_d_instance; /* Default instance */extern char * krb5_d_realm; /* Default realm */extern char * krb5_d_cc; /* Default credentials cache */extern char * krb5_d_srv; /* Default service name */extern int krb5_d_lifetime; /* Default lifetime */extern int krb5_d_forwardable;extern int krb5_d_proxiable;extern int krb5_d_renewable;extern int krb5_autoget;extern int krb5_checkaddrs;extern int krb5_d_getk4;extern int krb5_d_no_addresses;extern char * k5_keytab;extern int krb5_errno;extern char * krb5_errmsg;extern char * krb4_d_principal; /* Default principal */extern char * krb4_d_realm; /* Default realm */extern char * krb4_d_srv; /* Default service name */extern int krb4_d_lifetime; /* Default lifetime */extern int krb4_d_preauth;extern char * krb4_d_instance;extern int krb4_autoget;extern int krb4_checkaddrs;extern char * k4_keytab;extern int krb4_errno;extern char * krb4_errmsg;#endif /* CK_KERBEROS */extern char tn_msg[], hexbuf[]; /* from ckcnet.c */extern CHAR pwbuf[];extern int pwflg, pwcrypt;extern int deblog, debses, tn_deb;extern int sstelnet, inserver;#ifdef CK_LOGINextern int ckxanon;#endif /* CK_LOGIN */extern int tn_auth_how;extern int tn_auth_enc;#ifdef CK_ENCRYPTIONextern int cx_type;#endif /* CK_ENCRYPTION */extern int quiet, ttyfd, ttnproto;intck_gssapi_is_installed(){#ifdef KRB5#ifdef OS2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -