Loading...
Searching...
No Matches
voms_api.h
Go to the documentation of this file.
/*********************************************************************
*
* Authors: Vincenzo Ciaschini - Vincenzo.Ciaschini@cnaf.infn.it
*
* Copyright (c) Members of the EGEE Collaboration. 2004-2010.
* See http://www.eu-egee.org/partners/ for details on the copyright holders.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Parts of this code may be based upon or even include verbatim pieces,
* originally written by other people, in which case the original header
* follows.
*
*********************************************************************/
#ifndef VOMS_API_H
#define VOMS_API_H
#include <fstream>
#include <string>
#include <vector>
#ifndef NOGLOBUS
#define NOGLOBUS
#endif
extern "C" {
#ifndef GSSAPI_H_
/*
* Also check against _GSSAPI_H_ as that is what the Kerberos 5 code defines and
* what header files on some systems look for.
*/
#ifndef _GSSAPI_H_
typedef void * gss_cred_id_t;
typedef void * gss_ctx_id_t;
#endif
#endif
#include <openssl/x509.h>
#include <openssl/bio.h>
#include <sys/types.h>
#include "newformat.h"
}
struct data {
std::string group;
std::string role;
std::string cap;
};
struct attribute {
std::string name;
std::string qualifier;
std::string value;
};
struct attributelist {
std::string grantor;
std::vector<attribute> attributes;
};
enum data_type {
TYPE_NODATA,
TYPE_STD,
TYPE_CUSTOM
};
struct contactdata {
std::string nick;
std::string host;
std::string contact;
std::string vo;
int port;
int version;
};
class vomspriv;
struct voms {
friend class vomsdata;
int version;
int siglen;
std::string signature;
std::string user;
std::string userca;
std::string server;
std::string serverca;
std::string voname;
std::string uri;
std::string date1;
std::string date2;
data_type type;
std::vector<data> std;
std::string custom;
/* Data below this line only makes sense if version >= 1 */
std::vector<std::string> fqan;
std::string serial;
/* Data below this line is private. */
private:
void *realdata;
X509 *holder;
public:
voms(const voms &);
voms();
voms &operator=(const voms &);
~voms();
private:
struct vomsr *translate();
friend int TranslateVOMS(struct vomsdatar *vd, std::vector<voms>&v, int *error);
public:
AC *GetAC();
public:
std::vector<attributelist>& GetAttributes();
std::vector<std::string> GetTargets();
private:
vomspriv *vp;
};
enum recurse_type {
RECURSE_CHAIN,
RECURSE_NONE,
RECURSE_DEEP
};
enum verify_type {
VERIFY_FULL = 0xffffffff,
VERIFY_NONE = 0x00000000,
VERIFY_DATE = 0x00000001,
VERIFY_TARGET = 0x00000002,
VERIFY_KEY = 0x00000004,
VERIFY_SIGN = 0x00000008,
VERIFY_ORDER = 0x00000010,
VERIFY_ID = 0x00000020,
VERIFY_CERTLIST = 0x00000040
};
enum verror_type {
VERR_NONE,
VERR_NOSOCKET,
VERR_NOIDENT,
VERR_COMM,
VERR_PARAM,
VERR_NOEXT,
VERR_NOINIT,
VERR_TIME,
VERR_IDCHECK,
VERR_EXTRAINFO,
VERR_FORMAT,
VERR_NODATA,
VERR_PARSE,
VERR_DIR,
VERR_SIGN,
VERR_SERVER,
VERR_MEM,
VERR_VERIFY,
// VERR_IDENT,
VERR_TYPE,
VERR_ORDER,
VERR_SERVERCODE,
VERR_NOTAVAIL,
VERR_FILE
};
typedef bool (*check_sig)(X509 *, void *, verror_type &);
class vomsdatapriv;
struct vomsdata {
private:
class Initializer {
public:
Initializer();
private:
Initializer(Initializer &);
};
private:
static Initializer init;
std::string ca_cert_dir;
std::string voms_cert_dir;
int duration;
std::string ordering;
std::vector<contactdata> servers;
std::vector<std::string> targets;
public:
verror_type error;
static void SkipSslInitialization();
vomsdata(std::string voms_dir = "",
std::string cert_dir = "");
bool LoadSystemContacts(std::string dir = "");
bool LoadUserContacts(std::string dir = "");
std::vector<contactdata> FindByAlias(std::string alias);
std::vector<contactdata> FindByVO(std::string vo);
void Order(std::string att);
void ResetOrder(void);
void AddTarget(std::string target);
std::vector<std::string> ListTargets(void);
void ResetTargets(void);
std::string ServerErrors(void);
bool Retrieve(X509 *cert, STACK_OF(X509) *chain,
recurse_type how = RECURSE_CHAIN);
bool Contact(std::string hostname, int port,
std::string servsubject,
std::string command);
bool Contact(std::string hostname, int port,
std::string servsubject,
std::string command,
int timeout);
bool ContactRaw(std::string hostname, int port,
std::string servsubject,
std::string command,
std::string &raw,
int& version);
bool ContactRaw(std::string hostname, int port,
std::string servsubject,
std::string command,
std::string &raw,
int& version,
int timeout);
void SetVerificationType(verify_type how);
void SetLifetime(int lifetime);
bool Import(std::string buffer);
bool Export(std::string &data);
bool DefaultData(voms &);
std::vector<voms> data;
std::string workvo;
std::string extra_data;
private:
bool loadfile(std::string, uid_t uid, gid_t gid);
bool loadfile0(std::string, uid_t uid, gid_t gid);
bool verifydata(std::string &message, std::string subject, std::string ca,
X509 *holder, voms &v);
bool check_cert(X509 *cert);
bool retrieve(X509 *cert, STACK_OF(X509) *chain, recurse_type how,
AC_SEQ **listnew, std::string &subject, std::string &ca,
X509 **holder);
verify_type ver_type;
std::string serverrors;
std::string errmessage;
void seterror(verror_type, std::string);
bool check_sig_ac(X509 *, void *);
X509 *check(void *);
bool contact(const std::string&, int, const std::string&,
const std::string&, std::string&, std::string&,
std::string&, int timeout);
bool verifydata(AC *ac, const std::string& subject, const std::string& ca,
X509 *holder, voms &v);
bool evaluate(AC_SEQ *, const std::string&, const std::string&, X509*);
public:
std::string ErrorMessage(void);
#ifdef NOGLOBUS
bool RetrieveFromCtx(gss_ctx_id_t context, recurse_type how);
bool RetrieveFromCred(gss_cred_id_t credential, recurse_type how);
#endif
bool Retrieve(X509_EXTENSION *ext);
bool RetrieveFromProxy(recurse_type how);
bool Retrieve(FILE *file, recurse_type how);
bool Retrieve(AC *ac);
~vomsdata();
private:
// X509 *check_file(void *);
bool check_cert(STACK_OF(X509) *);
X509 *check_from_certs(AC *ac, const std::string& voname);
X509 *check_from_file(AC *, std::ifstream&, const std::string &vo, const std::string &filename);
public:
vomsdata(const vomsdata &);
private:
int retry_count;
public:
void SetRetryCount(int retryCount);
public:
void SetVerificationTime(time_t);
private:
time_t verificationtime;
bool verifyac(X509 *, X509 *, AC*, time_t, voms&);
public:
bool LoadCredentials(X509*, EVP_PKEY *, STACK_OF(X509) *);
bool ContactRESTRaw(const std::string&, int, const std::string&, std::string&, int, int);
private:
bool InterpretOutput(const std::string&, std::string&);
private:
vomsdatapriv *vdp;
};
extern "C" {
int getVOMSMajorVersionNumber(void);
int getVOMSMinorVersionNumber(void);
int getVOMSPatchVersionNumber(void);
}
#endif
attribute
Definition voms_api.h:66
attribute::value
std::string value
Definition voms_api.h:69
attribute::qualifier
std::string qualifier
Definition voms_api.h:68
attribute::name
std::string name
Definition voms_api.h:67
attributelist
Definition voms_api.h:72
attributelist::grantor
std::string grantor
Definition voms_api.h:73
attributelist::attributes
std::vector< attribute > attributes
Definition voms_api.h:74
contactdata
Definition voms_api.h:86
contactdata::host
std::string host
Definition voms_api.h:91
contactdata::contact
std::string contact
Definition voms_api.h:92
contactdata::nick
std::string nick
Definition voms_api.h:90
contactdata::port
int port
Definition voms_api.h:94
contactdata::vo
std::string vo
Definition voms_api.h:93
contactdata::version
int version
Definition voms_api.h:96
data
User's characteristics: can be repeated.Generic name-value attribute : can be repeated.
Definition voms_api.h:58
data::group
std::string group
Definition voms_api.h:59
data::cap
std::string cap
Definition voms_api.h:61
data::role
std::string role
Definition voms_api.h:60
voms
Definition voms_api.h:101
voms::date2
std::string date2
Definition voms_api.h:113
voms::fqan
std::vector< std::string > fqan
Definition voms_api.h:118
voms::vomsdata
friend class vomsdata
Definition voms_api.h:102
voms::version
int version
Definition voms_api.h:103
voms::user
std::string user
Definition voms_api.h:106
voms::voname
std::string voname
Definition voms_api.h:110
voms::GetAC
AC * GetAC()
voms::siglen
int siglen
Definition voms_api.h:104
voms::signature
std::string signature
Definition voms_api.h:105
voms::GetAttributes
std::vector< attributelist > & GetAttributes()
voms::uri
std::string uri
Definition voms_api.h:111
voms::serial
std::string serial
Definition voms_api.h:119
voms::~voms
~voms()
voms::userca
std::string userca
Definition voms_api.h:107
voms::custom
std::string custom
Definition voms_api.h:116
voms::TranslateVOMS
friend int TranslateVOMS(struct vomsdatar *vd, std::vector< voms > &v, int *error)
voms::voms
voms(const voms &)
voms::type
data_type type
Definition voms_api.h:114
voms::serverca
std::string serverca
Definition voms_api.h:109
voms::date1
std::string date1
Definition voms_api.h:112
voms::GetTargets
std::vector< std::string > GetTargets()
voms::std
std::vector< data > std
Definition voms_api.h:115
voms::voms
voms()
voms::operator=
voms & operator=(const voms &)
voms::server
std::string server
Definition voms_api.h:108
vomsdata::Export
bool Export(std::string &data)
vomsdata::FindByVO
std::vector< contactdata > FindByVO(std::string vo)
vomsdata::FindByAlias
std::vector< contactdata > FindByAlias(std::string alias)
vomsdata::ResetOrder
void ResetOrder(void)
vomsdata::AddTarget
void AddTarget(std::string target)
vomsdata::RetrieveFromCred
bool RetrieveFromCred(gss_cred_id_t credential, recurse_type how)
vomsdata::Import
bool Import(std::string buffer)
vomsdata::Retrieve
bool Retrieve(FILE *file, recurse_type how)
vomsdata::SetVerificationTime
void SetVerificationTime(time_t)
vomsdata::ServerErrors
std::string ServerErrors(void)
vomsdata::ResetTargets
void ResetTargets(void)
vomsdata::SetVerificationType
void SetVerificationType(verify_type how)
vomsdata::LoadUserContacts
bool LoadUserContacts(std::string dir="")
vomsdata::Retrieve
bool Retrieve(X509_EXTENSION *ext)
vomsdata::ContactRaw
bool ContactRaw(std::string hostname, int port, std::string servsubject, std::string command, std::string &raw, int &version, int timeout)
vomsdata::RetrieveFromCtx
bool RetrieveFromCtx(gss_ctx_id_t context, recurse_type how)
vomsdata::LoadSystemContacts
bool LoadSystemContacts(std::string dir="")
vomsdata::Contact
bool Contact(std::string hostname, int port, std::string servsubject, std::string command, int timeout)
vomsdata::ErrorMessage
std::string ErrorMessage(void)
vomsdata::RetrieveFromProxy
bool RetrieveFromProxy(recurse_type how)
vomsdata::ContactRESTRaw
bool ContactRESTRaw(const std::string &, int, const std::string &, std::string &, int, int)
vomsdata::vomsdata
vomsdata(std::string voms_dir="", std::string cert_dir="")
vomsdata::error
verror_type error
Definition voms_api.h:216
vomsdata::workvo
std::string workvo
Definition voms_api.h:378
vomsdata::data
std::vector< voms > data
Definition voms_api.h:375
vomsdata::ContactRaw
bool ContactRaw(std::string hostname, int port, std::string servsubject, std::string command, std::string &raw, int &version)
vomsdata::Retrieve
bool Retrieve(AC *ac)
vomsdata::SetLifetime
void SetLifetime(int lifetime)
vomsdata::~vomsdata
~vomsdata()
vomsdata::extra_data
std::string extra_data
Definition voms_api.h:379
vomsdata::SkipSslInitialization
static void SkipSslInitialization()
vomsdata::DefaultData
bool DefaultData(voms &)
vomsdata::LoadCredentials
bool LoadCredentials(X509 *, EVP_PKEY *, STACK_OF(X509) *)
vomsdata::SetRetryCount
void SetRetryCount(int retryCount)
vomsdata::Retrieve
bool Retrieve(X509 *cert, STACK_OF(X509) *chain, recurse_type how=RECURSE_CHAIN)
vomsdata::Contact
bool Contact(std::string hostname, int port, std::string servsubject, std::string command)
vomsdata::ListTargets
std::vector< std::string > ListTargets(void)
vomsdata::Order
void Order(std::string att)
vomsdata::vomsdata
vomsdata(const vomsdata &)
recurse_type
recurse_type
Definition voms_api.h:146
RECURSE_NONE
@ RECURSE_NONE
Definition voms_api.h:148
RECURSE_DEEP
@ RECURSE_DEEP
Definition voms_api.h:149
RECURSE_CHAIN
@ RECURSE_CHAIN
Definition voms_api.h:147
getVOMSMinorVersionNumber
int getVOMSMinorVersionNumber(void)
getVOMSPatchVersionNumber
int getVOMSPatchVersionNumber(void)
gss_cred_id_t
void * gss_cred_id_t
Definition voms_api.h:45
check_sig
bool(* check_sig)(X509 *, void *, verror_type &)
Definition voms_api.h:193
gss_ctx_id_t
void * gss_ctx_id_t
Definition voms_api.h:46
data_type
data_type
The type of data returned.
Definition voms_api.h:80
TYPE_CUSTOM
@ TYPE_CUSTOM
Definition voms_api.h:83
TYPE_NODATA
@ TYPE_NODATA
Definition voms_api.h:81
TYPE_STD
@ TYPE_STD
Definition voms_api.h:82
verify_type
verify_type
Definition voms_api.h:152
VERIFY_SIGN
@ VERIFY_SIGN
Definition voms_api.h:158
VERIFY_NONE
@ VERIFY_NONE
Definition voms_api.h:154
VERIFY_ORDER
@ VERIFY_ORDER
Definition voms_api.h:159
VERIFY_KEY
@ VERIFY_KEY
Definition voms_api.h:157
VERIFY_FULL
@ VERIFY_FULL
Definition voms_api.h:153
VERIFY_CERTLIST
@ VERIFY_CERTLIST
Definition voms_api.h:161
VERIFY_TARGET
@ VERIFY_TARGET
Definition voms_api.h:156
VERIFY_ID
@ VERIFY_ID
Definition voms_api.h:160
VERIFY_DATE
@ VERIFY_DATE
Definition voms_api.h:155
verror_type
verror_type
Error codes.
Definition voms_api.h:166
VERR_PARAM
@ VERR_PARAM
Definition voms_api.h:171
VERR_FILE
@ VERR_FILE
Definition voms_api.h:190
VERR_EXTRAINFO
@ VERR_EXTRAINFO
Definition voms_api.h:176
VERR_NOINIT
@ VERR_NOINIT
Definition voms_api.h:173
VERR_NONE
@ VERR_NONE
Definition voms_api.h:167
VERR_NOSOCKET
@ VERR_NOSOCKET
Definition voms_api.h:168
VERR_FORMAT
@ VERR_FORMAT
Definition voms_api.h:177
VERR_NOEXT
@ VERR_NOEXT
Definition voms_api.h:172
VERR_IDCHECK
@ VERR_IDCHECK
Definition voms_api.h:175
VERR_TIME
@ VERR_TIME
Definition voms_api.h:174
VERR_VERIFY
@ VERR_VERIFY
Definition voms_api.h:184
VERR_PARSE
@ VERR_PARSE
Definition voms_api.h:179
VERR_ORDER
@ VERR_ORDER
Definition voms_api.h:187
VERR_COMM
@ VERR_COMM
Definition voms_api.h:170
VERR_SERVERCODE
@ VERR_SERVERCODE
Definition voms_api.h:188
VERR_TYPE
@ VERR_TYPE
Definition voms_api.h:186
VERR_NODATA
@ VERR_NODATA
Definition voms_api.h:178
VERR_SIGN
@ VERR_SIGN
Definition voms_api.h:181
VERR_MEM
@ VERR_MEM
Definition voms_api.h:183
VERR_NOTAVAIL
@ VERR_NOTAVAIL
Definition voms_api.h:189
VERR_NOIDENT
@ VERR_NOIDENT
Definition voms_api.h:169
VERR_DIR
@ VERR_DIR
Definition voms_api.h:180
VERR_SERVER
@ VERR_SERVER
Definition voms_api.h:182
getVOMSMajorVersionNumber
int getVOMSMajorVersionNumber(void)