12 #ifndef ROOT_TAuthenticate
13 #define ROOT_TAuthenticate
38 class TRootSecContext;
41 typedef Int_t (*CheckSecCtx_t)(
const char *subj, TRootSecContext *ctx);
42 typedef Int_t (*GlobusAuth_t)(TAuthenticate *auth, TString &user, TString &det);
43 typedef Int_t (*Krb5Auth_t)(TAuthenticate *auth, TString &user, TString &det, Int_t version);
44 typedef Int_t (*SecureAuth_t)(TAuthenticate *auth,
const char *user,
const char *passwd,
45 const char *remote, TString &det, Int_t version);
47 R__EXTERN TVirtualMutex *gAuthenticateMutex;
50 struct R__rsa_KEY_export;
53 class TAuthenticate :
public TObject {
55 friend class TRootAuth;
56 friend class TRootSecContext;
60 enum ESecurity { kClear, kUnsupported, kKrb5, kGlobus, kSSH, kRfio };
70 TRootSecContext *fSecContext;
78 Bool_t GetPwHash()
const {
return fPwHash; }
79 Int_t GetRSAKey()
const {
return fRSAKey; }
80 ESecurity GetSecurity()
const {
return fSecurity; }
81 Bool_t GetSRPPwd()
const {
return false; }
82 const char *GetSshUser(TString user)
const;
83 Int_t GetVersion()
const {
return fVersion; }
84 Int_t ClearAuth(TString &user, TString &passwd, Bool_t &pwhash);
85 Bool_t GetUserPasswd(TString &user, TString &passwd,
86 Bool_t &pwhash, Bool_t srppwd);
87 char *GetRandString(Int_t Opt,Int_t Len);
88 Int_t ProofAuthSetup();
89 Int_t RfioAuth(TString &user);
90 void SetEnvironment();
91 Int_t SshAuth(TString &user);
92 Int_t SshError(
const char *errfile);
94 static TList *fgAuthInfo;
95 static TString fgAuthMeth[kMAXSEC];
96 static Bool_t fgAuthReUse;
97 static TString fgDefaultUser;
98 static TDatime fgExpDate;
99 static GlobusAuth_t fgGlobusAuthHook;
100 static Krb5Auth_t fgKrb5AuthHook;
101 static TString fgKrb5Principal;
102 static TDatime fgLastAuthrc;
103 static TString fgPasswd;
104 static TPluginHandler *fgPasswdDialog;
105 static Bool_t fgPromptUser;
106 static TList *fgProofAuthInfo;
107 static Bool_t fgPwHash;
108 static Bool_t fgReadHomeAuthrc;
109 static TString fgRootAuthrc;
110 static Int_t fgRSAKey;
111 static Int_t fgRSAInit;
112 static R__rsa_KEY fgRSAPriKey;
113 static R__rsa_KEY fgRSAPubKey;
114 static R__rsa_KEY_export* fgRSAPubExport;
115 static SecureAuth_t fgSecAuthHook;
116 static TString fgUser;
117 static Bool_t fgUsrPwdCrypt;
118 static Int_t fgLastError;
119 static Int_t fgAuthTO;
120 static Int_t fgProcessID;
122 static Bool_t CheckHost(
const char *Host,
const char *host);
124 static void FileExpand(
const char *fin, FILE *ftmp);
125 static Int_t ProofAuthSetup(TSocket *sock, Bool_t client);
126 static void RemoveSecContext(TRootSecContext *ctx);
129 TAuthenticate(TSocket *sock,
const char *remote,
const char *proto,
130 const char *user =
"");
131 virtual ~TAuthenticate() { }
133 Bool_t Authenticate();
134 Int_t AuthExists(TString User, Int_t method,
const char *Options,
135 Int_t *Message, Int_t *Rflag, CheckSecCtx_t funcheck);
137 Bool_t CheckNetrc(TString &user, TString &passwd);
138 Bool_t CheckNetrc(TString &user, TString &passwd,
139 Bool_t &pwhash, Bool_t srppwd);
140 THostAuth *GetHostAuth()
const {
return fHostAuth; }
141 const char *GetProtocol()
const {
return fProtocol; }
142 const char *GetRemoteHost()
const {
return fRemote; }
143 Int_t GetRSAKeyType()
const {
return fRSAKey; }
144 TRootSecContext *GetSecContext()
const {
return fSecContext; }
145 TSocket *GetSocket()
const {
return fSocket; }
146 const char *GetUser()
const {
return fUser; }
147 Int_t HasTimedOut()
const {
return fTimeOut; }
148 void SetRSAKeyType(Int_t key) { fRSAKey = key; }
149 void SetSecContext(TRootSecContext *ctx) { fSecContext = ctx; }
151 static void AuthError(
const char *where, Int_t error);
152 static Bool_t CheckProofAuth(Int_t cSec, TString &det);
154 static Int_t DecodeRSAPublic(
const char *rsapubexport, R__rsa_NUMBER &n,
155 R__rsa_NUMBER &d,
char **rsassl = 0);
157 static TList *GetAuthInfo();
158 static const char *GetAuthMethod(Int_t idx);
159 static Int_t GetAuthMethodIdx(
const char *meth);
160 static Bool_t GetAuthReUse();
161 static Int_t GetClientProtocol();
162 static char *GetDefaultDetails(Int_t method, Int_t opt,
const char *user);
163 static const char *GetDefaultUser();
164 static TDatime GetGlobalExpDate();
165 static Bool_t GetGlobalPwHash();
166 static Bool_t GetGlobalSRPPwd();
167 static const char *GetGlobalUser();
168 static GlobusAuth_t GetGlobusAuthHook();
169 static THostAuth *GetHostAuth(
const char *host,
const char *user=
"",
170 Option_t *opt =
"R", Int_t *Exact = 0);
171 static const char *GetKrb5Principal();
172 static Bool_t GetPromptUser();
173 static TList *GetProofAuthInfo();
174 static Int_t GetRSAInit();
175 static const char *GetRSAPubExport(Int_t key = 0);
176 static THostAuth *HasHostAuth(
const char *host,
const char *user,
177 Option_t *opt =
"R");
178 static void InitRandom();
179 static void MergeHostAuthList(TList *Std, TList *New, Option_t *Opt =
"");
180 static char *PromptPasswd(
const char *prompt =
"Password: ");
181 static char *PromptUser(
const char *remote);
182 static Int_t ReadRootAuthrc();
183 static void RemoveHostAuth(THostAuth *ha, Option_t *opt =
"");
184 static Int_t SecureRecv(TSocket *Socket, Int_t dec,
185 Int_t KeyType,
char **Out);
186 static Int_t SecureSend(TSocket *Socket, Int_t enc,
187 Int_t KeyType,
const char *In);
188 static Int_t SendRSAPublicKey(TSocket *Socket, Int_t key = 0);
189 static void SetAuthReUse(Bool_t authreuse);
190 static void SetDefaultUser(
const char *defaultuser);
191 static void SetGlobalExpDate(TDatime expdate);
192 static void SetGlobalPasswd(
const char *passwd);
193 static void SetGlobalPwHash(Bool_t pwhash);
194 static void SetGlobalSRPPwd(Bool_t srppwd);
195 static void SetGlobalUser(
const char *user);
196 static void SetGlobusAuthHook(GlobusAuth_t func);
197 static void SetKrb5AuthHook(Krb5Auth_t func);
198 static void SetPromptUser(Bool_t promptuser);
199 static void SetDefaultRSAKeyType(Int_t key);
200 static void SetReadHomeAuthrc(Bool_t readhomeauthrc);
201 static void SetRSAInit(Int_t init = 1);
202 static Int_t SetRSAPublic(
const char *rsapubexport, Int_t klen);
203 static void SetSecureAuthHook(SecureAuth_t func);
204 static void SetTimeOut(Int_t to);
205 static void Show(Option_t *opt=
"S");
207 ClassDef(TAuthenticate,0)