xrootd
XrdCryptoFactory.hh
Go to the documentation of this file.
1 // $Id$
2 #ifndef __CRYPTO_FACTORY_H__
3 #define __CRYPTO_FACTORY_H__
4 /******************************************************************************/
5 /* */
6 /* X r d C r y p t o F a c t o r y . h h */
7 /* */
8 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
9 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */
10 /* Produced by Andrew Hanushevsky for Stanford University under contract */
11 /* DE-AC03-76-SFO0515 with the Department of Energy */
12 /******************************************************************************/
13 
14 /* ************************************************************************** */
15 /* */
16 /* Abstract interface for a crypto factory */
17 /* Allows to plug-in modules based on different crypto implementation */
18 /* (OpenSSL, Botan, ...) */
19 /* */
20 /* ************************************************************************** */
21 
23 
24 #define MAXFACTORYNAMELEN 10
25 // ---------------------------------------------------------------------------//
26 //
27 // Abstract Crypto Factory
28 //
29 // ---------------------------------------------------------------------------//
30 
31 class XrdSutBucket;
32 class XrdCryptoCipher;
33 class XrdCryptoMsgDigest;
34 class XrdCryptoRSA;
35 class XrdCryptoX509;
36 class XrdCryptoX509Chain;
37 class XrdCryptoX509Crl;
38 class XrdCryptoX509Req;
39 
40 #if 1
41 //
42 // Prototypes for some Utility Functions
43 
44 // Key derivation function
45 typedef int (*XrdCryptoKDFunLen_t)();
46 typedef int (*XrdCryptoKDFun_t)(const char *pass, int plen,
47  const char *salt, int slen,
48  char *key, int klen);
49 
50 // X509 manipulation: certificate verification
52 // chain verification
54  int &errcode);
55 // chain export
56 typedef XrdSutBucket *(*XrdCryptoX509ExportChain_t)(XrdCryptoX509Chain *, bool);
57 
58 // chain to file
59 typedef int (*XrdCryptoX509ChainToFile_t)(XrdCryptoX509Chain *, const char *);
60 
61 // certificates from file parsing
62 typedef int (*XrdCryptoX509ParseFile_t)(const char *fname,
64 // certificates from bucket parsing
67 #endif
68 
70 {
71 private:
73  int fID;
74 public:
75  XrdCryptoFactory(const char *n = "Unknown", int id = -1);
76  virtual ~XrdCryptoFactory() { }
77 
78  // Set trace flags
79  virtual void SetTrace(kXR_int32 trace);
80 
81  // Get the factory name
82  char *Name() const { return (char *)&name[0]; }
83  int ID() const { return fID; }
84 
85  // Get the right factory
86  static XrdCryptoFactory *GetCryptoFactory(const char *factoryname);
87 
88  // Hook to a Key Derivation Function (PBKDF2 when possible)
89  virtual XrdCryptoKDFunLen_t KDFunLen(); // Length of buffer
90  virtual XrdCryptoKDFun_t KDFun();
91 
92  // Cipher constructors
93  virtual bool SupportedCipher(const char *t);
94  virtual XrdCryptoCipher *Cipher(const char *t, int l = 0);
95  virtual XrdCryptoCipher *Cipher(const char *t, int l, const char *k,
96  int liv, const char *iv);
97  virtual XrdCryptoCipher *Cipher(XrdSutBucket *b);
98  virtual XrdCryptoCipher *Cipher(int bits, char *pub, int lpub, const char *t = 0);
99  virtual XrdCryptoCipher *Cipher(const XrdCryptoCipher &c);
100 
101  // MsgDigest constructors
102  virtual bool SupportedMsgDigest(const char *dgst);
103  virtual XrdCryptoMsgDigest *MsgDigest(const char *dgst);
104 
105  // RSA constructors
106  virtual XrdCryptoRSA *RSA(int b = 0, int e = 0);
107  virtual XrdCryptoRSA *RSA(const char *p, int l = 0);
108  virtual XrdCryptoRSA *RSA(const XrdCryptoRSA &r);
109 
110  // X509 constructors
111  virtual XrdCryptoX509 *X509(const char *cf, const char *kf = 0);
112  virtual XrdCryptoX509 *X509(XrdSutBucket *b);
113 
114  // X509 CRL constructors
115  virtual XrdCryptoX509Crl *X509Crl(const char *crlfile, int opt = 0);
116  virtual XrdCryptoX509Crl *X509Crl(XrdCryptoX509 *cacert);
117 
118  // X509 REQ constructors
119  virtual XrdCryptoX509Req *X509Req(XrdSutBucket *bck);
120 
121  // Hooks to handle X509 certificates
128 
129  // Equality operator
130  bool operator==(const XrdCryptoFactory factory);
131 };
132 #endif