00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef VOMS_API_H
00017 #define VOMS_API_H
00018
00019 #include <fstream>
00020 #include <string>
00021 #include <vector>
00022
00023
00024 extern "C" {
00025 #ifdef NOGLOBUS
00026 #ifndef GSSAPI_H_
00027 typedef void * gss_cred_id_t;
00028 typedef void * gss_ctx_id_t;
00029 #endif
00030 #else
00031 #include "gssapi.h"
00032 #endif
00033
00034 #include <openssl/x509.h>
00035 #include <openssl/bio.h>
00036 #include <sys/types.h>
00037 #include "newformat.h"
00038 }
00039
00042 struct data {
00043 std::string group;
00044 std::string role;
00045 std::string cap;
00046 };
00047
00050 struct attribute {
00051 std::string name;
00052 std::string qualifier;
00053 std::string value;
00054 };
00055
00056 struct attributelist {
00057 std::string grantor;
00058 std::vector<attribute> attributes;
00059 };
00060
00061
00064 enum data_type {
00065 TYPE_NODATA,
00066 TYPE_STD,
00067 TYPE_CUSTOM
00068 };
00069
00070 struct contactdata {
00074 std::string nick;
00075 std::string host;
00076 std::string contact;
00077 std::string vo;
00078 int port;
00080 int version;
00081 };
00082
00083 struct voms {
00084 friend class vomsdata;
00085 int version;
00086 int siglen;
00087 std::string signature;
00088 std::string user;
00089 std::string userca;
00090 std::string server;
00091 std::string serverca;
00092 std::string voname;
00093 std::string uri;
00094 std::string date1;
00095 std::string date2;
00096 data_type type;
00097 std::vector<data> std;
00098 std::string custom;
00099
00100 std::vector<std::string> fqan;
00101 std::string serial;
00102
00103
00104 private:
00105 void *realdata;
00106 X509 *holder;
00107 public:
00108 voms(const voms &);
00109 voms();
00110 voms &operator=(const voms &);
00111 ~voms();
00112
00113 private:
00114 struct vomsr *translate();
00115 friend int TranslateVOMS(struct vomsdatar *vd, std::vector<voms>&v, int *error);
00116
00117 public:
00118 AC *GetAC();
00119
00120 public:
00121 std::vector<attributelist>& GetAttributes();
00122 std::vector<std::string> GetTargets();
00123 };
00124
00125 enum recurse_type {
00126 RECURSE_CHAIN,
00127 RECURSE_NONE,
00128 RECURSE_DEEP
00129 };
00130
00131 enum verify_type {
00132 VERIFY_FULL = 0xffffffff,
00133 VERIFY_NONE = 0x00000000,
00134 VERIFY_DATE = 0x00000001,
00135 VERIFY_TARGET = 0x00000002,
00136 VERIFY_KEY = 0x00000004,
00137 VERIFY_SIGN = 0x00000008,
00138 VERIFY_ORDER = 0x00000010,
00139 VERIFY_ID = 0x00000020,
00140 VERIFY_CERTLIST = 0x00000040
00141 };
00142
00145 enum verror_type {
00146 VERR_NONE,
00147 VERR_NOSOCKET,
00148 VERR_NOIDENT,
00149 VERR_COMM,
00150 VERR_PARAM,
00151 VERR_NOEXT,
00152 VERR_NOINIT,
00153 VERR_TIME,
00154 VERR_IDCHECK,
00155 VERR_EXTRAINFO,
00156 VERR_FORMAT,
00157 VERR_NODATA,
00158 VERR_PARSE,
00159 VERR_DIR,
00160 VERR_SIGN,
00161 VERR_SERVER,
00162 VERR_MEM,
00163 VERR_VERIFY,
00164
00165 VERR_TYPE,
00166 VERR_ORDER,
00167 VERR_SERVERCODE,
00168 VERR_NOTAVAIL,
00169 VERR_FILE
00170 };
00171
00172 typedef bool (*check_sig)(X509 *, void *, verror_type &);
00174 struct vomsdata {
00175 private:
00176 class Initializer {
00177 public:
00178 Initializer();
00179 private:
00180 Initializer(Initializer &);
00181 };
00182
00183 private:
00184 static Initializer init;
00185 std::string ca_cert_dir;
00186 std::string voms_cert_dir;
00187 int duration;
00188 std::string ordering;
00189 std::vector<contactdata> servers;
00190 std::vector<std::string> targets;
00191
00192 public:
00193 verror_type error;
00195 vomsdata(std::string voms_dir = "",
00196 std::string cert_dir = "");
00207 bool LoadSystemContacts(std::string dir = "");
00214 bool LoadUserContacts(std::string dir = "");
00224 std::vector<contactdata> FindByAlias(std::string alias);
00232 std::vector<contactdata> FindByVO(std::string vo);
00240 void Order(std::string att);
00247 void ResetOrder(void);
00249 void AddTarget(std::string target);
00254 std::vector<std::string> ListTargets(void);
00256 void ResetTargets(void);
00257 std::string ServerErrors(void);
00259 bool Retrieve(X509 *cert, STACK_OF(X509) *chain,
00260 recurse_type how = RECURSE_CHAIN);
00269 bool Contact(std::string hostname, int port,
00270 std::string servsubject,
00271 std::string command);
00281 bool Contact(std::string hostname, int port,
00282 std::string servsubject,
00283 std::string command,
00284 int timeout);
00295 bool ContactRaw(std::string hostname, int port,
00296 std::string servsubject,
00297 std::string command,
00298 std::string &raw,
00299 int& version);
00308 bool ContactRaw(std::string hostname, int port,
00309 std::string servsubject,
00310 std::string command,
00311 std::string &raw,
00312 int& version,
00313 int timeout);
00323 void SetVerificationType(verify_type how);
00327 void SetLifetime(int lifetime);
00331 bool Import(std::string buffer);
00338 bool Export(std::string &data);
00345 bool DefaultData(voms &);
00348 std::vector<voms> data;
00351 std::string workvo;
00352 std::string extra_data;
00361 private:
00362 bool loadfile(std::string, uid_t uid, gid_t gid);
00363 bool loadfile0(std::string, uid_t uid, gid_t gid);
00364 bool verifydata(std::string &message, std::string subject, std::string ca,
00365 X509 *holder, voms &v);
00366 X509 *check(check_sig f, void *data);
00367 bool check_cert(X509 *cert);
00368 bool retrieve(X509 *cert, STACK_OF(X509) *chain, recurse_type how,
00369 AC_SEQ **listnew, std::string &subject, std::string &ca,
00370 X509 **holder);
00371 verify_type ver_type;
00372
00373 std::string serverrors;
00374 std::string errmessage;
00375
00376 void seterror(verror_type, std::string);
00377
00378 bool verifyac(X509 *, X509 *, AC*, voms&);
00379 bool check_sig_ac(X509 *, void *);
00380 X509 *check(void *);
00381 bool my_conn(const std::string&, int, const std::string&, int,
00382 const std::string&, std::string&, std::string&,
00383 std::string&);
00384 bool contact(const std::string&, int, const std::string&,
00385 const std::string&, std::string&, std::string&,
00386 std::string&);
00387 bool my_conn(const std::string&, int, const std::string&, int,
00388 const std::string&, std::string&, std::string&,
00389 std::string&, int timeout);
00390 bool contact(const std::string&, int, const std::string&,
00391 const std::string&, std::string&, std::string&,
00392 std::string&, int timeout);
00393 bool verifydata(AC *ac, const std::string& subject, const std::string& ca,
00394 X509 *holder, voms &v);
00395 bool evaluate(AC_SEQ *, const std::string&, const std::string&, X509*);
00396
00397 public:
00398
00399 std::string ErrorMessage(void);
00402 #ifdef NOGLOBUS
00403 bool RetrieveFromCtx(gss_ctx_id_t context, recurse_type how);
00408 bool RetrieveFromCred(gss_cred_id_t credential, recurse_type how);
00412 #else
00413 bool RetrieveFromCtx(void *context, recurse_type how);
00418 bool RetrieveFromCred(void *credential, recurse_type how);
00422 bool RetrieveFromCtx(gss_ctx_id_t context, recurse_type how) {
00423 return RetrieveFromCtx((void*)context,how);
00424 }
00429 bool RetrieveFromCred(gss_cred_id_t credential, recurse_type how) {
00430 return RetrieveFromCred((void*)credential, how);
00431 }
00435 #endif
00436
00437 bool Retrieve(X509_EXTENSION *ext);
00441 bool RetrieveFromProxy(recurse_type how);
00445 bool Retrieve(FILE *file, recurse_type how);
00451 ~vomsdata();
00452 private:
00453
00454 bool check_cert(STACK_OF(X509) *);
00455 X509 *check_from_certs(AC *ac, const std::string& voname);
00456 X509 *check_from_file(AC *, std::ifstream&, const std::string &vo, const std::string &filename);
00457
00458 public:
00459 vomsdata(const vomsdata &);
00460
00461 private:
00462 int retry_count;
00463
00464 public:
00465 void SetRetryCount(int retryCount);
00466
00467 private:
00468 STACK_OF(X509) *load_chain(BIO *in);
00469
00470 public:
00471 void SetVerificationTime(time_t);
00472
00473 private:
00474 time_t verificationtime;
00475 bool verifyac(X509 *, X509 *, AC*, time_t, voms&);
00476
00477 public:
00478 bool LoadCredentials(X509*, EVP_PKEY *, STACK_OF(X509) *);
00479 };
00480
00481
00482 int getMajorVersionNumber(void);
00483 int getMinorVersionNumber(void);
00484 int getPatchVersionNumber(void);
00485
00486 #endif