VOMS CC API  1.5.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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);
315  bool ContactRaw(std::string hostname, int port,
316  std::string servsubject,
317  std::string command,
318  std::string &raw,
319  int& version);
328  bool ContactRaw(std::string hostname, int port,
329  std::string servsubject,
330  std::string command,
331  std::string &raw,
332  int& version,
333  int timeout);
343  void SetVerificationType(verify_type how);
347  void SetLifetime(int lifetime);
351  bool Import(std::string buffer);
358  bool Export(std::string &data);
365  bool DefaultData(voms &);
368  std::vector<voms> data;
371  std::string workvo;
372  std::string extra_data;
381 private:
382  bool loadfile(std::string, uid_t uid, gid_t gid);
383  bool loadfile0(std::string, uid_t uid, gid_t gid);
384  bool verifydata(std::string &message, std::string subject, std::string ca,
385  X509 *holder, voms &v);
386  bool check_cert(X509 *cert);
387  bool retrieve(X509 *cert, STACK_OF(X509) *chain, recurse_type how,
388  AC_SEQ **listnew, std::string &subject, std::string &ca,
389  X509 **holder);
390  verify_type ver_type;
391 
392  std::string serverrors;
393  std::string errmessage;
394 
395  void seterror(verror_type, std::string);
396 
397  bool check_sig_ac(X509 *, void *);
398  X509 *check(void *);
399  bool contact(const std::string&, int, const std::string&,
400  const std::string&, std::string&, std::string&,
401  std::string&, int timeout);
402  bool verifydata(AC *ac, const std::string& subject, const std::string& ca,
403  X509 *holder, voms &v);
404  bool evaluate(AC_SEQ *, const std::string&, const std::string&, X509*);
405 
406 public:
407 
408  std::string ErrorMessage(void);
411 #ifdef NOGLOBUS
412  bool RetrieveFromCtx(gss_ctx_id_t context, recurse_type how);
417  bool RetrieveFromCred(gss_cred_id_t credential, recurse_type how);
421 #endif
422 
423  bool Retrieve(X509_EXTENSION *ext);
427  bool RetrieveFromProxy(recurse_type how);
431  bool Retrieve(FILE *file, recurse_type how);
438  bool Retrieve(AC *ac);
442  ~vomsdata();
443 private:
444  // X509 *check_file(void *);
445  bool check_cert(STACK_OF(X509) *);
446  X509 *check_from_certs(AC *ac, const std::string& voname);
447  X509 *check_from_file(AC *, std::ifstream&, const std::string &vo, const std::string &filename);
448 
449 public:
450  vomsdata(const vomsdata &);
451 
452 private:
453  int retry_count;
454 
455 public:
456  void SetRetryCount(int retryCount);
457 
458 public:
459  void SetVerificationTime(time_t);
460 
461 private:
462  time_t verificationtime;
463  bool verifyac(X509 *, X509 *, AC*, time_t, voms&);
464 
465 public:
466  bool LoadCredentials(X509*, EVP_PKEY *, STACK_OF(X509) *);
467  bool ContactRESTRaw(const std::string&, int, const std::string&, std::string&, int, int);
468 
469 private:
470  bool InterpretOutput(const std::string&, std::string&);
471 
472 private:
473  vomsdatapriv *vdp;
474 };
475 
476 
477 extern "C" {
478 int getVOMSMajorVersionNumber(void);
479 int getVOMSMinorVersionNumber(void);
480 int getVOMSPatchVersionNumber(void);
481 }
482 
483 #endif