XrdCryptoRSA.cc

Go to the documentation of this file.
00001 // $Id: XrdCryptoRSA.cc 30949 2009-11-02 16:37:58Z ganis $
00002 
00003 const char *XrdCryptoRSACVSID = "$Id: XrdCryptoRSA.cc 30949 2009-11-02 16:37:58Z ganis $";
00004 /******************************************************************************/
00005 /*                                                                            */
00006 /*                       X r d C r y p t o R S A . c c                        */
00007 /*                                                                            */
00008 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University  */
00009 /*       All Rights Reserved. See XrdInfo.cc for complete License Terms       */
00010 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00011 /*              DE-AC03-76-SFO0515 with the Department of Energy              */
00012 /******************************************************************************/
00013 
00014 /* ************************************************************************** */
00015 /*                                                                            */
00016 /* Abstract interface for RSA PKI functionality.                              */
00017 /* Allows to plug-in modules based on different crypto implementation         */
00018 /* (OpenSSL, Botan, ...)                                                      */
00019 /*                                                                            */
00020 /* ************************************************************************** */
00021 
00022 #include <string.h>
00023 
00024 #include <XrdCrypto/XrdCryptoRSA.hh>
00025 
00026 const char *XrdCryptoRSA::cstatus[3] = { "Invalid", "Public", "Complete" };
00027 
00028 //_____________________________________________________________________________
00029 void XrdCryptoRSA::Dump()
00030 {
00031    // Check key validity
00032    ABSTRACTMETHOD("XrdCryptoRSA::Dump");
00033 }
00034 
00035 //_____________________________________________________________________________
00036 XrdCryptoRSAdata XrdCryptoRSA::Opaque()
00037 {
00038    // Return underlying key in raw format
00039    ABSTRACTMETHOD("XrdCryptoRSA::Opaque");
00040    return (XrdCryptoRSAdata)0;
00041 }
00042 
00043 //_____________________________________________________________________________
00044 int XrdCryptoRSA::GetOutlen(int)
00045 {
00046    // Get length of output
00047    ABSTRACTMETHOD("XrdCryptoRSA::GetOutlen");
00048    return 0;
00049 }
00050 
00051 //_____________________________________________________________________________
00052 int XrdCryptoRSA::GetPublen()
00053 {
00054    // Get length of public key export form
00055    ABSTRACTMETHOD("XrdCryptoRSA::GetPublen");
00056    return 0;
00057 }
00058 
00059 //_____________________________________________________________________________
00060 int XrdCryptoRSA::GetPrilen()
00061 {
00062    // Get length of private key export form
00063    ABSTRACTMETHOD("XrdCryptoRSA::GetPrilen");
00064    return 0;
00065 }
00066 
00067 //_____________________________________________________________________________
00068 int XrdCryptoRSA::ImportPublic(const char *, int)
00069 {
00070    // Abstract method to import a public key
00071    ABSTRACTMETHOD("XrdCryptoRSA::ImportPublic");
00072    return -1;
00073 }
00074 
00075 //_____________________________________________________________________________
00076 int XrdCryptoRSA::ExportPublic(char *, int)
00077 {
00078    // Abstract method to export the public key
00079    ABSTRACTMETHOD("XrdCryptoRSA::ExportPublic");
00080    return -1;
00081 }
00082 
00083 //_____________________________________________________________________________
00084 int XrdCryptoRSA::ImportPrivate(const char *, int)
00085 {
00086    // Abstract method to import a private key
00087    ABSTRACTMETHOD("XrdCryptoRSA::ImportPrivate");
00088    return -1;
00089 }
00090 
00091 //_____________________________________________________________________________
00092 int XrdCryptoRSA::ExportPrivate(char *, int)
00093 {
00094    // Abstract method to export the private key
00095    ABSTRACTMETHOD("XrdCryptoRSA::ExportPrivate");
00096    return -1;
00097 }
00098 
00099 //_____________________________________________________________________________
00100 int XrdCryptoRSA::ExportPublic(XrdOucString &s)
00101 {
00102    // Export the public key into string s
00103 
00104    int newlen = GetPublen();
00105    if (newlen > 0) {
00106       char *newbuf = new char[newlen+1];
00107       if (newbuf) {
00108          memset(newbuf, 0, newlen+1);
00109          if (ExportPublic(newbuf,newlen+1) > -1) {
00110             s = (const char *)newbuf;
00111             delete[] newbuf;
00112             return 0;
00113          }
00114          delete[] newbuf;
00115       }
00116    }
00117    return -1;
00118 }
00119 
00120 //_____________________________________________________________________________
00121 int XrdCryptoRSA::ExportPrivate(XrdOucString &s)
00122 {
00123    // Export the private key into string s
00124 
00125    int newlen = GetPrilen();
00126    if (newlen > 0) {
00127       char *newbuf = new char[newlen+1];
00128       if (newbuf) {
00129          memset(newbuf, 0, newlen+1);
00130          if (ExportPrivate(newbuf,newlen+1) > -1) {
00131             s = (const char *)newbuf;
00132             delete[] newbuf;
00133             return 0;
00134          }
00135          delete[] newbuf;
00136       }
00137    }
00138    return -1;
00139 }
00140 
00141 //_____________________________________________________________________________
00142 int XrdCryptoRSA::EncryptPrivate(const char *, int, char *, int)
00143 {
00144    // Abstract method to encrypt using the private key
00145    ABSTRACTMETHOD("XrdCryptoRSA::EncryptPrivate");
00146    return -1;
00147 }
00148 
00149 //_____________________________________________________________________________
00150 int XrdCryptoRSA::EncryptPublic(const char *, int, char *, int)
00151 {
00152    // Abstract method to encrypt using the public key
00153    ABSTRACTMETHOD("XrdCryptoRSA::EncryptPublic");
00154    return -1;
00155 }
00156 
00157 //_____________________________________________________________________________
00158 int XrdCryptoRSA::DecryptPrivate(const char *, int, char *, int)
00159 {
00160    // Abstract method to decrypt using the private key
00161    ABSTRACTMETHOD("XrdCryptoRSA::DecryptPrivate");
00162    return -1;
00163 }
00164 
00165 //_____________________________________________________________________________
00166 int XrdCryptoRSA::DecryptPublic(const char *, int, char *, int)
00167 {
00168    // Abstract method to decrypt using the public key
00169    ABSTRACTMETHOD("XrdCryptoRSA::DecryptPublic");
00170    return -1;
00171 }
00172 
00173 //_____________________________________________________________________________
00174 int XrdCryptoRSA::EncryptPrivate(XrdSutBucket &bck)
00175 {
00176    // Encrypt bucket bck using the private key
00177    // Return new bucket size, or -1 in case of error
00178    int snew = -1;
00179 
00180    int sz = GetOutlen(bck.size);
00181    char *newbuf = new char[sz];
00182    if (newbuf) {
00183       memset(newbuf, 0, sz);
00184       snew = EncryptPrivate(bck.buffer,bck.size,newbuf,sz);
00185       if (snew > -1)
00186          bck.Update(newbuf,snew);
00187    }
00188    return snew;
00189 }
00190 
00191 //_____________________________________________________________________________
00192 int XrdCryptoRSA::EncryptPublic(XrdSutBucket &bck)
00193 {
00194    // Encrypt bucket bck using the public key
00195    // Return new bucket size, or -1 in case of error
00196    int snew = -1;
00197 
00198    int sz = GetOutlen(bck.size);
00199    char *newbuf = new char[sz];
00200    if (newbuf) {
00201       memset(newbuf, 0, sz);
00202       snew = EncryptPublic(bck.buffer,bck.size,newbuf,sz);
00203       if (snew > -1)
00204          bck.Update(newbuf,snew);
00205    }
00206    return snew;
00207 }
00208 
00209 //_____________________________________________________________________________
00210 int XrdCryptoRSA::DecryptPrivate(XrdSutBucket &bck)
00211 {
00212    // Decrypt bucket bck using the private key
00213    // Return new bucket size, or -1 in case of error
00214    int snew = -1;
00215 
00216    int sz = GetOutlen(bck.size);
00217    char *newbuf = new char[sz];
00218    if (newbuf) {
00219       memset(newbuf, 0, sz);
00220       snew = DecryptPrivate(bck.buffer,bck.size,newbuf,sz);
00221       if (snew > -1)
00222          bck.Update(newbuf,snew);
00223    }
00224    return snew;
00225 }
00226 
00227 //_____________________________________________________________________________
00228 int XrdCryptoRSA::DecryptPublic(XrdSutBucket &bck)
00229 {
00230    // Decrypt bucket bck using the public key
00231    // Return new bucket size, or -1 in case of error
00232    int snew = -1;
00233 
00234    int sz = GetOutlen(bck.size);
00235    char *newbuf = new char[sz];
00236    if (newbuf) {
00237       memset(newbuf, 0, sz);
00238       snew = DecryptPublic(bck.buffer,bck.size,newbuf,sz);
00239       if (snew > -1)
00240          bck.Update(newbuf,snew);
00241    }
00242    return snew;
00243 }

Generated on Tue Jul 5 14:46:33 2011 for ROOT_528-00b_version by  doxygen 1.5.1