00001 #ifndef __CRYPTO_RSA_H__ 00002 #define __CRYPTO_RSA_H__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d C r y p t o R S A . h h */ 00006 /* */ 00007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* Produced by Gerri Ganis for CERN */ 00009 /* */ 00010 /* This file is part of the XRootD software suite. */ 00011 /* */ 00012 /* XRootD is free software: you can redistribute it and/or modify it under */ 00013 /* the terms of the GNU Lesser General Public License as published by the */ 00014 /* Free Software Foundation, either version 3 of the License, or (at your */ 00015 /* option) any later version. */ 00016 /* */ 00017 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00018 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00019 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00020 /* License for more details. */ 00021 /* */ 00022 /* You should have received a copy of the GNU Lesser General Public License */ 00023 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00024 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00025 /* */ 00026 /* The copyright holder's institutional names and contributor's names may not */ 00027 /* be used to endorse or promote products derived from this software without */ 00028 /* specific prior written permission of the institution or contributor. */ 00029 /******************************************************************************/ 00030 00031 /* ************************************************************************** */ 00032 /* */ 00033 /* Abstract interface for RSA PKI functionality. */ 00034 /* Allows to plug-in modules based on different crypto implementation */ 00035 /* (OpenSSL, Botan, ...) */ 00036 /* */ 00037 /* ************************************************************************** */ 00038 00039 #include "XrdSut/XrdSutBucket.hh" 00040 #include "XrdOuc/XrdOucString.hh" 00041 #include "XrdCrypto/XrdCryptoAux.hh" 00042 00043 typedef void * XrdCryptoRSAdata; 00044 00045 // ---------------------------------------------------------------------------// 00046 // 00047 // RSA interface 00048 // 00049 // ---------------------------------------------------------------------------// 00050 class XrdCryptoRSA 00051 { 00052 public: 00053 XrdCryptoRSA() { status = kInvalid; } 00054 virtual ~XrdCryptoRSA() {} 00055 00056 // Status 00057 enum ERSAStatus { kInvalid = 0, kPublic = 1, kComplete = 2}; 00058 ERSAStatus status; 00059 const char *Status(ERSAStatus t = kInvalid) const 00060 { return ((t == kInvalid) ? cstatus[status] : cstatus[t]); } 00061 00062 // Access underlying data (in opaque form) 00063 virtual XrdCryptoRSAdata Opaque(); 00064 00065 // Dump information 00066 virtual void Dump(); 00067 00068 // Validity 00069 bool IsValid() { return (status != kInvalid); } 00070 00071 // Output lengths 00072 virtual int GetOutlen(int lin); // Length of encrypted buffers 00073 virtual int GetPublen(); // Length of export public key 00074 virtual int GetPrilen(); // Length of export private key 00075 00076 // Import / Export methods 00077 virtual int ImportPublic(const char *in, int lin); 00078 virtual int ExportPublic(char *out, int lout); 00079 int ExportPublic(XrdOucString &exp); 00080 virtual int ImportPrivate(const char *in, int lin); 00081 virtual int ExportPrivate(char *out, int lout); 00082 int ExportPrivate(XrdOucString &exp); 00083 00084 // Encryption / Decryption methods 00085 virtual int EncryptPrivate(const char *in, int lin, char *out, int lout); 00086 virtual int DecryptPublic(const char *in, int lin, char *out, int lout); 00087 virtual int EncryptPublic(const char *in, int lin, char *out, int lout); 00088 virtual int DecryptPrivate(const char *in, int lin, char *out, int lout); 00089 int EncryptPrivate(XrdSutBucket &buck); 00090 int DecryptPublic (XrdSutBucket &buck); 00091 int EncryptPublic (XrdSutBucket &buck); 00092 int DecryptPrivate(XrdSutBucket &buck); 00093 00094 private: 00095 static const char *cstatus[3]; // Names of status 00096 }; 00097 00098 #endif