xrootd
XrdCryptoFactory.hh
Go to the documentation of this file.
00001 #ifndef __CRYPTO_FACTORY_H__
00002 #define __CRYPTO_FACTORY_H__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                 X r d C r y p t o F a c t o r y . 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 a crypto factory                                    */
00034 /* Allows to plug-in modules based on different crypto implementation         */
00035 /* (OpenSSL, Botan, ...)                                                      */
00036 /*                                                                            */
00037 /* ************************************************************************** */
00038 
00039 #include "XrdCrypto/XrdCryptoAux.hh"
00040 
00041 #define MAXFACTORYNAMELEN  10
00042 // ---------------------------------------------------------------------------//
00043 //
00044 // Abstract Crypto Factory
00045 //
00046 // ---------------------------------------------------------------------------//
00047 
00048 class XrdSutBucket;
00049 class XrdCryptoCipher;
00050 class XrdCryptoMsgDigest;
00051 class XrdCryptoRSA;
00052 class XrdCryptoX509;
00053 class XrdCryptoX509Chain;
00054 class XrdCryptoX509Crl;
00055 class XrdCryptoX509Req;
00056 
00057 //
00058 // Prototypes for some Utility Functions
00059 
00060 // Key derivation function
00061 typedef int (*XrdCryptoKDFunLen_t)();
00062 typedef int (*XrdCryptoKDFun_t)(const char *pass, int plen,
00063                                 const char *salt, int slen,
00064                                 char *key, int klen);
00065 
00066 // X509 manipulation: certificate verification
00067 typedef bool (*XrdCryptoX509VerifyCert_t)(XrdCryptoX509 *c, XrdCryptoX509 *r);
00068 // chain verification
00069 typedef bool (*XrdCryptoX509VerifyChain_t)(XrdCryptoX509Chain *chain,
00070                                            int &errcode);
00071 // chain export
00072 typedef XrdSutBucket *(*XrdCryptoX509ExportChain_t)(XrdCryptoX509Chain *, bool);
00073 
00074 // chain to file
00075 typedef int (*XrdCryptoX509ChainToFile_t)(XrdCryptoX509Chain *, const char *);
00076 
00077 // certificates from file parsing
00078 typedef int (*XrdCryptoX509ParseFile_t)(const char *fname,
00079                                         XrdCryptoX509Chain *);
00080 // certificates from bucket parsing
00081 typedef int (*XrdCryptoX509ParseBucket_t)(XrdSutBucket *,
00082                                           XrdCryptoX509Chain *);
00083 
00084 class XrdCryptoFactory
00085 {
00086 private:
00087    char    name[MAXFACTORYNAMELEN];
00088    int     fID;
00089 public:
00090    XrdCryptoFactory(const char *n = "Unknown", int id = -1);
00091    virtual ~XrdCryptoFactory() { }
00092 
00093    // Set trace flags
00094    virtual void SetTrace(kXR_int32 trace);
00095 
00096    // Get the factory name
00097    char *Name() const { return (char *)&name[0]; }
00098    int   ID() const { return fID; }
00099 
00100    // Get the right factory
00101    static XrdCryptoFactory *GetCryptoFactory(const char *factoryname);
00102    
00103    // Any possible notification
00104    virtual void Notify() { }
00105 
00106    // Hook to a Key Derivation Function (PBKDF2 when possible)
00107    virtual XrdCryptoKDFunLen_t KDFunLen(); // Length of buffer
00108    virtual XrdCryptoKDFun_t KDFun();
00109 
00110    // Cipher constructors
00111    virtual bool SupportedCipher(const char *t);
00112    virtual XrdCryptoCipher *Cipher(const char *t, int l = 0);
00113    virtual XrdCryptoCipher *Cipher(const char *t, int l, const char *k, 
00114                                    int liv, const char *iv);
00115    virtual XrdCryptoCipher *Cipher(XrdSutBucket *b);
00116    virtual XrdCryptoCipher *Cipher(int bits, char *pub, int lpub, const char *t = 0);
00117    virtual XrdCryptoCipher *Cipher(const XrdCryptoCipher &c);
00118 
00119    // MsgDigest constructors
00120    virtual bool SupportedMsgDigest(const char *dgst);
00121    virtual XrdCryptoMsgDigest *MsgDigest(const char *dgst);
00122 
00123    // RSA constructors
00124    virtual XrdCryptoRSA *RSA(int b = 0, int e = 0);
00125    virtual XrdCryptoRSA *RSA(const char *p, int l = 0);
00126    virtual XrdCryptoRSA *RSA(const XrdCryptoRSA &r);
00127 
00128    // X509 constructors
00129    virtual XrdCryptoX509 *X509(const char *cf, const char *kf = 0);
00130    virtual XrdCryptoX509 *X509(XrdSutBucket *b);
00131 
00132    // X509 CRL constructors
00133    virtual XrdCryptoX509Crl *X509Crl(const char *crlfile, int opt = 0);
00134    virtual XrdCryptoX509Crl *X509Crl(XrdCryptoX509 *cacert);
00135 
00136    // X509 REQ constructors
00137    virtual XrdCryptoX509Req *X509Req(XrdSutBucket *bck);
00138 
00139    // Hooks to handle X509 certificates
00140    virtual XrdCryptoX509VerifyCert_t X509VerifyCert();
00141    virtual XrdCryptoX509VerifyChain_t X509VerifyChain();
00142    virtual XrdCryptoX509ParseFile_t X509ParseFile();
00143    virtual XrdCryptoX509ParseBucket_t X509ParseBucket();
00144    virtual XrdCryptoX509ExportChain_t X509ExportChain();
00145    virtual XrdCryptoX509ChainToFile_t X509ChainToFile();
00146 
00147    // Equality operator
00148    bool operator==(const XrdCryptoFactory factory);
00149 };
00150 #endif