00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TAuthenticate
00013 #define ROOT_TAuthenticate
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef ROOT_TObject
00026 #include "TObject.h"
00027 #endif
00028 #ifndef ROOT_TString
00029 #include "TString.h"
00030 #endif
00031 #ifndef ROOT_TList
00032 #include "TList.h"
00033 #endif
00034 #ifndef ROOT_TDatime
00035 #include "TDatime.h"
00036 #endif
00037 #ifndef ROOT_rsafun
00038 #include "rsafun.h"
00039 #endif
00040 #ifndef ROOT_AuthConst
00041 #include "AuthConst.h"
00042 #endif
00043 #ifdef R__SSL
00044
00045 #include <openssl/blowfish.h>
00046 #endif
00047
00048 class TAuthenticate;
00049 class THostAuth;
00050 class TPluginHandler;
00051 class TSocket;
00052 class TRootSecContext;
00053 class TVirtualMutex;
00054
00055 typedef Int_t (*CheckSecCtx_t)(const char *subj, TRootSecContext *ctx);
00056 typedef Int_t (*GlobusAuth_t)(TAuthenticate *auth, TString &user, TString &det);
00057 typedef Int_t (*Krb5Auth_t)(TAuthenticate *auth, TString &user, TString &det, Int_t version);
00058 typedef Int_t (*SecureAuth_t)(TAuthenticate *auth, const char *user, const char *passwd,
00059 const char *remote, TString &det, Int_t version);
00060
00061 R__EXTERN TVirtualMutex *gAuthenticateMutex;
00062
00063 class TAuthenticate : public TObject {
00064
00065 friend class TRootAuth;
00066 friend class TRootSecContext;
00067 friend class TSocket;
00068
00069 public:
00070 enum ESecurity { kClear, kSRP, kKrb5, kGlobus, kSSH, kRfio };
00071
00072 private:
00073 TString fDetails;
00074 THostAuth *fHostAuth;
00075 TString fPasswd;
00076 TString fProtocol;
00077 Bool_t fPwHash;
00078 TString fRemote;
00079 Int_t fRSAKey;
00080 TRootSecContext *fSecContext;
00081 ESecurity fSecurity;
00082 TSocket *fSocket;
00083 Bool_t fSRPPwd;
00084 Int_t fVersion;
00085 TString fUser;
00086 Int_t fTimeOut;
00087
00088 Int_t GenRSAKeys();
00089 Bool_t GetPwHash() const { return fPwHash; }
00090 Int_t GetRSAKey() const { return fRSAKey; }
00091 ESecurity GetSecurity() const { return fSecurity; }
00092 Bool_t GetSRPPwd() const { return fSRPPwd; }
00093 const char *GetSshUser(TString user) const;
00094 Int_t GetVersion() const { return fVersion; }
00095 Int_t ClearAuth(TString &user, TString &passwd, Bool_t &pwhash);
00096 Bool_t GetUserPasswd(TString &user, TString &passwd,
00097 Bool_t &pwhash, Bool_t srppwd);
00098 char *GetRandString(Int_t Opt,Int_t Len);
00099 Int_t ProofAuthSetup();
00100 Int_t RfioAuth(TString &user);
00101 void SetEnvironment();
00102 Int_t SshAuth(TString &user);
00103 Int_t SshError(const char *errfile);
00104
00105 static TList *fgAuthInfo;
00106 static TString fgAuthMeth[kMAXSEC];
00107 static Bool_t fgAuthReUse;
00108 static TString fgDefaultUser;
00109 static TDatime fgExpDate;
00110 static GlobusAuth_t fgGlobusAuthHook;
00111 static Krb5Auth_t fgKrb5AuthHook;
00112 static TString fgKrb5Principal;
00113 static TDatime fgLastAuthrc;
00114 static TString fgPasswd;
00115 static TPluginHandler *fgPasswdDialog;
00116 static Bool_t fgPromptUser;
00117 static TList *fgProofAuthInfo;
00118 static Bool_t fgPwHash;
00119 static Bool_t fgReadHomeAuthrc;
00120 static TString fgRootAuthrc;
00121 static Int_t fgRSAKey;
00122 static Int_t fgRSAInit;
00123 static rsa_KEY fgRSAPriKey;
00124 static rsa_KEY fgRSAPubKey;
00125 static rsa_KEY_export fgRSAPubExport[2];
00126 #ifdef R__SSL
00127 static BF_KEY fgBFKey;
00128 #endif
00129 static SecureAuth_t fgSecAuthHook;
00130 static Bool_t fgSRPPwd;
00131 static TString fgUser;
00132 static Bool_t fgUsrPwdCrypt;
00133 static Int_t fgLastError;
00134 static Int_t fgAuthTO;
00135 static Int_t fgProcessID;
00136
00137 static Bool_t CheckHost(const char *Host, const char *host);
00138
00139 static void FileExpand(const char *fin, FILE *ftmp);
00140 static Int_t ProofAuthSetup(TSocket *sock, Bool_t client);
00141 static void RemoveSecContext(TRootSecContext *ctx);
00142
00143 public:
00144 TAuthenticate(TSocket *sock, const char *remote, const char *proto,
00145 const char *user = "");
00146 virtual ~TAuthenticate() { }
00147
00148 Bool_t Authenticate();
00149 Int_t AuthExists(TString User, Int_t method, const char *Options,
00150 Int_t *Message, Int_t *Rflag, CheckSecCtx_t funcheck);
00151 void CatchTimeOut();
00152 Bool_t CheckNetrc(TString &user, TString &passwd);
00153 Bool_t CheckNetrc(TString &user, TString &passwd,
00154 Bool_t &pwhash, Bool_t srppwd);
00155 THostAuth *GetHostAuth() const { return fHostAuth; }
00156 const char *GetProtocol() const { return fProtocol; }
00157 const char *GetRemoteHost() const { return fRemote; }
00158 Int_t GetRSAKeyType() const { return fRSAKey; }
00159 TRootSecContext *GetSecContext() const { return fSecContext; }
00160 TSocket *GetSocket() const { return fSocket; }
00161 const char *GetUser() const { return fUser; }
00162 Int_t HasTimedOut() const { return fTimeOut; }
00163 void SetRSAKeyType(Int_t key) { fRSAKey = key; }
00164 void SetSecContext(TRootSecContext *ctx) { fSecContext = ctx; }
00165
00166 static void AuthError(const char *where, Int_t error);
00167 static Bool_t CheckProofAuth(Int_t cSec, TString &det);
00168
00169 static Int_t DecodeRSAPublic(const char *rsapubexport, rsa_NUMBER &n,
00170 rsa_NUMBER &d, char **rsassl = 0);
00171
00172 static TList *GetAuthInfo();
00173 static const char *GetAuthMethod(Int_t idx);
00174 static Int_t GetAuthMethodIdx(const char *meth);
00175 static Bool_t GetAuthReUse();
00176 static Int_t GetClientProtocol();
00177 static char *GetDefaultDetails(Int_t method, Int_t opt, const char *user);
00178 static const char *GetDefaultUser();
00179 static TDatime GetGlobalExpDate();
00180 static Bool_t GetGlobalPwHash();
00181 static Bool_t GetGlobalSRPPwd();
00182 static const char *GetGlobalUser();
00183 static GlobusAuth_t GetGlobusAuthHook();
00184 static THostAuth *GetHostAuth(const char *host, const char *user="",
00185 Option_t *opt = "R", Int_t *Exact = 0);
00186 static const char *GetKrb5Principal();
00187 static Bool_t GetPromptUser();
00188 static TList *GetProofAuthInfo();
00189 static Int_t GetRSAInit();
00190 static const char *GetRSAPubExport(Int_t key = 0);
00191 static THostAuth *HasHostAuth(const char *host, const char *user,
00192 Option_t *opt = "R");
00193 static void InitRandom();
00194 static void MergeHostAuthList(TList *Std, TList *New, Option_t *Opt = "");
00195 static char *PromptPasswd(const char *prompt = "Password: ");
00196 static char *PromptUser(const char *remote);
00197 static Int_t ReadRootAuthrc();
00198 static void RemoveHostAuth(THostAuth *ha, Option_t *opt = "");
00199 static Int_t SecureRecv(TSocket *Socket, Int_t dec,
00200 Int_t KeyType, char **Out);
00201 static Int_t SecureSend(TSocket *Socket, Int_t enc,
00202 Int_t KeyType, const char *In);
00203 static Int_t SendRSAPublicKey(TSocket *Socket, Int_t key = 0);
00204 static void SetAuthReUse(Bool_t authreuse);
00205 static void SetDefaultUser(const char *defaultuser);
00206 static void SetGlobalExpDate(TDatime expdate);
00207 static void SetGlobalPasswd(const char *passwd);
00208 static void SetGlobalPwHash(Bool_t pwhash);
00209 static void SetGlobalSRPPwd(Bool_t srppwd);
00210 static void SetGlobalUser(const char *user);
00211 static void SetGlobusAuthHook(GlobusAuth_t func);
00212 static void SetKrb5AuthHook(Krb5Auth_t func);
00213 static void SetPromptUser(Bool_t promptuser);
00214 static void SetDefaultRSAKeyType(Int_t key);
00215 static void SetReadHomeAuthrc(Bool_t readhomeauthrc);
00216 static void SetRSAInit(Int_t init = 1);
00217 static Int_t SetRSAPublic(const char *rsapubexport, Int_t klen);
00218 static void SetSecureAuthHook(SecureAuth_t func);
00219 static void SetTimeOut(Int_t to);
00220 static void Show(Option_t *opt="S");
00221
00222 ClassDef(TAuthenticate,0)
00223 };
00224
00225 #endif