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 #ifndef GSSAPI_H_
00026 typedef void * gss_cred_id_t;
00027 typedef void * gss_ctx_id_t;
00028 #endif
00029
00030 #include <openssl/x509.h>
00031 #include <openssl/bio.h>
00032 #include <sys/types.h>
00033 #include "newformat.h"
00034 }
00035
00038 struct data {
00039 std::string group;
00040 std::string role;
00041 std::string cap;
00042 };
00043
00046 struct attribute {
00047 std::string name;
00048 std::string qualifier;
00049 std::string value;
00050 };
00051
00052 struct attributelist {
00053 std::string grantor;
00054 std::vector<attribute> attributes;
00055 };
00056
00057
00060 enum data_type {
00061 TYPE_NODATA,
00062 TYPE_STD,
00063 TYPE_CUSTOM
00064 };
00065
00066 struct contactdata {
00070 std::string nick;
00071 std::string host;
00072 std::string contact;
00073 std::string vo;
00074 int port;
00076 int version;
00077 };
00078
00079 struct voms {
00080 friend class vomsdata;
00081 int version;
00082 int siglen;
00083 std::string signature;
00084 std::string user;
00085 std::string userca;
00086 std::string server;
00087 std::string serverca;
00088 std::string voname;
00089 std::string uri;
00090 std::string date1;
00091 std::string date2;
00092 data_type type;
00093 std::vector<data> std;
00094 std::string custom;
00095
00096 std::vector<std::string> fqan;
00097 std::string serial;
00098
00099
00100 private:
00101 void *realdata;
00102 X509 *holder;
00103 public:
00104 voms(const voms &);
00105 voms();
00106 voms &operator=(const voms &);
00107 ~voms();
00108
00109 private:
00110 struct vomsr *translate();
00111 friend int TranslateVOMS(struct vomsdatar *vd, std::vector<voms>&v, int *error);
00112
00113 public:
00114 AC *GetAC();
00115
00116 public:
00117 std::vector<attributelist>& GetAttributes();
00118 std::vector<std::string> GetTargets();
00119 };
00120
00121 enum recurse_type {
00122 RECURSE_CHAIN,
00123 RECURSE_NONE,
00124 RECURSE_DEEP
00125 };
00126
00127 enum verify_type {
00128 VERIFY_FULL = 0xffffffff,
00129 VERIFY_NONE = 0x00000000,
00130 VERIFY_DATE = 0x00000001,
00131 VERIFY_TARGET = 0x00000002,
00132 VERIFY_KEY = 0x00000004,
00133 VERIFY_SIGN = 0x00000008,
00134 VERIFY_ORDER = 0x00000010,
00135 VERIFY_ID = 0x00000020,
00136 VERIFY_CERTLIST = 0x00000040
00137 };
00138
00141 enum verror_type {
00142 VERR_NONE,
00143 VERR_NOSOCKET,
00144 VERR_NOIDENT,
00145 VERR_COMM,
00146 VERR_PARAM,
00147 VERR_NOEXT,
00148 VERR_NOINIT,
00149 VERR_TIME,
00150 VERR_IDCHECK,
00151 VERR_EXTRAINFO,
00152 VERR_FORMAT,
00153 VERR_NODATA,
00154 VERR_PARSE,
00155 VERR_DIR,
00156 VERR_SIGN,
00157 VERR_SERVER,
00158 VERR_MEM,
00159 VERR_VERIFY,
00160
00161 VERR_TYPE,
00162 VERR_ORDER,
00163 VERR_SERVERCODE,
00164 VERR_NOTAVAIL,
00165 VERR_FILE
00166 };
00167
00168 typedef bool (*check_sig)(X509 *, void *, verror_type &);
00170 struct vomsdata {
00171 private:
00172 class Initializer {
00173 public:
00174 Initializer();
00175 private:
00176 Initializer(Initializer &);
00177 };
00178
00179 private:
00180 static Initializer init;
00181 std::string ca_cert_dir;
00182 std::string voms_cert_dir;
00183 int duration;
00184 std::string ordering;
00185 std::vector<contactdata> servers;
00186 std::vector<std::string> targets;
00187
00188 public:
00189 verror_type error;
00191 vomsdata(std::string voms_dir = "",
00192 std::string cert_dir = "");
00203 bool LoadSystemContacts(std::string dir = "");
00210 bool LoadUserContacts(std::string dir = "");
00220 std::vector<contactdata> FindByAlias(std::string alias);
00228 std::vector<contactdata> FindByVO(std::string vo);
00236 void Order(std::string att);
00243 void ResetOrder(void);
00245 void AddTarget(std::string target);
00250 std::vector<std::string> ListTargets(void);
00252 void ResetTargets(void);
00253 std::string ServerErrors(void);
00255 bool Retrieve(X509 *cert, STACK_OF(X509) *chain,
00256 recurse_type how = RECURSE_CHAIN);
00265 bool Contact(std::string hostname, int port,
00266 std::string servsubject,
00267 std::string command);
00277 bool Contact(std::string hostname, int port,
00278 std::string servsubject,
00279 std::string command,
00280 int timeout);
00291 bool ContactRaw(std::string hostname, int port,
00292 std::string servsubject,
00293 std::string command,
00294 std::string &raw,
00295 int& version);
00304 bool ContactRaw(std::string hostname, int port,
00305 std::string servsubject,
00306 std::string command,
00307 std::string &raw,
00308 int& version,
00309 int timeout);
00319 void SetVerificationType(verify_type how);
00323 void SetLifetime(int lifetime);
00327 bool Import(std::string buffer);
00334 bool Export(std::string &data);
00341 bool DefaultData(voms &);
00344 std::vector<voms> data;
00347 std::string workvo;
00348 std::string extra_data;
00357 private:
00358 bool loadfile(std::string, uid_t uid, gid_t gid);
00359 bool loadfile0(std::string, uid_t uid, gid_t gid);
00360 bool verifydata(std::string &message, std::string subject, std::string ca,
00361 X509 *holder, voms &v);
00362 X509 *check(check_sig f, void *data);
00363 bool check_cert(X509 *cert);
00364 bool retrieve(X509 *cert, STACK_OF(X509) *chain, recurse_type how,
00365 AC_SEQ **listnew, std::string &subject, std::string &ca,
00366 X509 **holder);
00367 verify_type ver_type;
00368
00369 std::string serverrors;
00370 std::string errmessage;
00371
00372 void seterror(verror_type, std::string);
00373
00374 bool verifyac(X509 *, X509 *, AC*, voms&);
00375 bool check_sig_ac(X509 *, void *);
00376 X509 *check(void *);
00377 bool my_conn(const std::string&, int, const std::string&, int,
00378 const std::string&, std::string&, std::string&,
00379 std::string&);
00380 bool contact(const std::string&, int, const std::string&,
00381 const std::string&, std::string&, std::string&,
00382 std::string&);
00383 bool my_conn(const std::string&, int, const std::string&, int,
00384 const std::string&, std::string&, std::string&,
00385 std::string&, int timeout);
00386 bool contact(const std::string&, int, const std::string&,
00387 const std::string&, std::string&, std::string&,
00388 std::string&, int timeout);
00389 bool verifydata(AC *ac, const std::string& subject, const std::string& ca,
00390 X509 *holder, voms &v);
00391 bool evaluate(AC_SEQ *, const std::string&, const std::string&, X509*);
00392
00393 public:
00394
00395 std::string ErrorMessage(void);
00397 bool RetrieveFromCtx(gss_ctx_id_t context, recurse_type how);
00402 bool RetrieveFromCred(gss_cred_id_t credential, recurse_type how);
00407 bool Retrieve(X509_EXTENSION *ext);
00411 bool RetrieveFromProxy(recurse_type how);
00415 bool Retrieve(FILE *file, recurse_type how);
00421 ~vomsdata();
00422 private:
00423
00424 bool check_cert(STACK_OF(X509) *);
00425 X509 *check_from_certs(AC *ac, const std::string& voname);
00426 X509 *check_from_file(AC *, std::ifstream&, const std::string &vo, const std::string &filename);
00427
00428 public:
00429 vomsdata(const vomsdata &);
00430
00431 private:
00432 int retry_count;
00433
00434 public:
00435 void SetRetryCount(int retryCount);
00436
00437 private:
00438 STACK_OF(X509) *load_chain(BIO *in);
00439
00440 public:
00441 void SetVerificationTime(time_t);
00442
00443 private:
00444 time_t verificationtime;
00445 bool verifyac(X509 *, X509 *, AC*, time_t, voms&);
00446
00447 public:
00448 bool LoadCredentials(X509*, EVP_PKEY *, STACK_OF(X509) *);
00449 };
00450
00451
00452 int getMajorVersionNumber(void);
00453 int getMinorVersionNumber(void);
00454 int getPatchVersionNumber(void);
00455
00456 #endif