ARC SDK
VOMSUtil.h
1 #ifndef __ARC_VOMSUTIL_H__
2 #define __ARC_VOMSUTIL_H__
3 
4 #include <vector>
5 #include <string>
6 
7 #include <arc/ArcRegex.h>
8 #include <arc/credential/VOMSAttribute.h>
9 #include <arc/credential/Credential.h>
10 
11 namespace Arc {
12 
16  typedef std::vector<std::string> VOMSTrustChain;
17 
18  typedef std::string VOMSTrustRegex;
19 
21  class VOMSACInfo {
22  public:
23  // Not all statuses are implemented
24  typedef enum {
25  Success = 0,
26  CAUnknown = (1<<0), // Signed by VOMS certificate of unknow CA
27  CertRevoked = (1<<1), // Signed by revoked VOMS certificate
28  LSCFailed = (1<<2), // Failed while matching VOMS attr. against LSC files
29  TrustFailed = (1<<2), // Failed matching VOMS attr. against specified trust list
30  X509ParsingFailed = (1<<3), // Failed while parsing at X509 level
31  ACParsingFailed = (1<<4), // Failed while parsing at AC level
32  InternalParsingFailed = (1<<5), // Failed while parsing internal VOMS structures
33  TimeValidFailed = (1<<6), // VOMS attributes are not valid yet or expired
34  IsCritical = (1<<7), // VOMS extension was marked as critical (unusual but not error)
35  ParsingError = (X509ParsingFailed | ACParsingFailed | InternalParsingFailed), // Mask to test if status represents any failure caused by failed parsing
36  ValidationError = (CAUnknown | CertRevoked | LSCFailed | TrustFailed | TimeValidFailed), // Mask to test if status represents any failure caused by validation rules
37  Error = (0xffff & ~IsCritical) // Mask to test if status represents any failure
38  } status_t;
39  std::string voname;
40  std::string holder;
41  std::string issuer;
42  std::string target;
43  std::vector<std::string> attributes;
44  Time from;
45  Time till;
46  //Period validity;
47  unsigned int status;
48  VOMSACInfo(void):from(-1),till(-1),status(0) { };
49  };
50 
52  class VOMSTrustList {
53  private:
54  std::vector<VOMSTrustChain> chains_;
55  std::vector<RegularExpression*> regexs_;
56  public:
57  VOMSTrustList(void) { };
93  VOMSTrustList(const std::vector<std::string>& encoded_list);
96  VOMSTrustList(const std::vector<VOMSTrustChain>& chains,const std::vector<VOMSTrustRegex>& regexs);
97  ~VOMSTrustList(void);
116  VOMSTrustChain& AddChain(const VOMSTrustChain& chain);
118  VOMSTrustChain& AddChain(void);
119  void AddElement(const std::vector<std::string>& encoded_list);
124  RegularExpression& AddRegex(const VOMSTrustRegex& reg);
125  int SizeChains(void) const { return chains_.size(); };
126  int SizeRegexs(void) const { return regexs_.size(); };
127  const VOMSTrustChain& GetChain(int num) const { return chains_[num]; };
128  const RegularExpression& GetRegex(int num) const { return *(regexs_[num]); };
129  };
130 
131  void InitVOMSAttribute(void);
132 
133  /* This method is used to create an AC. It is supposed
134  * to be used by the voms server
135  * @param issuer The issuer which will be used to sign the AC, it is also
136  * the voms server certificate
137  * @param issuerstack The stack of the issuer certificates that issue the
138  * voms server certificate. If the voms server certificate
139  * is issued by a root CA (self-signed), then this param
140  * is empty.
141  * @param holder The certificate of the holder of this AC. It should be
142  * parsed from the peer that launches a AC query request
143  * @param pkey The key of the holder
144  * @param fqan The AC_IETFATTR. According to the definition of voms, the fqan
145  * will be like /Role=Employee/Group=Tester/Capability=NULL
146  * @param attributes The AC_FULL_ATTRIBUTES. Accoding to the definition of voms,
147  * the attributes will be like "qualifier::name=value"
148  * @param target The list of targets which are supposed to consume this AC
149  * @param ac The generated AC
150  * @param voname The vo name
151  * @param uri The uri of this vo, together with voname, it will be
152  * as the grantor of this AC
153  * @param lifetime The lifetime of this AC
154  */
155  /*
156  int createVOMSAC(X509 *issuer, STACK_OF(X509) *issuerstack, X509 *holder,
157  EVP_PKEY *pkey, BIGNUM *serialnum,
158  std::vector<std::string> &fqan,
159  std::vector<std::string> &targets,
160  std::vector<std::string>& attributes,
161  ArcCredential::AC **ac, std::string voname,
162  std::string uri, int lifetime);
163  */
164 
180  bool createVOMSAC(std::string& codedac, Credential& issuer_cred,
181  Credential& holder_cred,
182  std::vector<std::string> &fqan,
183  std::vector<std::string> &targets,
184  std::vector<std::string>& attributes,
185  std::string &voname, std::string &uri, int lifetime);
186 
193  bool addVOMSAC(ArcCredential::AC** &aclist, std::string &acorder, std::string &decodedac);
194 
249  bool parseVOMSAC(X509* holder,
250  const std::string& ca_cert_dir,
251  const std::string& ca_cert_file,
252  const std::string& vomsdir,
253  VOMSTrustList& vomscert_trust_dn,
254  std::vector<VOMSACInfo>& output,
255  bool verify = true, bool reportall = false);
256 
259  bool parseVOMSAC(const Credential& holder_cred,
260  const std::string& ca_cert_dir,
261  const std::string& ca_cert_file,
262  const std::string& vomsdir,
263  VOMSTrustList& vomscert_trust_dn,
264  std::vector<VOMSACInfo>& output,
265  bool verify = true, bool reportall = false);
266 
268  bool parseVOMSAC(const std::string& cert_str,
269  const std::string& ca_cert_dir,
270  const std::string& ca_cert_file,
271  const std::string& vomsdir,
272  VOMSTrustList& vomscert_trust_dn,
273  std::vector<VOMSACInfo>& output,
274  bool verify = true, bool reportall = false);
275 
278  char *VOMSDecode(const char *data, int size, int *j);
279 
281  char *VOMSEncode(const char *data, int size, int *j);
282 
293  std::string getCredentialProperty(const Arc::Credential& u, const std::string& property,
294  const std::string& ca_cert_dir = std::string(""),
295  const std::string& ca_cert_file = std::string(""),
296  const std::string& vomsdir = std::string(""),
297  const std::vector<std::string>& voms_trust_list = std::vector<std::string>());
298 
299  std::string VOMSFQANToFull(const std::string& vo, const std::string& fqan);
300 
307  bool VOMSACSeqEncode(const std::string& ac_seq, std::string& asn1);
308 
314  bool VOMSACSeqEncode(const std::list<std::string> acs, std::string& asn1);
315 
318 }// namespace Arc
319 
320 #endif /* __ARC_VOMSUTIL_H__ */
321