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 extern "C" {
34 #ifndef GSSAPI_H_
35 /*
36  * Also check against _GSSAPI_H_ as that is what the Kerberos 5 code defines and
37  * what header files on some systems look for.
38  */
39 
40 #ifndef _GSSAPI_H_
41 typedef void * gss_cred_id_t;
42 typedef void * gss_ctx_id_t;
43 #endif
44 #endif
45 
46 #include <openssl/x509.h>
47 #include <openssl/bio.h>
48 #include <sys/types.h>
49 #include "newformat.h"
50 }
51 
54 struct data {
55  std::string group;
56  std::string role;
57  std::string cap;
58 };
59 
62 struct attribute {
63  std::string name;
64  std::string qualifier;
65  std::string value;
66 };
67 
68 struct attributelist {
69  std::string grantor;
70  std::vector<attribute> attributes;
71 };
72 
73 
76 enum data_type {
80 };
81 
82 struct contactdata {
86  std::string nick;
87  std::string host;
88  std::string contact;
89  std::string vo;
90  int port;
92  int version;
93 };
94 
95 class vomspriv;
96 
97 struct voms {
98  friend class vomsdata;
99  int version;
100  int siglen;
101  std::string signature;
102  std::string user;
103  std::string userca;
104  std::string server;
105  std::string serverca;
106  std::string voname;
107  std::string uri;
108  std::string date1;
109  std::string date2;
111  std::vector<data> std;
112  std::string custom;
113  /* Data below this line only makes sense if version >= 1 */
114  std::vector<std::string> fqan;
115  std::string serial;
116  /* Data below this line is private. */
117 
118 private:
119  void *realdata;
120  X509 *holder;
121 public:
122  voms(const voms &);
123  voms();
124  voms &operator=(const voms &);
125  ~voms();
126 
127 private:
128  struct vomsr *translate();
129  friend int TranslateVOMS(struct vomsdatar *vd, std::vector<voms>&v, int *error);
130 
131 public:
132  AC *GetAC();
133 
134 public:
135  std::vector<attributelist>& GetAttributes();
136  std::vector<std::string> GetTargets();
137 
138 private:
139  vomspriv *vp;
140 };
141 
146 };
147 
149  VERIFY_FULL = 0xffffffff,
150  VERIFY_NONE = 0x00000000,
151  VERIFY_DATE = 0x00000001,
152  VERIFY_TARGET = 0x00000002,
153  VERIFY_KEY = 0x00000004,
154  VERIFY_SIGN = 0x00000008,
155  VERIFY_ORDER = 0x00000010,
156  VERIFY_ID = 0x00000020,
157  VERIFY_CERTLIST = 0x00000040
158 };
159 
162 enum verror_type {
181  // VERR_IDENT,
187 };
188 
189 typedef bool (*check_sig)(X509 *, void *, verror_type &);
191 class vomsdatapriv;
192 
193 struct vomsdata {
194  private:
195  class Initializer {
196  public:
197  Initializer();
198  private:
199  Initializer(Initializer &);
200  };
201 
202  private:
203  static Initializer init;
204  std::string ca_cert_dir;
205  std::string voms_cert_dir;
206  int duration;
207  std::string ordering;
208  std::vector<contactdata> servers;
209  std::vector<std::string> targets;
210 
211  public:
214  static void SkipSslInitialization();
215 
216  vomsdata(std::string voms_dir = "",
217  std::string cert_dir = "");
228  bool LoadSystemContacts(std::string dir = "");
235  bool LoadUserContacts(std::string dir = "");
245  std::vector<contactdata> FindByAlias(std::string alias);
253  std::vector<contactdata> FindByVO(std::string vo);
261  void Order(std::string att);
268  void ResetOrder(void);
270  void AddTarget(std::string target);
275  std::vector<std::string> ListTargets(void);
277  void ResetTargets(void);
278  std::string ServerErrors(void);
280  bool Retrieve(X509 *cert, STACK_OF(X509) *chain,
281  recurse_type how = RECURSE_CHAIN);
290  bool Contact(std::string hostname, int port,
291  std::string servsubject,
292  std::string command);
302  bool Contact(std::string hostname, int port,
303  std::string servsubject,
304  std::string command,
305  int timeout);
317  bool ContactRaw(std::string hostname, int port,
318  std::string servsubject,
319  std::string command,
320  std::string &raw,
321  int& version);
330  bool ContactRaw(std::string hostname, int port,
331  std::string servsubject,
332  std::string command,
333  std::string &raw,
334  int& version,
335  int timeout);
346  void SetVerificationType(verify_type how);
350  void SetLifetime(int lifetime);
354  bool Import(std::string buffer);
361  bool Export(std::string &data);
368  bool DefaultData(voms &);
371  std::vector<voms> data;
374  std::string workvo;
375  std::string extra_data;
384 private:
385  bool loadfile(std::string, uid_t uid, gid_t gid);
386  bool loadfile0(std::string, uid_t uid, gid_t gid);
387  bool verifydata(std::string &message, std::string subject, std::string ca,
388  X509 *holder, voms &v);
389  bool check_cert(X509 *cert);
390  bool retrieve(X509 *cert, STACK_OF(X509) *chain, recurse_type how,
391  AC_SEQ **listnew, std::string &subject, std::string &ca,
392  X509 **holder);
393  verify_type ver_type;
394 
395  std::string serverrors;
396  std::string errmessage;
397 
398  void seterror(verror_type, std::string);
399 
400  bool check_sig_ac(X509 *, void *);
401  X509 *check(void *);
402  bool contact(const std::string&, int, const std::string&,
403  const std::string&, std::string&, std::string&,
404  std::string&, int timeout);
405  bool verifydata(AC *ac, const std::string& subject, const std::string& ca,
406  X509 *holder, voms &v);
407  bool evaluate(AC_SEQ *, const std::string&, const std::string&, X509*);
408 
409 public:
410 
411  std::string ErrorMessage(void);
414  bool RetrieveFromCtx(gss_ctx_id_t context, recurse_type how);
419  bool RetrieveFromCred(gss_cred_id_t credential, recurse_type how);
424  bool Retrieve(X509_EXTENSION *ext);
428  bool RetrieveFromProxy(recurse_type how);
432  bool Retrieve(FILE *file, recurse_type how);
439  bool Retrieve(AC *ac);
443  ~vomsdata();
444 private:
445  // X509 *check_file(void *);
446  bool check_cert(STACK_OF(X509) *);
447  X509 *check_from_certs(AC *ac, const std::string& voname);
448  X509 *check_from_file(AC *, std::ifstream&, const std::string &vo, const std::string &filename);
449 
450 public:
451  vomsdata(const vomsdata &);
452 
453 private:
454  int retry_count;
455 
456 public:
457  void SetRetryCount(int retryCount);
458 
459 public:
460  void SetVerificationTime(time_t);
461 
462 private:
463  time_t verificationtime;
464  bool verifyac(X509 *, X509 *, AC*, time_t, voms&);
465 
466 public:
467  bool LoadCredentials(X509*, EVP_PKEY *, STACK_OF(X509) *);
468  bool ContactRESTRaw(const std::string&, int, const std::string&, std::string&, int, int);
469 
470 private:
471  bool InterpretOutput(const std::string&, std::string&);
472 
473 private:
474  vomsdatapriv *vdp;
475 };
476 
477 
478 extern "C" {
479 int getVOMSMajorVersionNumber(void);
480 int getVOMSMinorVersionNumber(void);
481 int getVOMSPatchVersionNumber(void);
482 }
483 
484 #endif
std::string custom
Definition: voms_api.h:112
std::string host
Definition: voms_api.h:87
void Order(std::string att)
std::string qualifier
Definition: voms_api.h:64
bool Export(std::string &data)
int getVOMSMajorVersionNumber(void)
std::string signature
Definition: voms_api.h:101
Definition: voms_api.h:97
std::string uri
Definition: voms_api.h:107
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:102
static void SkipSslInitialization()
int getVOMSPatchVersionNumber(void)
void AddTarget(std::string target)
std::vector< std::string > ListTargets(void)
verror_type
Error codes.
Definition: voms_api.h:162
AC * GetAC()
std::string name
Definition: voms_api.h:63
std::vector< attributelist > & GetAttributes()
int siglen
Definition: voms_api.h:100
std::string ErrorMessage(void)
void * gss_cred_id_t
Definition: voms_api.h:41
std::string vo
Definition: voms_api.h:89
std::string serial
Definition: voms_api.h:115
std::string value
Definition: voms_api.h:65
std::string date1
Definition: voms_api.h:108
int version
Definition: voms_api.h:99
verify_type
Definition: voms_api.h:148
void SetVerificationTime(time_t)
std::vector< voms > data
Definition: voms_api.h:371
std::string nick
Definition: voms_api.h:86
verror_type error
Definition: voms_api.h:212
std::string userca
Definition: voms_api.h:103
std::string serverca
Definition: voms_api.h:105
std::string extra_data
Definition: voms_api.h:375
data_type type
Definition: voms_api.h:110
std::string voname
Definition: voms_api.h:106
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:57
friend int TranslateVOMS(struct vomsdatar *vd, std::vector< voms > &v, int *error)
std::vector< std::string > fqan
Definition: voms_api.h:114
int port
Definition: voms_api.h:90
voms & operator=(const voms &)
recurse_type
Definition: voms_api.h:142
std::vector< contactdata > FindByVO(std::string vo)
bool DefaultData(voms &)
std::string grantor
Definition: voms_api.h:69
std::string contact
Definition: voms_api.h:88
bool LoadCredentials(X509 *, EVP_PKEY *, STACK_OF(X509) *)
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:189
int version
Definition: voms_api.h:92
void SetLifetime(int lifetime)
std::string server
Definition: voms_api.h:104
std::string workvo
Definition: voms_api.h:374
void * gss_ctx_id_t
Definition: voms_api.h:42
std::string date2
Definition: voms_api.h:109
bool LoadSystemContacts(std::string dir="")
void SetRetryCount(int retryCount)
bool Contact(std::string hostname, int port, std::string servsubject, std::string command)
bool Retrieve(X509 *cert, STACK_OF(X509) *chain, recurse_type how=RECURSE_CHAIN)
bool LoadUserContacts(std::string dir="")
std::vector< data > std
Definition: voms_api.h:111
std::vector< attribute > attributes
Definition: voms_api.h:70
std::string role
Definition: voms_api.h:56
User&#39;s characteristics: can be repeated. Generic name-value attribute : can be repeated.
Definition: voms_api.h:54
void ResetOrder(void)
std::string group
Definition: voms_api.h:55
bool RetrieveFromCtx(gss_ctx_id_t context, recurse_type how)
data_type
The type of data returned.
Definition: voms_api.h:76
void SetVerificationType(verify_type how)