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 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00009 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00010 /* */ 00011 /* This file is part of the XRootD software suite. */ 00012 /* */ 00013 /* XRootD is free software: you can redistribute it and/or modify it under */ 00014 /* the terms of the GNU Lesser General Public License as published by the */ 00015 /* Free Software Foundation, either version 3 of the License, or (at your */ 00016 /* option) any later version. */ 00017 /* */ 00018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00020 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00021 /* License for more details. */ 00022 /* */ 00023 /* You should have received a copy of the GNU Lesser General Public License */ 00024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00025 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00026 /* */ 00027 /* The copyright holder's institutional names and contributor's names may not */ 00028 /* be used to endorse or promote products derived from this software without */ 00029 /* specific prior written permission of the institution or contributor. */ 00030 /******************************************************************************/ 00031 00032 #include <errno.h> 00033 #ifndef WIN32 00034 #include <netdb.h> 00035 #include <netinet/in.h> 00036 #include <sys/param.h> 00037 #endif 00038 #include <stdlib.h> 00039 #include <stdio.h> 00040 #include <string.h> 00041 #if defined(__CYGWIN__) || defined(__FreeBSD__) 00042 #include <sys/socket.h> 00043 #endif 00044 00045 #include "XrdSec/XrdSecEntity.hh" 00046 00047 /******************************************************************************/ 00048 /* 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 */ 00049 /******************************************************************************/ 00050 00051 //------------------------------------------------------------------------------ 00053 //------------------------------------------------------------------------------ 00054 00055 struct XrdSecBuffer 00056 { 00057 int size; 00058 char *buffer; 00059 00060 XrdSecBuffer(char *bp=0, int sz=0) : size(sz), buffer(bp), membuf(bp) {} 00061 ~XrdSecBuffer() {if (membuf) free(membuf);} 00062 00063 private: 00064 char *membuf; // Stable copy of the buffer address 00065 }; 00066 00067 //------------------------------------------------------------------------------ 00072 //------------------------------------------------------------------------------ 00073 00074 typedef XrdSecBuffer XrdSecCredentials; 00075 00076 //------------------------------------------------------------------------------ 00082 //------------------------------------------------------------------------------ 00083 00084 typedef XrdSecBuffer XrdSecParameters; 00085 00086 /******************************************************************************/ 00087 /* X r d S e c P r o t o c o l */ 00088 /******************************************************************************/ 00133 class XrdOucErrInfo; 00134 00135 class XrdSecProtocol 00136 { 00137 public: 00138 00139 //------------------------------------------------------------------------------ 00142 //------------------------------------------------------------------------------ 00143 00144 XrdSecEntity Entity; 00145 00146 //------------------------------------------------------------------------------ 00159 //------------------------------------------------------------------------------ 00160 00161 virtual int Authenticate (XrdSecCredentials *cred, 00162 XrdSecParameters **parms, 00163 XrdOucErrInfo *einfo=0)=0; 00164 00165 //------------------------------------------------------------------------------ 00178 //------------------------------------------------------------------------------ 00179 00180 virtual XrdSecCredentials *getCredentials(XrdSecParameters *parm=0, 00181 XrdOucErrInfo *einfo=0)=0; 00182 00183 //------------------------------------------------------------------------------ 00196 //------------------------------------------------------------------------------ 00197 00198 virtual int Encrypt(const char * /*inbuff*/, // Data to be encrypted 00199 int /*inlen*/, // Length of data in inbuff 00200 XrdSecBuffer ** /*outbuff*/ // Returns encrypted data 00201 ) {return -ENOTSUP;} 00202 00203 //------------------------------------------------------------------------------ 00213 //------------------------------------------------------------------------------ 00214 00215 virtual int Decrypt(const char * /*inbuff*/, // Data to be decrypted 00216 int /*inlen*/, // Length of data in inbuff 00217 XrdSecBuffer ** /*outbuff*/ // Buffer for decrypted data 00218 ) {return -ENOTSUP;} 00219 00220 //------------------------------------------------------------------------------ 00230 //------------------------------------------------------------------------------ 00231 00232 virtual int Sign(const char * /*inbuff*/, // Data to be signed 00233 int /*inlen*/, // Length of data in inbuff 00234 XrdSecBuffer ** /*outbuff*/ // Buffer for the signature 00235 ) {return -ENOTSUP;} 00236 00237 //------------------------------------------------------------------------------ 00248 //------------------------------------------------------------------------------ 00249 00250 virtual int Verify(const char * /*inbuff*/, // Data to be decrypted 00251 int /*inlen*/, // Length of data in inbuff 00252 const char * /*sigbuff*/, // Buffer for signature 00253 int /*siglen*/) // Length if signature 00254 {return -ENOTSUP;} 00255 00256 //------------------------------------------------------------------------------ 00267 //------------------------------------------------------------------------------ 00268 00269 virtual int getKey(char * /*buff*/=0, int /*size*/=0) {return -ENOTSUP;} 00270 00271 //------------------------------------------------------------------------------ 00279 //------------------------------------------------------------------------------ 00280 00281 virtual int setKey(char * /*buff*/, int /*size*/) {return -ENOTSUP;} 00282 00283 //------------------------------------------------------------------------------ 00285 //------------------------------------------------------------------------------ 00286 00287 virtual void Delete()=0; // Normally does "delete this" 00288 00289 //------------------------------------------------------------------------------ 00291 //------------------------------------------------------------------------------ 00292 00293 XrdSecProtocol(const char *pName) : Entity(pName) {} 00294 protected: 00295 00296 //------------------------------------------------------------------------------ 00298 //------------------------------------------------------------------------------ 00299 00300 virtual ~XrdSecProtocol() {} 00301 }; 00302 00303 /******************************************************************************/ 00304 /* 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 */ 00305 /******************************************************************************/ 00306 00320 //------------------------------------------------------------------------------ 00343 //------------------------------------------------------------------------------ 00344 00350 //------------------------------------------------------------------------------ 00377 //------------------------------------------------------------------------------ 00378 00391 /******************************************************************************/ 00392 /* P r o t o c o l O b j e c t M a n a g e m e n t */ 00393 /******************************************************************************/ 00394 00398 00399 /******************************************************************************/ 00400 /* X r d S e c G e t P r o t o c o l */ 00401 /* */ 00402 /* C l i e n t S i d e U S e O n l y */ 00403 /******************************************************************************/ 00404 00405 //------------------------------------------------------------------------------ 00437 //------------------------------------------------------------------------------ 00438 00450 /******************************************************************************/ 00451 /* X r d S e c S e r v i c e */ 00452 /* */ 00453 /* S e r v e r S i d e U s e O n l y */ 00454 /******************************************************************************/ 00455 00469 class XrdSecService 00470 { 00471 public: 00472 00473 //------------------------------------------------------------------------------ 00485 //------------------------------------------------------------------------------ 00486 00487 virtual const char *getParms(int &size, const char *hname=0) = 0; 00488 00489 //------------------------------------------------------------------------------ 00508 //------------------------------------------------------------------------------ 00509 00510 virtual XrdSecProtocol *getProtocol(const char *host, // In 00511 const struct sockaddr &hadr, // In 00512 const XrdSecCredentials *cred, // In 00513 XrdOucErrInfo *einfo)=0;// Out 00514 00515 //------------------------------------------------------------------------------ 00517 //------------------------------------------------------------------------------ 00518 00519 XrdSecService() {} 00520 00521 //------------------------------------------------------------------------------ 00523 //------------------------------------------------------------------------------ 00524 00525 virtual ~XrdSecService() {} 00526 }; 00527 00528 /******************************************************************************/ 00529 /* X r d g e t S e c S e r v i c e */ 00530 /******************************************************************************/ 00531 00532 //------------------------------------------------------------------------------ 00553 //------------------------------------------------------------------------------ 00554 00561 #endif