VOMS CC API  1.5.0
voms_api.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * Authors: Vincenzo Ciaschini - Vincenzo.Ciaschini@cnaf.infn.it
4  *
5  * Copyright (c) Members of the EGEE Collaboration. 2004-2010.
6  * See http://www.eu-egee.org/partners/ for details on the copyright holders.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  * Parts of this code may be based upon or even include verbatim pieces,
21  * originally written by other people, in which case the original header
22  * follows.
23  *
24  *********************************************************************/
25 
26 #ifndef VOMS_API_H
27 #define VOMS_API_H
28 
29 #include <fstream>
30 #include <string>
31 #include <vector>
32 
33 #define NOGLOBUS
34 extern "C" {
35 #ifndef GSSAPI_H_
36 /*
37  * Also check against _GSSAPI_H_ as that is what the Kerberos 5 code defines and
38  * what header files on some systems look for.
39  */
40 
41 #ifndef _GSSAPI_H_
42 typedef void * gss_cred_id_t;
43 typedef void * gss_ctx_id_t;
44 #endif
45 #endif
46 
47 #include <openssl/x509.h>
48 #include <openssl/bio.h>
49 #include <sys/types.h>
50 #include "newformat.h"
51 }
52 
55 struct data {
56  std::string group;
57  std::string role;
58  std::string cap;
59 };
60 
63 struct attribute {
64  std::string name;
65  std::string qualifier;
66  std::string value;
67 };
68 
69 struct attributelist {
70  std::string grantor;
71  std::vector<attribute> attributes;
72 };
73 
74 
77 enum data_type {
81 };
82 
83 struct contactdata {
87  std::string nick;
88  std::string host;
89  std::string contact;
90  std::string vo;
91  int port;
93  int version;
94 };
95 
96 class vomspriv;
97 
98 struct voms {
99  friend class vomsdata;
100  int version;
101  int siglen;
102  std::string signature;
103  std::string user;
104  std::string userca;
105  std::string server;
106  std::string serverca;
107  std::string voname;
108  std::string uri;
109  std::string date1;
110  std::string date2;
112  std::vector<data> std;
113  std::string custom;
114  /* Data below this line only makes sense if version >= 1 */
115  std::vector<std::string> fqan;
116  std::string serial;
117  /* Data below this line is private. */
118 
119 private:
120  void *realdata;
121  X509 *holder;
122 public:
123  voms(const voms &);
124  voms();
125  voms &operator=(const voms &);
126  ~voms();
127 
128 private:
129  struct vomsr *translate();
130  friend int TranslateVOMS(struct vomsdatar *vd, std::vector<voms>&v, int *error);
131 
132 public:
133  AC *GetAC();
134 
135 public:
136  std::vector<attributelist>& GetAttributes();
137  std::vector<std::string> GetTargets();
138 
139 private:
140  vomspriv *vp;
141 };
142 
147 };
148 
150  VERIFY_FULL = 0xffffffff,
151  VERIFY_NONE = 0x00000000,
152  VERIFY_DATE = 0x00000001,
153  VERIFY_TARGET = 0x00000002,
154  VERIFY_KEY = 0x00000004,
155  VERIFY_SIGN = 0x00000008,
156  VERIFY_ORDER = 0x00000010,
157  VERIFY_ID = 0x00000020,
158  VERIFY_CERTLIST = 0x00000040
159 };
160 
163 enum verror_type {
182  // VERR_IDENT,
188 };
189 
190 typedef bool (*check_sig)(X509 *, void *, verror_type &);
192 class vomsdatapriv;
193 
194 struct vomsdata {
195  private:
196  class Initializer {
197  public:
198  Initializer();
199  private:
200  Initializer(Initializer &);
201  };
202 
203  private:
204  static Initializer init;
205  std::string ca_cert_dir;
206  std::string voms_cert_dir;
207  int duration;
208  std::string ordering;
209  std::vector<contactdata> servers;
210  std::vector<std::string> targets;
211 
212  public:
215  vomsdata(std::string voms_dir = "",
216  std::string cert_dir = "");
227  bool LoadSystemContacts(std::string dir = "");
234  bool LoadUserContacts(std::string dir = "");
244  std::vector<contactdata> FindByAlias(std::string alias);
252  std::vector<contactdata> FindByVO(std::string vo);
260  void Order(std::string att);
267  void ResetOrder(void);
269  void AddTarget(std::string target);
274  std::vector<std::string> ListTargets(void);
276  void ResetTargets(void);
277  std::string ServerErrors(void);
279  bool Retrieve(X509 *cert, STACK_OF(X509) *chain,
280  recurse_type how = RECURSE_CHAIN);
289  bool Contact(std::string hostname, int port,
290  std::string servsubject,
291  std::string command);
301  bool Contact(std::string hostname, int port,
302  std::string servsubject,
303  std::string command,
304  int timeout);
316  bool ContactRaw(std::string hostname, int port,
317  std::string servsubject,
318  std::string command,
319  std::string &raw,
320  int& version);
329  bool ContactRaw(std::string hostname, int port,
330  std::string servsubject,
331  std::string command,
332  std::string &raw,
333  int& version,
334  int timeout);
345  void SetVerificationType(verify_type how);
349  void SetLifetime(int lifetime);
353  bool Import(std::string buffer);
360  bool Export(std::string &data);
367  bool DefaultData(voms &);
370  std::vector<voms> data;
373  std::string workvo;
374  std::string extra_data;
383 private:
384  bool loadfile(std::string, uid_t uid, gid_t gid);
385  bool loadfile0(std::string, uid_t uid, gid_t gid);
386  bool verifydata(std::string &message, std::string subject, std::string ca,
387  X509 *holder, voms &v);
388  bool check_cert(X509 *cert);
389  bool retrieve(X509 *cert, STACK_OF(X509) *chain, recurse_type how,
390  AC_SEQ **listnew, std::string &subject, std::string &ca,
391  X509 **holder);
392  verify_type ver_type;
393 
394  std::string serverrors;
395  std::string errmessage;
396 
397  void seterror(verror_type, std::string);
398 
399  bool check_sig_ac(X509 *, void *);
400  X509 *check(void *);
401  bool contact(const std::string&, int, const std::string&,
402  const std::string&, std::string&, std::string&,
403  std::string&, int timeout);
404  bool verifydata(AC *ac, const std::string& subject, const std::string& ca,
405  X509 *holder, voms &v);
406  bool evaluate(AC_SEQ *, const std::string&, const std::string&, X509*);
407 
408 public:
409 
410  std::string ErrorMessage(void);
413 #ifdef NOGLOBUS
414  bool RetrieveFromCtx(gss_ctx_id_t context, recurse_type how);
419  bool RetrieveFromCred(gss_cred_id_t credential, recurse_type how);
423 #endif
424 
425  bool Retrieve(X509_EXTENSION *ext);
429  bool RetrieveFromProxy(recurse_type how);
433  bool Retrieve(FILE *file, recurse_type how);
440  bool Retrieve(AC *ac);
444  ~vomsdata();
445 private:
446  // X509 *check_file(void *);
447  bool check_cert(STACK_OF(X509) *);
448  X509 *check_from_certs(AC *ac, const std::string& voname);
449  X509 *check_from_file(AC *, std::ifstream&, const std::string &vo, const std::string &filename);
450 
451 public:
452  vomsdata(const vomsdata &);
453 
454 private:
455  int retry_count;
456 
457 public:
458  void SetRetryCount(int retryCount);
459 
460 public:
461  void SetVerificationTime(time_t);
462 
463 private:
464  time_t verificationtime;
465  bool verifyac(X509 *, X509 *, AC*, time_t, voms&);
466 
467 public:
468  bool LoadCredentials(X509*, EVP_PKEY *, STACK_OF(X509) *);
469  bool ContactRESTRaw(const std::string&, int, const std::string&, std::string&, int, int);
470 
471 private:
472  bool InterpretOutput(const std::string&, std::string&);
473 
474 private:
475  vomsdatapriv *vdp;
476 };
477 
478 
479 extern "C" {
480 int getVOMSMajorVersionNumber(void);
481 int getVOMSMinorVersionNumber(void);
482 int getVOMSPatchVersionNumber(void);
483 }
484 
485 #endif
std::string custom
Definition: voms_api.h:113
std::string host
Definition: voms_api.h:88
void Order(std::string att)
std::string qualifier
Definition: voms_api.h:65
bool Export(std::string &data)
int getVOMSMajorVersionNumber(void)
std::string signature
Definition: voms_api.h:102
Definition: voms_api.h:98
std::string uri
Definition: voms_api.h:108
int getVOMSMinorVersionNumber(void)
bool RetrieveFromProxy(recurse_type how)
std::vector< std::string > GetTargets()
std::vector< contactdata > FindByAlias(std::string alias)
std::string ServerErrors(void)
std::string user
Definition: voms_api.h:103
int getVOMSPatchVersionNumber(void)
void AddTarget(std::string target)
std::vector< std::string > ListTargets(void)
verror_type
Error codes.
Definition: voms_api.h:163
AC * GetAC()
std::string name
Definition: voms_api.h:64
std::vector< attributelist > & GetAttributes()
int siglen
Definition: voms_api.h:101
std::string ErrorMessage(void)
void * gss_cred_id_t
Definition: voms_api.h:42
std::string vo
Definition: voms_api.h:90
std::string serial
Definition: voms_api.h:116
std::string value
Definition: voms_api.h:66
std::string date1
Definition: voms_api.h:109
int version
Definition: voms_api.h:100
verify_type
Definition: voms_api.h:149
void SetVerificationTime(time_t)
std::vector< voms > data
Definition: voms_api.h:370
std::string nick
Definition: voms_api.h:87
bool Retrieve(X509 *cert, STACK_OF(X509)*chain, recurse_type how=RECURSE_CHAIN)
verror_type error
Definition: voms_api.h:213
std::string userca
Definition: voms_api.h:104
std::string serverca
Definition: voms_api.h:106
std::string extra_data
Definition: voms_api.h:374
data_type type
Definition: voms_api.h:111
std::string voname
Definition: voms_api.h:107
bool ContactRESTRaw(const std::string &, int, const std::string &, std::string &, int, int)
void ResetTargets(void)
bool ContactRaw(std::string hostname, int port, std::string servsubject, std::string command, std::string &raw, int &version)
vomsdata(std::string voms_dir="", std::string cert_dir="")
std::string cap
Definition: voms_api.h:58
friend int TranslateVOMS(struct vomsdatar *vd, std::vector< voms > &v, int *error)
std::vector< std::string > fqan
Definition: voms_api.h:115
int port
Definition: voms_api.h:91
voms & operator=(const voms &)
recurse_type
Definition: voms_api.h:143
std::vector< contactdata > FindByVO(std::string vo)
bool DefaultData(voms &)
std::string grantor
Definition: voms_api.h:70
std::string contact
Definition: voms_api.h:89
bool Import(std::string buffer)
bool RetrieveFromCred(gss_cred_id_t credential, recurse_type how)
bool(* check_sig)(X509 *, void *, verror_type &)
Definition: voms_api.h:190
int version
Definition: voms_api.h:93
void SetLifetime(int lifetime)
std::string server
Definition: voms_api.h:105
bool LoadCredentials(X509 *, EVP_PKEY *, STACK_OF(X509)*)
std::string workvo
Definition: voms_api.h:373
void * gss_ctx_id_t
Definition: voms_api.h:43
std::string date2
Definition: voms_api.h:110
bool LoadSystemContacts(std::string dir="")
void SetRetryCount(int retryCount)
bool Contact(std::string hostname, int port, std::string servsubject, std::string command)
bool LoadUserContacts(std::string dir="")
std::vector< data > std
Definition: voms_api.h:112
std::vector< attribute > attributes
Definition: voms_api.h:71
std::string role
Definition: voms_api.h:57
User's characteristics: can be repeated. Generic name-value attribute : can be repeated.
Definition: voms_api.h:55
void ResetOrder(void)
std::string group
Definition: voms_api.h:56
bool RetrieveFromCtx(gss_ctx_id_t context, recurse_type how)
data_type
The type of data returned.
Definition: voms_api.h:77
void SetVerificationType(verify_type how)