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 #ifndef NOGLOBUS
34 #define NOGLOBUS
35 #endif
36 
37 extern "C" {
38 #ifndef GSSAPI_H_
39 /*
40  * Also check against _GSSAPI_H_ as that is what the Kerberos 5 code defines and
41  * what header files on some systems look for.
42  */
43 
44 #ifndef _GSSAPI_H_
45 typedef void * gss_cred_id_t;
46 typedef void * gss_ctx_id_t;
47 #endif
48 #endif
49 
50 #include <openssl/x509.h>
51 #include <openssl/bio.h>
52 #include <sys/types.h>
53 #include "newformat.h"
54 }
55 
58 struct data {
59  std::string group;
60  std::string role;
61  std::string cap;
62 };
63 
66 struct attribute {
67  std::string name;
68  std::string qualifier;
69  std::string value;
70 };
71 
72 struct attributelist {
73  std::string grantor;
74  std::vector<attribute> attributes;
75 };
76 
77 
80 enum data_type {
84 };
85 
86 struct contactdata {
90  std::string nick;
91  std::string host;
92  std::string contact;
93  std::string vo;
94  int port;
96  int version;
97 };
98 
99 class vomspriv;
100 
101 struct voms {
102  friend class vomsdata;
103  int version;
104  int siglen;
105  std::string signature;
106  std::string user;
107  std::string userca;
108  std::string server;
109  std::string serverca;
110  std::string voname;
111  std::string uri;
112  std::string date1;
113  std::string date2;
115  std::vector<data> std;
116  std::string custom;
117  /* Data below this line only makes sense if version >= 1 */
118  std::vector<std::string> fqan;
119  std::string serial;
120  /* Data below this line is private. */
121 
122 private:
123  void *realdata;
124  X509 *holder;
125 public:
126  voms(const voms &);
127  voms();
128  voms &operator=(const voms &);
129  ~voms();
130 
131 private:
132  struct vomsr *translate();
133  friend int TranslateVOMS(struct vomsdatar *vd, std::vector<voms>&v, int *error);
134 
135 public:
136  AC *GetAC();
137 
138 public:
139  std::vector<attributelist>& GetAttributes();
140  std::vector<std::string> GetTargets();
141 
142 private:
143  vomspriv *vp;
144 };
145 
150 };
151 
153  VERIFY_FULL = 0xffffffff,
154  VERIFY_NONE = 0x00000000,
155  VERIFY_DATE = 0x00000001,
156  VERIFY_TARGET = 0x00000002,
157  VERIFY_KEY = 0x00000004,
158  VERIFY_SIGN = 0x00000008,
159  VERIFY_ORDER = 0x00000010,
160  VERIFY_ID = 0x00000020,
161  VERIFY_CERTLIST = 0x00000040
162 };
163 
166 enum verror_type {
185  // VERR_IDENT,
191 };
192 
193 typedef bool (*check_sig)(X509 *, void *, verror_type &);
195 class vomsdatapriv;
196 
197 struct vomsdata {
198  private:
199  class Initializer {
200  public:
201  Initializer();
202  private:
203  Initializer(Initializer &);
204  };
205 
206  private:
207  static Initializer init;
208  std::string ca_cert_dir;
209  std::string voms_cert_dir;
210  int duration;
211  std::string ordering;
212  std::vector<contactdata> servers;
213  std::vector<std::string> targets;
214 
215  public:
218  vomsdata(std::string voms_dir = "",
219  std::string cert_dir = "");
230  bool LoadSystemContacts(std::string dir = "");
237  bool LoadUserContacts(std::string dir = "");
247  std::vector<contactdata> FindByAlias(std::string alias);
255  std::vector<contactdata> FindByVO(std::string vo);
263  void Order(std::string att);
270  void ResetOrder(void);
272  void AddTarget(std::string target);
277  std::vector<std::string> ListTargets(void);
279  void ResetTargets(void);
280  std::string ServerErrors(void);
282  bool Retrieve(X509 *cert, STACK_OF(X509) *chain,
283  recurse_type how = RECURSE_CHAIN);
292  bool Contact(std::string hostname, int port,
293  std::string servsubject,
294  std::string command);
304  bool Contact(std::string hostname, int port,
305  std::string servsubject,
306  std::string command,
307  int timeout);
319  bool ContactRaw(std::string hostname, int port,
320  std::string servsubject,
321  std::string command,
322  std::string &raw,
323  int& version);
332  bool ContactRaw(std::string hostname, int port,
333  std::string servsubject,
334  std::string command,
335  std::string &raw,
336  int& version,
337  int timeout);
348  void SetVerificationType(verify_type how);
352  void SetLifetime(int lifetime);
356  bool Import(std::string buffer);
363  bool Export(std::string &data);
370  bool DefaultData(voms &);
373  std::vector<voms> data;
376  std::string workvo;
377  std::string extra_data;
386 private:
387  bool loadfile(std::string, uid_t uid, gid_t gid);
388  bool loadfile0(std::string, uid_t uid, gid_t gid);
389  bool verifydata(std::string &message, std::string subject, std::string ca,
390  X509 *holder, voms &v);
391  bool check_cert(X509 *cert);
392  bool retrieve(X509 *cert, STACK_OF(X509) *chain, recurse_type how,
393  AC_SEQ **listnew, std::string &subject, std::string &ca,
394  X509 **holder);
395  verify_type ver_type;
396 
397  std::string serverrors;
398  std::string errmessage;
399 
400  void seterror(verror_type, std::string);
401 
402  bool check_sig_ac(X509 *, void *);
403  X509 *check(void *);
404  bool contact(const std::string&, int, const std::string&,
405  const std::string&, std::string&, std::string&,
406  std::string&, int timeout);
407  bool verifydata(AC *ac, const std::string& subject, const std::string& ca,
408  X509 *holder, voms &v);
409  bool evaluate(AC_SEQ *, const std::string&, const std::string&, X509*);
410 
411 public:
412 
413  std::string ErrorMessage(void);
416 #ifdef NOGLOBUS
417  bool RetrieveFromCtx(gss_ctx_id_t context, recurse_type how);
422  bool RetrieveFromCred(gss_cred_id_t credential, recurse_type how);
426 #endif
427 
428  bool Retrieve(X509_EXTENSION *ext);
432  bool RetrieveFromProxy(recurse_type how);
436  bool Retrieve(FILE *file, recurse_type how);
443  bool Retrieve(AC *ac);
447  ~vomsdata();
448 private:
449  // X509 *check_file(void *);
450  bool check_cert(STACK_OF(X509) *);
451  X509 *check_from_certs(AC *ac, const std::string& voname);
452  X509 *check_from_file(AC *, std::ifstream&, const std::string &vo, const std::string &filename);
453 
454 public:
455  vomsdata(const vomsdata &);
456 
457 private:
458  int retry_count;
459 
460 public:
461  void SetRetryCount(int retryCount);
462 
463 public:
464  void SetVerificationTime(time_t);
465 
466 private:
467  time_t verificationtime;
468  bool verifyac(X509 *, X509 *, AC*, time_t, voms&);
469 
470 public:
471  bool LoadCredentials(X509*, EVP_PKEY *, STACK_OF(X509) *);
472  bool ContactRESTRaw(const std::string&, int, const std::string&, std::string&, int, int);
473 
474 private:
475  bool InterpretOutput(const std::string&, std::string&);
476 
477 private:
478  vomsdatapriv *vdp;
479 };
480 
481 
482 extern "C" {
483 int getVOMSMajorVersionNumber(void);
484 int getVOMSMinorVersionNumber(void);
485 int getVOMSPatchVersionNumber(void);
486 }
487 
488 #endif
vomsdata::ContactRaw
bool ContactRaw(std::string hostname, int port, std::string servsubject, std::string command, std::string &raw, int &version)
voms::GetTargets
std::vector< std::string > GetTargets()
VERR_PARSE
@ VERR_PARSE
Definition: voms_api.h:179
VERR_NOSOCKET
@ VERR_NOSOCKET
Definition: voms_api.h:168
vomsdata::RetrieveFromProxy
bool RetrieveFromProxy(recurse_type how)
vomsdata
Definition: voms_api.h:197
voms::user
std::string user
Definition: voms_api.h:106
vomsdata::FindByAlias
std::vector< contactdata > FindByAlias(std::string alias)
vomsdata::Retrieve
bool Retrieve(X509 *cert, STACK_OF(X509) *chain, recurse_type how=RECURSE_CHAIN)
vomsdata::ServerErrors
std::string ServerErrors(void)
voms::uri
std::string uri
Definition: voms_api.h:111
VERR_TYPE
@ VERR_TYPE
Definition: voms_api.h:186
RECURSE_CHAIN
@ RECURSE_CHAIN
Definition: voms_api.h:147
getVOMSMinorVersionNumber
int getVOMSMinorVersionNumber(void)
voms::custom
std::string custom
Definition: voms_api.h:116
VERR_FILE
@ VERR_FILE
Definition: voms_api.h:190
data::role
std::string role
Definition: voms_api.h:60
data::group
std::string group
Definition: voms_api.h:59
gss_cred_id_t
void * gss_cred_id_t
Definition: voms_api.h:45
data_type
data_type
The type of data returned.
Definition: voms_api.h:80
vomsdata::FindByVO
std::vector< contactdata > FindByVO(std::string vo)
VERIFY_ID
@ VERIFY_ID
Definition: voms_api.h:160
contactdata::version
int version
Definition: voms_api.h:96
data
User's characteristics: can be repeated.
Definition: voms_api.h:58
contactdata::port
int port
Definition: voms_api.h:94
attributelist::grantor
std::string grantor
Definition: voms_api.h:73
voms::GetAC
AC * GetAC()
vomsdata::SetRetryCount
void SetRetryCount(int retryCount)
VERIFY_TARGET
@ VERIFY_TARGET
Definition: voms_api.h:156
voms::signature
std::string signature
Definition: voms_api.h:105
RECURSE_NONE
@ RECURSE_NONE
Definition: voms_api.h:148
VERR_ORDER
@ VERR_ORDER
Definition: voms_api.h:187
vomsdata::LoadCredentials
bool LoadCredentials(X509 *, EVP_PKEY *, STACK_OF(X509) *)
vomsdata::ResetOrder
void ResetOrder(void)
VERIFY_CERTLIST
@ VERIFY_CERTLIST
Definition: voms_api.h:161
VERR_SERVER
@ VERR_SERVER
Definition: voms_api.h:182
voms::date1
std::string date1
Definition: voms_api.h:112
verify_type
verify_type
Definition: voms_api.h:152
vomsdata::RetrieveFromCtx
bool RetrieveFromCtx(gss_ctx_id_t context, recurse_type how)
VERIFY_DATE
@ VERIFY_DATE
Definition: voms_api.h:155
VERIFY_ORDER
@ VERIFY_ORDER
Definition: voms_api.h:159
vomsdata::SetLifetime
void SetLifetime(int lifetime)
VERR_COMM
@ VERR_COMM
Definition: voms_api.h:170
attributelist
Definition: voms_api.h:72
vomsdata::AddTarget
void AddTarget(std::string target)
vomsdata::ListTargets
std::vector< std::string > ListTargets(void)
VERIFY_SIGN
@ VERIFY_SIGN
Definition: voms_api.h:158
vomsdata::DefaultData
bool DefaultData(voms &)
voms::voname
std::string voname
Definition: voms_api.h:110
voms::siglen
int siglen
Definition: voms_api.h:104
attribute::qualifier
std::string qualifier
Definition: voms_api.h:68
verror_type
verror_type
Error codes.
Definition: voms_api.h:166
voms::voms
voms()
voms::serial
std::string serial
Definition: voms_api.h:119
voms::operator=
voms & operator=(const voms &)
getVOMSPatchVersionNumber
int getVOMSPatchVersionNumber(void)
voms::userca
std::string userca
Definition: voms_api.h:107
contactdata::nick
std::string nick
Definition: voms_api.h:90
voms::GetAttributes
std::vector< attributelist > & GetAttributes()
TYPE_CUSTOM
@ TYPE_CUSTOM
Definition: voms_api.h:83
VERR_NONE
@ VERR_NONE
Definition: voms_api.h:167
contactdata::host
std::string host
Definition: voms_api.h:91
voms
Definition: voms_api.h:101
voms::fqan
std::vector< std::string > fqan
Definition: voms_api.h:118
VERR_NODATA
@ VERR_NODATA
Definition: voms_api.h:178
VERR_NOIDENT
@ VERR_NOIDENT
Definition: voms_api.h:169
vomsdata::Order
void Order(std::string att)
voms::serverca
std::string serverca
Definition: voms_api.h:109
vomsdata::Export
bool Export(std::string &data)
voms::type
data_type type
Definition: voms_api.h:114
check_sig
bool(* check_sig)(X509 *, void *, verror_type &)
Definition: voms_api.h:193
voms::TranslateVOMS
friend int TranslateVOMS(struct vomsdatar *vd, std::vector< voms > &v, int *error)
vomsdata::LoadSystemContacts
bool LoadSystemContacts(std::string dir="")
voms::version
int version
Definition: voms_api.h:103
VERR_VERIFY
@ VERR_VERIFY
Definition: voms_api.h:184
recurse_type
recurse_type
Definition: voms_api.h:146
vomsdata::vomsdata
vomsdata(std::string voms_dir="", std::string cert_dir="")
VERIFY_KEY
@ VERIFY_KEY
Definition: voms_api.h:157
vomsdata::LoadUserContacts
bool LoadUserContacts(std::string dir="")
vomsdata::extra_data
std::string extra_data
Definition: voms_api.h:377
VERR_DIR
@ VERR_DIR
Definition: voms_api.h:180
vomsdata::ResetTargets
void ResetTargets(void)
attribute::name
std::string name
Definition: voms_api.h:67
VERIFY_NONE
@ VERIFY_NONE
Definition: voms_api.h:154
contactdata::vo
std::string vo
Definition: voms_api.h:93
vomsdata::Import
bool Import(std::string buffer)
vomsdata::ErrorMessage
std::string ErrorMessage(void)
attribute::value
std::string value
Definition: voms_api.h:69
VERR_PARAM
@ VERR_PARAM
Definition: voms_api.h:171
vomsdata::RetrieveFromCred
bool RetrieveFromCred(gss_cred_id_t credential, recurse_type how)
TYPE_STD
@ TYPE_STD
Definition: voms_api.h:82
data::cap
std::string cap
Definition: voms_api.h:61
voms::date2
std::string date2
Definition: voms_api.h:113
VERR_NOEXT
@ VERR_NOEXT
Definition: voms_api.h:172
voms::std
std::vector< data > std
Definition: voms_api.h:115
vomsdata::data
std::vector< voms > data
Definition: voms_api.h:373
VERIFY_FULL
@ VERIFY_FULL
Definition: voms_api.h:153
vomsdata::Contact
bool Contact(std::string hostname, int port, std::string servsubject, std::string command)
VERR_NOINIT
@ VERR_NOINIT
Definition: voms_api.h:173
VERR_EXTRAINFO
@ VERR_EXTRAINFO
Definition: voms_api.h:176
TYPE_NODATA
@ TYPE_NODATA
Definition: voms_api.h:81
getVOMSMajorVersionNumber
int getVOMSMajorVersionNumber(void)
vomsdata::~vomsdata
~vomsdata()
vomsdata::ContactRESTRaw
bool ContactRESTRaw(const std::string &, int, const std::string &, std::string &, int, int)
attribute
Definition: voms_api.h:66
VERR_NOTAVAIL
@ VERR_NOTAVAIL
Definition: voms_api.h:189
VERR_SERVERCODE
@ VERR_SERVERCODE
Definition: voms_api.h:188
voms::~voms
~voms()
VERR_MEM
@ VERR_MEM
Definition: voms_api.h:183
RECURSE_DEEP
@ RECURSE_DEEP
Definition: voms_api.h:149
vomsdata::SetVerificationType
void SetVerificationType(verify_type how)
vomsdata::workvo
std::string workvo
Definition: voms_api.h:376
gss_ctx_id_t
void * gss_ctx_id_t
Definition: voms_api.h:46
VERR_IDCHECK
@ VERR_IDCHECK
Definition: voms_api.h:175
vomsdata::SetVerificationTime
void SetVerificationTime(time_t)
VERR_SIGN
@ VERR_SIGN
Definition: voms_api.h:181
attributelist::attributes
std::vector< attribute > attributes
Definition: voms_api.h:74
contactdata
Definition: voms_api.h:86
vomsdata::error
verror_type error
Definition: voms_api.h:216
voms::server
std::string server
Definition: voms_api.h:108
contactdata::contact
std::string contact
Definition: voms_api.h:92
VERR_TIME
@ VERR_TIME
Definition: voms_api.h:174
VERR_FORMAT
@ VERR_FORMAT
Definition: voms_api.h:177