xrootd
XrdCryptoX509Chain.hh
Go to the documentation of this file.
1 // $Id$
2 #ifndef __CRYPTO_X509CHAIN_H__
3 #define __CRYPTO_X509CHAIN_H__
4 /******************************************************************************/
5 /* */
6 /* X r d C r y p t o X 5 0 9 C h a i n . h h */
7 /* */
8 /* (c) 2005 G. Ganis , CERN */
9 /* */
10 /******************************************************************************/
11 
12 /* ************************************************************************** */
13 /* */
14 /* Chain of X509 certificates. */
15 /* */
16 /* ************************************************************************** */
17 
18 #include <XrdSut/XrdSutBucket.hh>
21 
22 // ---------------------------------------------------------------------------//
23 // //
24 // XrdCryptoX509Chain //
25 // //
26 // Light single-linked list for managing stacks of XrdCryptoX509* objects //
27 // //
28 // ---------------------------------------------------------------------------//
29 
30 //
31 // Description of options for verify
32 typedef struct {
33  int opt; // option container
34  int when; // time of verification (UTC)
35  int pathlen; // max allowed path length of chain
38 
39 const int kOptsCheckSelfSigned = 0x2; // CA ckecking option
40 
41 //
42 // Node definition
43 //
45 
46 private:
49 public:
51  { cert = c; next = n;}
53 
54  XrdCryptoX509 *Cert() const { return cert; }
55  XrdCryptoX509ChainNode *Next() const { return next; }
56 
58 };
59 
61 
63 
64  enum ESearchMode { kExact = 0, kBegin = 1, kEnd = 2 };
65 
66 public:
69  virtual ~XrdCryptoX509Chain();
70 
71  // CA status
73 
74  // Error codes
79 
80  // In case or error
81  const char *X509ChainError(EX509ChainErr e);
82  const char *LastError() const { return lastError.c_str(); }
83 
84  // Dump content
85  void Dump();
86 
87  // Access information
88  int Size() const { return size; }
89  XrdCryptoX509 *End() const { return end->Cert(); }
90  ECAStatus StatusCA() const { return statusCA; }
91  const char *CAname();
92  const char *EECname();
93  const char *CAhash();
94  const char *EEChash();
95 
96  // Modifiers
98  void PutInFront(XrdCryptoX509 *c);
99  void PushBack(XrdCryptoX509 *c);
100  void Remove(XrdCryptoX509 *c);
101  bool CheckCA(bool checkselfsigned = 1);
102  void Cleanup(bool keepCA = 0);
103  void SetStatusCA(ECAStatus st) { statusCA = st; }
104 
105  // Search
106  XrdCryptoX509 *SearchByIssuer(const char *issuer,
107  ESearchMode mode = kExact);
108  XrdCryptoX509 *SearchBySubject(const char *subject,
109  ESearchMode mode = kExact);
110 
111  // Check validity in time
112  virtual int CheckValidity(bool outatfirst = 1, int when = 0);
113 
114  // Reorder (C(n) issuer of C(n+1))
115  virtual int Reorder();
116 
117  // Verify chain
118  virtual bool Verify(EX509ChainErr &e, x509ChainVerifyOpt_t *vopt = 0);
119 
120  // Pseudo - iterator functionality
121  XrdCryptoX509 *Begin();
122  XrdCryptoX509 *Next();
123 
124 private:
125 
126 
131  int size;
138 
140  XrdCryptoX509ChainNode *FindIssuer(const char *issuer,
141  ESearchMode mode = kExact,
142  XrdCryptoX509ChainNode **p = 0);
143  XrdCryptoX509ChainNode *FindSubject(const char *subject,
144  ESearchMode mode = kExact,
145  XrdCryptoX509ChainNode **p = 0);
146  bool Verify(EX509ChainErr &e, const char *msg,
147  XrdCryptoX509::EX509Type type, int when,
148  XrdCryptoX509 *xcer, XrdCryptoX509 *xsig,
149  XrdCryptoX509Crl *crl = 0);
150 
151 };
152 
153 #endif