xrootd
XrdCryptoX509Chain.hh
Go to the documentation of this file.
1 #ifndef __CRYPTO_X509CHAIN_H__
2 #define __CRYPTO_X509CHAIN_H__
3 /******************************************************************************/
4 /* */
5 /* X r d C r y p t o X 5 0 9 C h a i n . h h */
6 /* */
7 /* (c) 2005 G. Ganis , CERN */
8 /* */
9 /* This file is part of the XRootD software suite. */
10 /* */
11 /* XRootD is free software: you can redistribute it and/or modify it under */
12 /* the terms of the GNU Lesser General Public License as published by the */
13 /* Free Software Foundation, either version 3 of the License, or (at your */
14 /* option) any later version. */
15 /* */
16 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
17 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
18 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
19 /* License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public License */
22 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
23 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
24 /* */
25 /* The copyright holder's institutional names and contributor's names may not */
26 /* be used to endorse or promote products derived from this software without */
27 /* specific prior written permission of the institution or contributor. */
28 /* */
29 /******************************************************************************/
30 
31 /* ************************************************************************** */
32 /* */
33 /* Chain of X509 certificates. */
34 /* */
35 /* ************************************************************************** */
36 
37 #include "XrdSut/XrdSutBucket.hh"
40 
41 // ---------------------------------------------------------------------------//
42 // //
43 // XrdCryptoX509Chain //
44 // //
45 // Light single-linked list for managing stacks of XrdCryptoX509* objects //
46 // //
47 // ---------------------------------------------------------------------------//
48 
49 //
50 // Description of options for verify
51 typedef struct {
52  int opt; // option container
53  int when; // time of verification (UTC)
54  int pathlen; // max allowed path length of chain
57 
58 const int kOptsCheckSelfSigned = 0x2; // CA ckecking option
59 
60 //
61 // Node definition
62 //
64 
65 private:
68 public:
70  { cert = c; next = n;}
72 
73  XrdCryptoX509 *Cert() const { return cert; }
74  XrdCryptoX509ChainNode *Next() const { return next; }
75 
77 };
78 
80 
82 
83  enum ESearchMode { kExact = 0, kBegin = 1, kEnd = 2 };
84 
85 public:
88  virtual ~XrdCryptoX509Chain();
89 
90  // CA status
92 
93  // Error codes
98 
99  // In case or error
100  const char *X509ChainError(EX509ChainErr e);
101  const char *LastError() const { return lastError.c_str(); }
102 
103  // Dump content
104  void Dump();
105 
106  // Access information
107  int Size() const { return size; }
108  XrdCryptoX509 *End() const { return end->Cert(); }
109  ECAStatus StatusCA() const { return statusCA; }
110  const char *CAname();
111  const char *EECname();
112  const char *CAhash();
113  const char *EEChash();
114 
115  // Modifiers
117  void PutInFront(XrdCryptoX509 *c);
118  void PushBack(XrdCryptoX509 *c);
119  void Remove(XrdCryptoX509 *c);
120  bool CheckCA(bool checkselfsigned = 1);
121  void Cleanup(bool keepCA = 0);
122  void SetStatusCA(ECAStatus st) { statusCA = st; }
123 
124  // Search
125  XrdCryptoX509 *SearchByIssuer(const char *issuer,
126  ESearchMode mode = kExact);
127  XrdCryptoX509 *SearchBySubject(const char *subject,
128  ESearchMode mode = kExact);
129 
130  // Check validity in time
131  virtual int CheckValidity(bool outatfirst = 1, int when = 0);
132 
133  // Reorder (C(n) issuer of C(n+1))
134  virtual int Reorder();
135 
136  // Verify chain
137  virtual bool Verify(EX509ChainErr &e, x509ChainVerifyOpt_t *vopt = 0);
138 
139  // Pseudo - iterator functionality
140  XrdCryptoX509 *Begin();
141  XrdCryptoX509 *Next();
142 
143 private:
144 
145 
150  int size;
157 
159  XrdCryptoX509ChainNode *FindIssuer(const char *issuer,
160  ESearchMode mode = kExact,
161  XrdCryptoX509ChainNode **p = 0);
162  XrdCryptoX509ChainNode *FindSubject(const char *subject,
163  ESearchMode mode = kExact,
164  XrdCryptoX509ChainNode **p = 0);
165  bool Verify(EX509ChainErr &e, const char *msg,
166  XrdCryptoX509::EX509Type type, int when,
167  XrdCryptoX509 *xcer, XrdCryptoX509 *xsig,
168  XrdCryptoX509Crl *crl = 0);
169 
170 };
171 
172 #endif