00001 #ifndef __SEC_INTERFACE_H__ 00002 #define __SEC_INTERFACE_H__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d S e c I n t e r f a c e . h h */ 00006 /* */ 00007 /* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC03-76-SFO0515 with the Department of Energy */ 00011 /******************************************************************************/ 00012 00013 // $Id: XrdSecInterface.hh,v 1.11 2008/12/18 04:08:24 abh Exp $ 00014 00015 #include <errno.h> 00016 #ifndef WIN32 00017 #include <netdb.h> 00018 #include <netinet/in.h> 00019 #include <sys/param.h> 00020 #endif 00021 #include <stdlib.h> 00022 #include <stdio.h> 00023 #include <string.h> 00024 #if defined(__CYGWIN__) || defined(__FreeBSD__) 00025 #include <sys/socket.h> 00026 #endif 00027 00028 #include "XrdSec/XrdSecEntity.hh" 00029 00030 /******************************************************************************/ 00031 /* X r d S e c C r e d e n t i a l s & X r d S e c P a r a m e t e r s */ 00032 /******************************************************************************/ 00033 00034 // The following structure is used to pass security information back and forth 00035 // 00036 struct XrdSecBuffer 00037 { 00038 int size; 00039 char *buffer; 00040 00041 XrdSecBuffer(char *bp=0, int sz=0) : size(sz), buffer(bp), membuf(bp) {} 00042 ~XrdSecBuffer() {if (membuf) free(membuf);} 00043 00044 private: 00045 char *membuf; 00046 }; 00047 00048 // When the buffer is used for credentials, the start of the buffer always 00049 // holds the credential protocol name (e.g., krb4) as a string. The client 00050 // will get credentials and the size will be filled out so that the contents 00051 // of buffer can be easily transmitted to the server. 00052 // 00053 typedef XrdSecBuffer XrdSecCredentials; 00054 00055 // When the buffer is used for parameters, the contents must be interpreted 00056 // in the context that it is used. For instance, the server will send the 00057 // security configuration parameters on the initial login. The format differs 00058 // from. say, the x.500 continuation paremeters that would be sent during 00059 // PKI authentication via an "authmore" return status. 00060 // 00061 typedef XrdSecBuffer XrdSecParameters; 00062 00063 /******************************************************************************/ 00064 /* X r d S e c P r o t o c o l */ 00065 /******************************************************************************/ 00066 00067 // The XrdSecProtocol is used to generate authentication credentials and to 00068 // authenticate those credentials. For example, When a server indicates 00069 // that authentication is needed (i.e., it returns security parameters), the 00070 // client must call XrdSecgetProtocol() to get an appropriate XrdSecProtocol 00071 // (i.e., one specific to the authentication protocol that needs to be used). 00072 // Then the client can use the first form getCredentials() to generate the 00073 // appropriate identification information. On subsequent calls in response to 00074 // "authmore" the client must use the second form, providing the additional 00075 // parameters the the server sends. The server uses Authenticate() to verify 00076 // the credentials. When XrdOucErrInfo is null (as it will usually be), error 00077 // messages are routed to standard error. So, for example, a client would 00078 00079 // 1) Call XrdSecGetProtocol() to get an appropriate XrdSecProtocol 00080 // (i.e., one specific to the authentication protocol that needs to be used). 00081 // Note that successive calls to XrdSecGetProtocol() using the same 00082 // XrdSecParameters will use the subsequent protocol named in the list of 00083 // protocols that the server returned. Failure is indicated when the list 00084 // is exhausted or none of the protocols apply (which exhausts the list). 00085 00086 00087 // 2) Call getCredentials() without supplying any parameters so as to 00088 // generate identification information and send them to the server. 00089 00090 // 3) If the server indicates "authmore", call getCredentials() supplying 00091 // the additional parameters sent by the server. The returned credentials 00092 // are then sent to the server using the "authneticate" request code. 00093 00094 // 4) Repeat step (3) as often as "authmore" is requested by the server. 00095 00096 // The server uses Authenticate() to verify the credentials and getParms() 00097 // to generate initial parameters to start the authentication process. 00098 00099 // When XrdOucErrInfo is null (as it will usually be), error messages are 00100 // are routed to standard error. 00101 00102 // Server-side security is handled by the XrdSecServer object and, while 00103 // it uses XrdSecProtocol objects to perform authentication, the XrdSecServer 00104 // object is used to initialize the security environment and to generate 00105 // the appropriate protocol objects at run-time. See XrdSecServer.hh. 00106 00107 // MT Requirements: Must be MT_Safe. 00108 00109 class XrdOucErrInfo; 00110 00111 class XrdSecProtocol 00112 { 00113 public: 00114 00115 // The following structure holds the entity's identification. It is filled 00116 // in by a successful call to Authenticate(). 00117 // 00118 XrdSecEntity Entity; 00119 00120 // Authenticate credentials supplied by the client or server. Upon success, 00121 // the XrdSecIdentity structure is completed. The method returns: 00122 // 00123 // > 0 -> parms present (more authentication needed) 00124 // = 0 -> client present (authentication suceeded) 00125 // < 0 -> einfo present (error has occured) 00126 // 00127 virtual int Authenticate (XrdSecCredentials *cred, 00128 XrdSecParameters **parms, 00129 XrdOucErrInfo *einfo=0)=0; 00130 00131 // Generate credentials to be used in the authentication process. Upon 00132 // success, return a credentials object. Upon failure, returns null and 00133 // einfo, if present, has the reason for the failure. 00134 // 00135 virtual XrdSecCredentials *getCredentials(XrdSecParameters *parm=0, 00136 XrdOucErrInfo *einfo=0)=0; 00137 00138 // Encrypt data in inbuff and place it in outbuff. 00139 // 00140 // Returns: < 0 Failed, the return value is -errno of the reason. Typically, 00141 // -EINVAL - one or more arguments are invalid. 00142 // -NOTSUP - encryption not supported by the protocol 00143 // -EOVERFLOW - outbuff is too small to hold result 00144 // -ENOENT - Context not innitialized 00145 // = 0 Success, outbuff contains a pointer to the encrypted data. 00146 // 00147 virtual int Encrypt(const char * /*inbuff*/, // Data to be encrypted 00148 int /*inlen*/, // Length of data in inbuff 00149 XrdSecBuffer ** /*outbuff*/ // Returns encrypted data 00150 ) {return -ENOTSUP;} 00151 00152 // Decrypt data in inbuff and place it in outbuff. 00153 // 00154 // Returns: < 0 Failed,the return value is -errno (see Encrypt). 00155 // = 0 Success, outbuff contains a pointer to the encrypted data. 00156 // 00157 virtual int Decrypt(const char * /*inbuff*/, // Data to be decrypted 00158 int /*inlen*/, // Length of data in inbuff 00159 XrdSecBuffer ** /*outbuff*/ // Buffer for decrypted data 00160 ) {return -ENOTSUP;} 00161 00162 // Sign data in inbuff and place the signiture in outbuff. 00163 // 00164 // Returns: < 0 Failed, returned value is -errno (see Encrypt). 00165 // = 0 Success, the return value is the length of the signature 00166 // placed in outbuff. 00167 // 00168 virtual int Sign(const char * /*inbuff*/, // Data to be signed 00169 int /*inlen*/, // Length of data in inbuff 00170 XrdSecBuffer ** /*outbuff*/ // Buffer for the signature 00171 ) {return -ENOTSUP;} 00172 00173 // Verify a signature 00174 // 00175 // Returns: < 0 Failed, returned value is -errno (see Encrypt). 00176 // = 0 Signature matches the value in inbuff. 00177 // > 0 Failed to verify, signature does not match inbuff data. 00178 // 00179 virtual int Verify(const char * /*inbuff*/, // Data to be decrypted 00180 int /*inlen*/, // Length of data in inbuff 00181 const char * /*sigbuff*/, // Buffer for signature 00182 int /*siglen*/) // Length if signature 00183 {return -ENOTSUP;} 00184 00185 // Get the current encryption key 00186 // 00187 // Returns: < 0 Failed, returned value if -errno (see Encrypt) 00188 // >= 0 The size of the encyption key. The supplied buffer of length 00189 // size hold the key. If the buffer address is 0, only the 00190 // size of the key is returned. 00191 // 00192 virtual int getKey(char * /*buff*/=0, int /*size*/=0) {return -ENOTSUP;} 00193 00194 // Set the current encryption key 00195 // 00196 // Returns: < 0 Failed, returned value if -errno (see Encrypt) 00197 // 0 The new key has been set. 00198 // 00199 virtual int setKey(char * /*buff*/, int /*size*/) {return -ENOTSUP;} 00200 00201 // DO NOT use C++ delete() on this object. Since the same compiler may not 00202 // have been used in constructing all shared libraries, you must use the object 00203 // specific Delete() method to insure that the object creator's delete is used. 00204 // 00205 virtual void Delete()=0; // Normally does "delete this" 00206 00207 XrdSecProtocol() {} 00208 protected: 00209 00210 virtual ~XrdSecProtocol() {} 00211 }; 00212 00213 /******************************************************************************/ 00214 /* P r o t o c o l N a m i n g C o n v e n t i o n s */ 00215 /******************************************************************************/ 00216 00217 // Each specific protocol resides in a shared library named "libXrdSec<p>.so" 00218 // where <p> is the protocol identifier (e.g., krb5, gsi, etc). The library 00219 // contains a class derived from the XrdSecProtocol object. The library must 00220 // also contain a two extern "C" functions: 00221 // 1) XrdSec<p>Init() - for one-time protocol ininitialization, and 00222 // 2) XrdSec<p>Object() - for protocol object instantiation. 00223 // 00224 // extern "C" {char *XrdSecProtocol<p>Init (const char who, 00225 // const char *parms, 00226 // XrdOucErrInfo *einfo); 00227 // } 00228 // Is used by the dynamic protocol loader to initialize the protocol when the 00229 // shared library is loaded. Parmater who contains 'c' when called on the 00230 // client side and 's' when called on the server side. For client initialization, 00231 // the parms is null. For server size initialization, parms contains the 00232 // parameters specified in the configuration file. The protocol must return 00233 // the parameters it needs to have sent to the client during the initial 00234 // authentication handshake. If no parameters need to be sent, it must return 00235 // the null string. If initialization fails, null must be returned and einfo 00236 // must contain the reason for the failure. The storage occupied by the returned 00237 // string is not freed by the dynamic loader; therefore, constant strings can 00238 // be returned. 00239 00240 // MT Requirements: None. Function called once in single-thread mode. 00241 00242 // extern "C" { 00243 // XrdSecProtocol *XrdSecProtocol<p>Object(const char who, 00244 // const char *hostname, 00245 // const struct sockaddr &netaddr, 00246 // const char *parms, 00247 // XrdOucErrInfo *einfo); 00248 // } 00249 // Is used by the dynamic protocol loader to obtain an instance of the 00250 // XrdSecProtocol object. Argument who will contain 'c' for client-side calls 00251 // and 's' for server-side calls. When who = 'c' then parms contains the parms 00252 // supplied by the protocol at server-side initialization time (see the 00253 // function Xrdsec<p>Init*(, explained above). When who = 's', parms is null. 00254 00255 // Warning! The protocol *must* allow both 'c' and 's' calls to occur within 00256 // the same execution context. This occurs when a server acts like a client. 00257 00258 // The naming conventions were chosen to avoid platform dependent run-time 00259 // loaders that resolve all addresses with the same name in all shared libraries 00260 // to the first address with the same name encountered by the run-time loader. 00261 00262 // MT Requirements: Must be MT_Safe. 00263 00264 /******************************************************************************/ 00265 /* X r d S e c G e t P r o t o c o l */ 00266 /* */ 00267 /* C l i e n t S i d e U S e O n l y */ 00268 /******************************************************************************/ 00269 00270 // The following external routine creates a security context and returns an 00271 // XrdSecProtocol object to be used for authentication purposes. The caller 00272 // provides the host name and IP address of the remote connection along with 00273 // any parameters provided by the server. A null return means an error occured. 00274 // Error messages are sent to standard error unless and XrdOucErrInfo class is 00275 // provided to capture the message. There should be one protocol object per 00276 // physical TCP/IP connection. 00277 00278 // When the connection is closed, the protocol's Delete() method should be 00279 // called to properly delete the object. 00280 // 00281 extern "C" 00282 { 00283 extern XrdSecProtocol *XrdSecGetProtocol(const char *hostname, 00284 const struct sockaddr &netaddr, 00285 XrdSecParameters &parms, 00286 XrdOucErrInfo *einfo=0); 00287 } 00288 00289 // MT Requirements: Must be MT_Safe. 00290 00291 /******************************************************************************/ 00292 /* X r d S e c S e r v i c e */ 00293 /* */ 00294 /* S e r v e r S i d e U s e O n l y */ 00295 /******************************************************************************/ 00296 00297 // The XrdSecService object is the the object that the server uses to obtain 00298 // parameters to be passed to the client on initial contact and to create the 00299 // appropriate protocol on the initial receipt of the client's credentials. 00300 // Server-side processing is a bit more complicated because the set of valid 00301 // protocols needs to be configured and that configuration needs to be supplied 00302 // to the client so that both can agree on a compatible protocol. This object 00303 // is created via a call to XrdSecgetService, defined later on. 00304 00305 class XrdSecService 00306 { 00307 public: 00308 00309 // = 0 -> No security parameters need to be supplied to the client. 00310 // This implies that authentication need not occur. 00311 // ! 0 -> Address of the parameter string (which may be host-specigfic if hname 00312 // was supplied). Ths length of the string is returned in size. 00313 // 00314 virtual const char *getParms(int &size, const char *hname=0) = 0; 00315 00316 // = 0 -> No protocol can be returned (einfo has the reason) 00317 // ! 0 -> Address of protocol object is bing returned. If cred is null, 00318 // a host protocol object is returned if so allowed. 00319 // 00320 virtual XrdSecProtocol *getProtocol(const char *host, // In 00321 const struct sockaddr &hadr, // In 00322 const XrdSecCredentials *cred, // In 00323 XrdOucErrInfo *einfo)=0;// Out 00324 00325 XrdSecService() {} 00326 virtual ~XrdSecService() {} 00327 }; 00328 00329 // MT Requirements: Must be MT_Safe. 00330 00331 /******************************************************************************/ 00332 /* X r d g e t S e c S e r v i c e */ 00333 /******************************************************************************/ 00334 00335 // The XrdSecSgetService function is calle during server initialization to 00336 // obtain the XrdSecService object. This object is used to control server-side 00337 // authentication. 00338 // 00339 class XrdSysLogger; 00340 00341 extern "C" 00342 { 00343 extern XrdSecService *XrdSecgetService(XrdSysLogger *lp, const char *cfn); 00344 } 00345 00346 // MT Requirements: None. Function called once in single-thread mode. 00347 #endif
1.7.1