Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TAuthenticate.h
Go to the documentation of this file.
1// @(#)root/auth:$Id$
2// Author: Fons Rademakers 26/11/2000
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_TAuthenticate
13#define ROOT_TAuthenticate
14
15
16//////////////////////////////////////////////////////////////////////////
17// //
18// TAuthenticate //
19// //
20// An authentication module for ROOT based network services, like rootd.// //
21// //
22//////////////////////////////////////////////////////////////////////////
23
24#include "TObject.h"
25#include "TString.h"
26#include "TList.h"
27#include "TDatime.h"
28#ifndef ROOT_rsafun
29//#include "rsafun.h"
30#endif
31#include "AuthConst.h"
32
33class TPluginHandler;
34class TSocket;
35class TVirtualMutex;
36
37namespace ROOT::Deprecated {
38
39struct R__rsa_KEY; // opaque replacement for rsa_KEY
40struct R__rsa_KEY_export; // opaque replacement for rsa_KEY_export
41struct R__rsa_NUMBER; // opaque replacement for rsa_NUMBER
42
44
45class TAuthenticate;
46class THostAuth;
47class TRootAuth;
48class TRootSecContext;
49
50typedef Int_t (*CheckSecCtx_t)(const char *subj, ROOT::Deprecated::TRootSecContext *ctx);
51typedef Int_t (*GlobusAuth_t)(ROOT::Deprecated::TAuthenticate *auth, TString &user, TString &det);
53typedef Int_t (*SecureAuth_t)(ROOT::Deprecated::TAuthenticate *auth, const char *user, const char *passwd,
54 const char *remote, TString &det, Int_t version);
55
56class TAuthenticate : public TObject {
57
60
61public:
62 enum ESecurity {
63// clang++ <v20 (-Wshadow) complains about shadowing Getline.h global enum EGetLineMode. Let's silence warning:
64#if defined(__clang__) && __clang_major__ < 20
65#pragma clang diagnostic push
66#pragma clang diagnostic ignored "-Wshadow"
67#endif
69#if defined(__clang__) && __clang_major__ < 20
70#pragma clang diagnostic pop
71#endif
72 kUnsupported, kKrb5, kGlobus, kSSH, kRfio }; // type of authentication
73
74private:
75 TString fDetails; // logon details (method dependent ...)
76 THostAuth *fHostAuth; // pointer to relevant authentication info
77 TString fPasswd; // user's password
78 TString fProtocol; // remote service (rootd)
79 Bool_t fPwHash; // kTRUE if fPasswd is a passwd hash
80 TString fRemote; // remote host to which we want to connect
81 Int_t fRSAKey; // Type of RSA key used
82 TRootSecContext *fSecContext; // pointer to relevant sec context
83 ESecurity fSecurity; // actual logon security level
84 TSocket *fSocket; // connection to remote daemon
85 Int_t fVersion; // 0,1,2, ... accordingly to remote daemon version
86 TString fUser; // user to be authenticated
87 Int_t fTimeOut; // timeout flag
88
90 Bool_t GetPwHash() const { return fPwHash; }
91 Int_t GetRSAKey() const { return fRSAKey; }
92 ESecurity GetSecurity() const { return fSecurity; }
93 Bool_t GetSRPPwd() const { return false; }
94 const char *GetSshUser(TString user) const;
95 Int_t GetVersion() const { return fVersion; }
99 char *GetRandString(Int_t Opt,Int_t Len);
100 Int_t RfioAuth(TString &user);
101 void SetEnvironment();
102 Int_t SshAuth(TString &user);
103 Int_t SshError(const char *errfile);
104
107 static Bool_t fgAuthReUse; // kTRUE is ReUse required
108 static TString fgDefaultUser; // Default user information
109 static TDatime fgExpDate; // Expiring date for new security contexts
110 static GlobusAuth_t fgGlobusAuthHook;
111 static Krb5Auth_t fgKrb5AuthHook;
112 static TString fgKrb5Principal; // Principal for Krb5 ticket
113 static TDatime fgLastAuthrc; // Time of last reading of fgRootAuthrc
115 static TPluginHandler *fgPasswdDialog; // Passwd dialog GUI plugin
116 static Bool_t fgPromptUser; // kTRUE if user prompt required
117 static Bool_t fgPwHash; // kTRUE if fgPasswd is a passwd hash
118 static Bool_t fgReadHomeAuthrc; // kTRUE to look for $HOME/.rootauthrc
119 static TString fgRootAuthrc; // Path to last rootauthrc-like file read
120 static Int_t fgRSAKey; // Default type of RSA key to be tried
124 static R__rsa_KEY_export* fgRSAPubExport; // array of size [2]
125 static SecureAuth_t fgSecAuthHook;
127 static Bool_t fgUsrPwdCrypt; // kTRUE if encryption for UsrPwd is required
128 static Int_t fgLastError; // Last error code processed by AuthError()
129 static Int_t fgAuthTO; // if > 0, timeout in sec
130 static Int_t fgProcessID; // ID of the main thread as unique identifier
131
132 static Bool_t CheckHost(const char *Host, const char *host);
133
134 static void FileExpand(const char *fin, FILE *ftmp);
135 static void RemoveSecContext(TRootSecContext *ctx);
136
137public:
138 TAuthenticate(TSocket *sock, const char *remote, const char *proto,
139 const char *user = "");
140 virtual ~TAuthenticate() {}
141
143 Int_t AuthExists(TString User, Int_t method, const char *Options,
144 Int_t *Message, Int_t *Rflag, CheckSecCtx_t funcheck);
145 void CatchTimeOut();
149 THostAuth *GetHostAuth() const { return fHostAuth; }
150 const char *GetProtocol() const { return fProtocol; }
151 const char *GetRemoteHost() const { return fRemote; }
152 Int_t GetRSAKeyType() const { return fRSAKey; }
154 TSocket *GetSocket() const { return fSocket; }
155 const char *GetUser() const { return fUser; }
156 Int_t HasTimedOut() const { return fTimeOut; }
157 void SetRSAKeyType(Int_t key) { fRSAKey = key; }
159
160 static void AuthError(const char *where, Int_t error);
161
162 static Int_t DecodeRSAPublic(const char *rsapubexport, R__rsa_NUMBER &n,
163 R__rsa_NUMBER &d, char **rsassl = nullptr);
164
165 static TList *GetAuthInfo();
166 static const char *GetAuthMethod(Int_t idx);
167 static Int_t GetAuthMethodIdx(const char *meth);
168 static Bool_t GetAuthReUse();
169 static Int_t GetClientProtocol();
170 static char *GetDefaultDetails(Int_t method, Int_t opt, const char *user);
171 static const char *GetDefaultUser();
172 static TDatime GetGlobalExpDate();
173 static Bool_t GetGlobalPwHash();
174 static Bool_t GetGlobalSRPPwd();
175 static const char *GetGlobalUser();
176 static GlobusAuth_t GetGlobusAuthHook();
177 static THostAuth *GetHostAuth(const char *host, const char *user="",
178 Option_t *opt = "R", Int_t *Exact = nullptr);
179 static const char *GetKrb5Principal();
180 static Bool_t GetPromptUser();
181 static Int_t GetRSAInit();
182 static const char *GetRSAPubExport(Int_t key = 0);
183 static THostAuth *HasHostAuth(const char *host, const char *user,
184 Option_t *opt = "R");
185 static void InitRandom();
186 static void MergeHostAuthList(TList *Std, TList *New, Option_t *Opt = "");
187 static char *PromptPasswd(const char *prompt = "Password: ");
188 static char *PromptUser(const char *remote);
189 static Int_t ReadRootAuthrc();
190 static void RemoveHostAuth(THostAuth *ha, Option_t *opt = "");
191 static Int_t SecureRecv(TSocket *Socket, Int_t dec,
192 Int_t KeyType, char **Out);
193 static Int_t SecureSend(TSocket *Socket, Int_t enc,
194 Int_t KeyType, const char *In);
195 static Int_t SendRSAPublicKey(TSocket *Socket, Int_t key = 0);
196 static void SetAuthReUse(Bool_t authreuse);
197 static void SetDefaultUser(const char *defaultuser);
198 static void SetGlobalExpDate(TDatime expdate);
199 static void SetGlobalPasswd(const char *passwd);
200 static void SetGlobalPwHash(Bool_t pwhash);
201 static void SetGlobalSRPPwd(Bool_t srppwd);
202 static void SetGlobalUser(const char *user);
203 static void SetGlobusAuthHook(GlobusAuth_t func);
204 static void SetKrb5AuthHook(Krb5Auth_t func);
205 static void SetPromptUser(Bool_t promptuser);
206 static void SetDefaultRSAKeyType(Int_t key);
207 static void SetRSAInit(Int_t init = 1);
208 static Int_t SetRSAPublic(const char *rsapubexport, Int_t klen);
209 static void SetSecureAuthHook(SecureAuth_t func);
210 static void SetTimeOut(Int_t to);
211 static void Show(Option_t *opt="S");
212
213 ClassDefOverride(TAuthenticate,0) // Class providing remote authentication service
214};
215
216} // namespace ROOT::Deprecated
217
218R__EXTERN TVirtualMutex *&gAuthenticateMutex R__DEPRECATED(6, 42, "the RootAuth library is deprecated");
219
220using CheckSecCtx_t R__DEPRECATED(6, 42, "the RootAuth library is deprecated") = ROOT::Deprecated::CheckSecCtx_t;
221using GlobusAuth_t R__DEPRECATED(6, 42, "the RootAuth library is deprecated") = ROOT::Deprecated::GlobusAuth_t;
222using Krb5Auth_t R__DEPRECATED(6, 42, "the RootAuth library is deprecated") = ROOT::Deprecated::Krb5Auth_t;
223using SecureAuth_t R__DEPRECATED(6, 42, "the RootAuth library is deprecated") = ROOT::Deprecated::SecureAuth_t;
224using TAuthenticate R__DEPRECATED(6, 42, "the RootAuth library is deprecated") = ROOT::Deprecated::TAuthenticate;
225
226#endif
#define R__EXTERN
Definition DllImport.h:26
#define R__DEPRECATED(MAJOR, MINOR, REASON)
Definition RConfig.hxx:510
#define d(i)
Definition RSha256.hxx:102
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
std::string Message(const std::string &msg, const std::string &location)
Definition Scanner.cxx:177
TVirtualMutex *& gAuthenticateMutex
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
const char * proto
Definition civetweb.c:18822
static const char * GetDefaultUser()
Static method returning the default user information.
static const char * GetGlobalUser()
Static method returning the global user.
static GlobusAuth_t GetGlobusAuthHook()
Static method returning the globus authorization hook (no longer supported)
static void RemoveSecContext(TRootSecContext *ctx)
Tool for removing SecContext ctx from THostAuth listed in fgAuthInfo.
void CatchTimeOut()
Called in connection with a timer timeout.
Int_t SshError(const char *errfile)
static char * GetDefaultDetails(Int_t method, Int_t opt, const char *user)
Determine default authentication details for method 'sec' and user 'usr'.
static void MergeHostAuthList(TList *Std, TList *New, Option_t *Opt="")
Tool for updating fgAuthInfo 'nin' contains list of last input information through (re)reading of a r...
Int_t AuthExists(TString User, Int_t method, const char *Options, Int_t *Message, Int_t *Rflag, CheckSecCtx_t funcheck)
Check if we have a valid established sec context in memory Retrieves relevant info and negotiates wit...
static TDatime GetGlobalExpDate()
Static method returning default expiring date for new validity contexts.
static Int_t ReadRootAuthrc()
Read authentication directives from $ROOTAUTHRC, $HOME/.rootauthrc or <Root_etc_dir>/system....
char * GetRandString(Int_t Opt, Int_t Len)
Allocates and fills a 0 terminated buffer of length len+1 with len random characters.
static void SetGlobalPwHash(Bool_t pwhash)
Set global passwd hash flag to be used for authentication to rootd.
static R__rsa_KEY_export * fgRSAPubExport
static GlobusAuth_t fgGlobusAuthHook
static void SetKrb5AuthHook(Krb5Auth_t func)
Set kerberos5 authorization function.
Int_t SshAuth(TString &user)
SSH client authentication code (no longer supported)
static void SetGlobalPasswd(const char *passwd)
Set global passwd to be used for authentication to rootd.
const char * GetRemoteHost() const
static TString fgAuthMeth[kMAXSEC]
static void SetDefaultUser(const char *defaultuser)
Set default user name.
static void RemoveHostAuth(THostAuth *ha, Option_t *opt="")
Remove THostAuth instance from the list.
static void Show(Option_t *opt="S")
Print info about the authentication sector.
static Int_t GetRSAInit()
Static method returning the RSA initialization flag.
static Int_t DecodeRSAPublic(const char *rsapubexport, R__rsa_NUMBER &n, R__rsa_NUMBER &d, char **rsassl=nullptr)
Store RSA public keys from export string rsaPubExport.
static void SetDefaultRSAKeyType(Int_t key)
Static method setting the default type of RSA key.
static Int_t GetAuthMethodIdx(const char *meth)
Static method returning the method index (which can be used to find the method in GetAuthMethod()).
static void SetGlobalExpDate(TDatime expdate)
Set default expiring date for new validity contexts.
static TPluginHandler * fgPasswdDialog
static Int_t SetRSAPublic(const char *rsapubexport, Int_t klen)
Store RSA public keys from export string rsaPubExport.
static TList * GetAuthInfo()
Static method returning the list with authentication details.
void SetEnvironment()
Set default authentication environment.
static void SetTimeOut(Int_t to)
Set timeout (active if > 0)
static Bool_t GetAuthReUse()
Static method returning the authentication reuse settings.
static void FileExpand(const char *fin, FILE *ftmp)
Expands include directives found in fexp files The expanded, temporary file, is pointed to by 'ftmp' ...
static SecureAuth_t fgSecAuthHook
static const char * GetKrb5Principal()
Static method returning the principal to be used to init Krb5 tickets.
static Int_t SecureSend(TSocket *Socket, Int_t enc, Int_t KeyType, const char *In)
Encode null terminated str using the session private key indicated by enc and sends it over the netwo...
static Bool_t GetPromptUser()
Static method returning the prompt user settings.
static void SetGlobalSRPPwd(Bool_t srppwd)
Set global SRP passwd flag to be used for authentication to rootd.
static void SetSecureAuthHook(SecureAuth_t func)
Set secure authorization function.
Bool_t Authenticate()
Authenticate to remote rootd server.
Int_t RfioAuth(TString &user)
RFIO authentication (no longer supported)
static void SetAuthReUse(Bool_t authreuse)
Set global AuthReUse flag.
static Int_t GetClientProtocol()
Static method returning supported client protocol.
static char * PromptUser(const char *remote)
Static method to prompt for the user name to be used for authentication to rootd.
static Bool_t GetGlobalPwHash()
Static method returning the global password hash flag.
static void SetGlobalUser(const char *user)
Set global user name to be used for authentication to rootd.
static void SetPromptUser(Bool_t promptuser)
Set global PromptUser flag.
static char * PromptPasswd(const char *prompt="Password: ")
Static method to prompt for the user's passwd to be used for authentication to rootd.
TAuthenticate(TSocket *sock, const char *remote, const char *proto, const char *user="")
Create authentication object.
THostAuth * GetHostAuth() const
Int_t GenRSAKeys()
Generate a valid pair of private/public RSA keys to protect for authentication token exchange.
static Bool_t CheckHost(const char *Host, const char *host)
Check if 'host' matches 'href': this means either equal or "containing" it, even with wild cards * in...
TRootSecContext * GetSecContext() const
static void SetRSAInit(Int_t init=1)
Static method setting RSA initialization flag.
static void InitRandom()
Initialize random machine using seed from /dev/urandom (or current time if /dev/urandom not available...
static void SetGlobusAuthHook(GlobusAuth_t func)
Set Globus authorization function.
static const char * GetAuthMethod(Int_t idx)
Static method returning the method corresponding to idx.
static Bool_t GetGlobalSRPPwd()
Static method returning the global SRP password flag.
Bool_t GetUserPasswd(TString &user, TString &passwd, Bool_t &pwhash, Bool_t srppwd)
Try to get user name and passwd from several sources.
const char * GetSshUser(TString user) const
Method returning the user to be used for the ssh login (no longer supported)
static Int_t SecureRecv(TSocket *Socket, Int_t dec, Int_t KeyType, char **Out)
Receive str from sock and decode it using key indicated by key type Return number of received bytes o...
static Int_t SendRSAPublicKey(TSocket *Socket, Int_t key=0)
Receives server RSA Public key Sends local RSA public key encoded.
const char * GetProtocol() const
Int_t ClearAuth(TString &user, TString &passwd, Bool_t &pwhash)
UsrPwd client authentication code.
static void AuthError(const char *where, Int_t error)
Print error string depending on error code.
static THostAuth * HasHostAuth(const char *host, const char *user, Option_t *opt="R")
Checks if a THostAuth with exact match for {host,user} exists in the fgAuthInfo list Returns pointer ...
static const char * GetRSAPubExport(Int_t key=0)
Static method returning the RSA public keys.
void SetSecContext(TRootSecContext *ctx)
Bool_t CheckNetrc(TString &user, TString &passwd)
Try to get user name and passwd from the ~/.rootnetrc or ~/.netrc files.
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition TDatime.h:37
A doubly linked list.
Definition TList.h:38
Mother of all ROOT objects.
Definition TObject.h:42
This class implements client sockets.
Definition TSocket.h:54
Basic string class.
Definition TString.h:138
This class implements a mutex interface.
const Int_t n
Definition legend1.C:16
Int_t(* GlobusAuth_t)(ROOT::Deprecated::TAuthenticate *auth, TString &user, TString &det)
Int_t(* CheckSecCtx_t)(const char *subj, ROOT::Deprecated::TRootSecContext *ctx)
Int_t(* Krb5Auth_t)(ROOT::Deprecated::TAuthenticate *auth, TString &user, TString &det, Int_t version)
const Int_t kMAXSEC
Definition AuthConst.h:28
R__EXTERN TVirtualMutex * gAuthenticateMutex
Int_t(* SecureAuth_t)(ROOT::Deprecated::TAuthenticate *auth, const char *user, const char *passwd, const char *remote, TString &det, Int_t version)