[64fa9ba] | 1 | #ifndef __ABAC_HH__ |
---|
| 2 | #define __ABAC_HH__ |
---|
| 3 | |
---|
[2af3b82] | 4 | #include <string> |
---|
[9dffbd6] | 5 | #include <vector> |
---|
| 6 | |
---|
[64fa9ba] | 7 | namespace ABAC { |
---|
| 8 | extern "C" { |
---|
| 9 | #include "abac.h" |
---|
| 10 | } |
---|
[8bd77b5] | 11 | static int debug=0; |
---|
| 12 | class Role; |
---|
| 13 | class Oset; |
---|
[7211a95] | 14 | class ID; |
---|
[5d06689] | 15 | |
---|
[2e9455f] | 16 | /*** |
---|
| 17 | ABAC::dump_yap_db() |
---|
| 18 | Dump the complete yap prolog database |
---|
| 19 | (C:show_yap_db) |
---|
| 20 | ABAC::dump_debug_info() |
---|
| 21 | Dump debug info on whole session |
---|
| 22 | (C:show_debug_info) |
---|
| 23 | ***/ |
---|
| 24 | void dump_yap_db() |
---|
| 25 | { show_yap_db("dump_yap"); } |
---|
| 26 | void dump_debug_info(const char *msg) |
---|
| 27 | { show_debug_info(msg); } |
---|
[d9c3886] | 28 | /*** |
---|
| 29 | ABAC::Constraint |
---|
[6e8997e] | 30 | Constraint on a data term. |
---|
| 31 | There are 3 types: |
---|
| 32 | - Role constraint on a principal |
---|
| 33 | - Oset constraint on a principal, or a data object |
---|
| 34 | - Range/List constraint on a data object |
---|
| 35 | It holds a ptr to a abac_condition_t structure |
---|
[d9c3886] | 36 | ***/ |
---|
[8bd77b5] | 37 | class Constraint { |
---|
| 38 | public: |
---|
[d9c3886] | 39 | /*** |
---|
[6e8997e] | 40 | f Constraint() |
---|
[ed3dc05] | 41 | default constructor, do not use, for swig only |
---|
[6e8997e] | 42 | f Constraint(const Constraint &) |
---|
[ed3dc05] | 43 | copy constructor, used for cloning a constraint |
---|
[2e9455f] | 44 | (C:abac_condition_dup) |
---|
[6e8997e] | 45 | f ~Constraint() |
---|
[ed3dc05] | 46 | default destructor |
---|
[2e9455f] | 47 | (C:abac_condition_free) |
---|
[d9c3886] | 48 | ***/ |
---|
| 49 | Constraint() : m_constraint(NULL) { } |
---|
[8bd77b5] | 50 | Constraint(const Constraint &constraint) { |
---|
[669b481] | 51 | m_constraint=abac_condition_dup(constraint.m_constraint); |
---|
[0b3ac65] | 52 | } |
---|
[8bd77b5] | 53 | ~Constraint() { |
---|
[0b3ac65] | 54 | if(m_constraint) abac_condition_free(m_constraint); |
---|
| 55 | } |
---|
[d9c3886] | 56 | /*** |
---|
[6e8997e] | 57 | f Constraint(Role &) |
---|
[ed3dc05] | 58 | constructor that takes a constraining role |
---|
| 59 | [role:?R[{role-constraint}] |
---|
[669b481] | 60 | (C:abac_constraint_from_role) |
---|
[6e8997e] | 61 | f Constraint(Oset &) |
---|
[ed3dc05] | 62 | constructor that takes a constraining oset |
---|
| 63 | [oset:?O[{oset-constraint}] |
---|
| 64 | [urn:?F[keyid:$alpha_keyid].oset:documents([string:?P])] |
---|
[669b481] | 65 | (C:abac_constraint_from_oset) |
---|
[6e8997e] | 66 | f Constraint(char *) |
---|
[ed3dc05] | 67 | constructor that takes one of following string |
---|
| 68 | as its vartype to set up a range constraint: |
---|
| 69 | "integer" |
---|
| 70 | "urn" |
---|
| 71 | "float" |
---|
| 72 | "boolean" |
---|
| 73 | "time" |
---|
| 74 | "string" |
---|
| 75 | it should be followed with one or many of following utility |
---|
| 76 | calls. |
---|
[669b481] | 77 | (C:abac_constraint_create) |
---|
[d9c3886] | 78 | ***/ |
---|
[2e9455f] | 79 | Constraint(Role& role); /* defined later in the class */ |
---|
| 80 | Constraint(Oset& oset); /* defined later in the class */ |
---|
[5d06689] | 81 | Constraint(char *vartype) |
---|
[669b481] | 82 | { m_constraint=abac_constraint_create(vartype); } |
---|
[5d06689] | 83 | /*ii** |
---|
| 84 | f Constraint(abac_condition_t *) |
---|
| 85 | internal constructor that takes an abac_condition_t structure |
---|
[2e9455f] | 86 | (C:abac_condition_dup) |
---|
[5d06689] | 87 | **ii*/ |
---|
[0b3ac65] | 88 | Constraint(abac_condition_t *constraint): |
---|
[d9c3886] | 89 | m_constraint(abac_condition_dup(constraint)) |
---|
[0b3ac65] | 90 | { } |
---|
[d9c3886] | 91 | /*** |
---|
[5d06689] | 92 | f void constraint_add_integer_max(int) |
---|
[669b481] | 93 | (C:abac_constraint_add_integer_max) |
---|
[5d06689] | 94 | void constraint_add_integer_min(int) |
---|
[ed3dc05] | 95 | utility routines to setup a integer range constraint |
---|
| 96 | [integer:?I[10 .. 20]] |
---|
[669b481] | 97 | (C:abac_constraint_add_integer_min) |
---|
[5d06689] | 98 | f void constraint_add_integer_target(int) |
---|
[ed3dc05] | 99 | utility routine to setup a integer list constraint |
---|
| 100 | [integer:?I[10,20]] |
---|
[669b481] | 101 | (C:abac_constraint_add_integer_target) |
---|
[d9c3886] | 102 | ***/ |
---|
[5d06689] | 103 | void constraint_add_integer_max(int val) |
---|
| 104 | { abac_constraint_add_integer_max(m_constraint,val); } |
---|
| 105 | void constraint_add_integer_min(int val) |
---|
| 106 | { abac_constraint_add_integer_min(m_constraint,val); } |
---|
| 107 | void constraint_add_integer_target(int val) |
---|
| 108 | { abac_constraint_add_integer_target(m_constraint,val); } |
---|
[d9c3886] | 109 | /*** |
---|
[5d06689] | 110 | f void constraint_add_float_max(float) |
---|
[669b481] | 111 | (C:abac_constraint_add_float_max) |
---|
[5d06689] | 112 | void constraint_add_float_min(float) |
---|
[ed3dc05] | 113 | utility routines to setup a float range constraint |
---|
| 114 | [float:?F[1.0 .. 2.5]] |
---|
[669b481] | 115 | (C:abac_constraint_add_float_min) |
---|
[5d06689] | 116 | f void constraint_add_float_target(float) |
---|
[ed3dc05] | 117 | utility routine to setup a float list constraint |
---|
| 118 | [float:?F[0.5, 2.5]] |
---|
[669b481] | 119 | (C:abac_constraint_add_float_target) |
---|
[d9c3886] | 120 | ***/ |
---|
[5d06689] | 121 | void constraint_add_float_max(float val) |
---|
| 122 | { abac_constraint_add_float_max(m_constraint,val); } |
---|
| 123 | void constraint_add_float_min(float val) |
---|
| 124 | { abac_constraint_add_float_min(m_constraint,val); } |
---|
| 125 | void constraint_add_float_target(float val) |
---|
| 126 | { abac_constraint_add_float_target(m_constraint,val); } |
---|
[0b3ac65] | 127 | /*** |
---|
[5d06689] | 128 | f void constraint_add_time_max(char*) |
---|
[669b481] | 129 | (C:abac_constraint_add_time_max) |
---|
[5d06689] | 130 | void constraint_add_time_min(char*) |
---|
[ed3dc05] | 131 | utility routines to setup a time range constraint, |
---|
| 132 | takes quoted string values, beyond T is optional |
---|
[6e8997e] | 133 | [time:?F["20120228T" .. "20120228T090000"]] |
---|
[669b481] | 134 | (C:abac_constraint_add_time_min) |
---|
[5d06689] | 135 | f void constraint_add_time_target(char*) |
---|
[ed3dc05] | 136 | utility routine to setup a time list constraint |
---|
[6e8997e] | 137 | [time:?M["20201101T182930","20201101T"]] |
---|
[669b481] | 138 | (C:abac_constraint_add_time_target) |
---|
[0b3ac65] | 139 | ***/ |
---|
[5d06689] | 140 | void constraint_add_time_max(char* val) |
---|
| 141 | { abac_constraint_add_time_max(m_constraint,val); } |
---|
| 142 | void constraint_add_time_min(char* val) |
---|
| 143 | { abac_constraint_add_time_min(m_constraint,val); } |
---|
| 144 | void constraint_add_time_target(char* val) |
---|
| 145 | { abac_constraint_add_time_target(m_constraint,val); } |
---|
[0b3ac65] | 146 | /*** |
---|
[5d06689] | 147 | f void constraint_add_urn_target(char*) |
---|
[ed3dc05] | 148 | utility routine to setup a an urn list constraint |
---|
| 149 | [urn:?U["fileA","http://fileB"]] |
---|
[669b481] | 150 | (C:abac_constraint_add_urn_target) |
---|
[5d06689] | 151 | f void constraint_add_string_target(char*) |
---|
[ed3dc05] | 152 | utility routine to setup a a string list constraint |
---|
| 153 | [string:?S["abc",'efg',"hij"]] |
---|
[669b481] | 154 | (C:abac_constraint_add_string_target) |
---|
[5d06689] | 155 | f void constraint_add_boolean_target(char*) |
---|
[ed3dc05] | 156 | utility routine to setup a a boolean list constraint |
---|
| 157 | [boolean:?B['true']] |
---|
[669b481] | 158 | (C:abac_constraint_add_boolean_target) |
---|
[0b3ac65] | 159 | ***/ |
---|
[5d06689] | 160 | void constraint_add_urn_target(char* val) |
---|
| 161 | { abac_constraint_add_urn_target(m_constraint,val); } |
---|
| 162 | void constraint_add_string_target(char* val) |
---|
| 163 | { abac_constraint_add_string_target(m_constraint,val); } |
---|
| 164 | void constraint_add_boolean_target(char* val) |
---|
| 165 | { abac_constraint_add_boolean_target(m_constraint,val); } |
---|
[0b3ac65] | 166 | /*** |
---|
[6e8997e] | 167 | f char *string() const |
---|
[ed3dc05] | 168 | returns literal string of the constraint |
---|
[669b481] | 169 | (C:abac_constraint_string) |
---|
[6e8997e] | 170 | f char *typed_string() const |
---|
[ed3dc05] | 171 | returns typed literal string of the constraint |
---|
[669b481] | 172 | (C:abac_constraint_typed_string) |
---|
[0b3ac65] | 173 | ***/ |
---|
| 174 | char *string() const |
---|
[5f551d3] | 175 | { return abac_constraint_string(m_constraint); } |
---|
[0b3ac65] | 176 | char *typed_string() const |
---|
[5f551d3] | 177 | { return abac_constraint_typed_string(m_constraint); } |
---|
[5d06689] | 178 | /*ii** |
---|
[6e8997e] | 179 | f abac_condition_t *constraint() |
---|
[5d06689] | 180 | internal returns internal constraint structure |
---|
[2e9455f] | 181 | (S:abac_condition_t) |
---|
[5d06689] | 182 | **ii*/ |
---|
[2e9455f] | 183 | abac_condition_t *constraint() { return m_constraint; } |
---|
[8bd77b5] | 184 | private: |
---|
| 185 | abac_condition_t *m_constraint; |
---|
| 186 | }; |
---|
| 187 | |
---|
[0b3ac65] | 188 | /*** |
---|
| 189 | ABAC::DataTerm |
---|
[ed3dc05] | 190 | A data term is associated with Role or Oset as a parameter that |
---|
| 191 | maybe be instantiated, or uninstantiated but being constrained, |
---|
[0b3ac65] | 192 | or as a principal oset term (standalone right handside of an oset |
---|
[7211a95] | 193 | policy rule). It holds a pointer to a abac_term_t structure. |
---|
| 194 | Types of data terms are: |
---|
| 195 | "integer" |
---|
| 196 | "urn" |
---|
| 197 | "float" |
---|
| 198 | "boolean" |
---|
| 199 | "string" |
---|
| 200 | "time" |
---|
| 201 | "principal" |
---|
| 202 | "anonymous" |
---|
[2e9455f] | 203 | "this" |
---|
[0b3ac65] | 204 | ***/ |
---|
[8bd77b5] | 205 | class DataTerm { |
---|
| 206 | public: |
---|
[0b3ac65] | 207 | /*** |
---|
[6e8997e] | 208 | f DataTerm() |
---|
[ed3dc05] | 209 | default constructor, do not use, for swig only |
---|
[6e8997e] | 210 | f DataTerm(const DataTerm &) |
---|
[ed3dc05] | 211 | copy constructor, used for cloning a data term |
---|
[2e9455f] | 212 | (C:abac_term_dup) |
---|
[6e8997e] | 213 | f ~DataTerm() |
---|
[ed3dc05] | 214 | default destructor |
---|
[2e9455f] | 215 | (C:abac_term_free) |
---|
[0b3ac65] | 216 | ***/ |
---|
[8bd77b5] | 217 | DataTerm() : m_term(NULL) { } // do not use: here for swig |
---|
[0b3ac65] | 218 | DataTerm(const DataTerm &dterm) { |
---|
[5d06689] | 219 | m_term=abac_term_dup(dterm.m_term); |
---|
[0b3ac65] | 220 | } |
---|
[8bd77b5] | 221 | ~DataTerm() { |
---|
[0b3ac65] | 222 | if(m_term) abac_term_free(m_term); |
---|
| 223 | } |
---|
[5d06689] | 224 | /*ii** |
---|
[6e8997e] | 225 | f DataTerm(abac_term_t *) |
---|
[5d06689] | 226 | internal constructor to make data term from abac_term_t structure |
---|
[2e9455f] | 227 | (C:abac_term_dup) |
---|
[5d06689] | 228 | **ii*/ |
---|
| 229 | DataTerm(abac_term_t *term) |
---|
| 230 | { m_term=abac_term_dup(term); } |
---|
[0b3ac65] | 231 | /*** |
---|
[6e8997e] | 232 | f DataTerm(char*) |
---|
[ed3dc05] | 233 | constructor to make named principal data term for the oset RHS |
---|
[2e9455f] | 234 | if "this" is supplied, a term with tyep=e_TERM_THIS is created |
---|
| 235 | if "anonymous" is supplied, a term with type=e_TERM_ANONYMOUS is created |
---|
| 236 | (C:abac_term_named_create) |
---|
[7211a95] | 237 | f DataTerm(const ID&) |
---|
[669b481] | 238 | constructor to make named principal data term for parameter term |
---|
[2e9455f] | 239 | (C:abac_term_id_create) |
---|
[6e8997e] | 240 | f DataTerm(char*, char*, Constraint*) |
---|
[5d06689] | 241 | constructor for making a variable data term |
---|
[2e9455f] | 242 | (C:abac_term_create) |
---|
[5d06689] | 243 | f DataTerm(char*, char*) |
---|
| 244 | constructor for making an instantiated data term |
---|
[2e9455f] | 245 | (C:abac_term_create) |
---|
[0b3ac65] | 246 | ***/ |
---|
[7211a95] | 247 | DataTerm(char *name) { |
---|
| 248 | if(debug) printf("adding a Dataterm named principal(%s)\n",name); |
---|
| 249 | m_term=abac_term_named_create(name); |
---|
[d037f54] | 250 | } |
---|
[2e9455f] | 251 | DataTerm(ID& id); /* defined later in the class */ |
---|
[5d06689] | 252 | DataTerm(char* typenm, char *name, Constraint *cond) { |
---|
[0b3ac65] | 253 | if(debug) printf("adding a Dataterm (%s)\n",name); |
---|
[5d06689] | 254 | m_term=abac_term_create(typenm,name,cond->constraint()); |
---|
| 255 | } |
---|
| 256 | DataTerm(char* typenm, char *name) { |
---|
| 257 | if(debug) printf("adding a Dataterm (%s)\n",name); |
---|
| 258 | m_term=abac_term_create(typenm,name,NULL); |
---|
[0b3ac65] | 259 | } |
---|
| 260 | /*** |
---|
[6e8997e] | 261 | f char *string() const |
---|
[ed3dc05] | 262 | returns literal string of the data term |
---|
[669b481] | 263 | (C:abac_term_string) |
---|
[6e8997e] | 264 | f char *typed_string() const |
---|
[ed3dc05] | 265 | returns typed literal string of the data term |
---|
[669b481] | 266 | (C:abac_term_typed_string) |
---|
[0b3ac65] | 267 | ***/ |
---|
| 268 | char *string() const |
---|
| 269 | { return abac_term_string(m_term); } |
---|
| 270 | char *typed_string() const |
---|
| 271 | { return abac_term_typed_string(m_term); } |
---|
| 272 | /*** |
---|
[5d06689] | 273 | f bool term_is_time() const |
---|
[669b481] | 274 | (C:abac_term_is_time) |
---|
[5d06689] | 275 | bool term_is_string() const |
---|
[669b481] | 276 | (C:abac_term_is_string) |
---|
[5d06689] | 277 | bool term_is_urn() const |
---|
[669b481] | 278 | (C:abac_term_is_urn) |
---|
[5d06689] | 279 | bool term_is_integer() const |
---|
[669b481] | 280 | (C:abac_term_is_integer) |
---|
[ed3dc05] | 281 | returns true if data term is of certain type |
---|
[0b3ac65] | 282 | ***/ |
---|
[5d06689] | 283 | bool term_is_time() const |
---|
| 284 | { return abac_term_is_time(m_term); } |
---|
| 285 | bool term_is_string() const |
---|
| 286 | { return abac_term_is_string(m_term); } |
---|
| 287 | bool term_is_urn() const |
---|
| 288 | { return abac_term_is_urn(m_term); } |
---|
| 289 | bool term_is_integer() const |
---|
| 290 | { return abac_term_is_integer(m_term); } |
---|
[0b3ac65] | 291 | /*** |
---|
[5d06689] | 292 | f int term_add_constraint(Contraint&) |
---|
[ed3dc05] | 293 | utiltiy routine to add a constraint to this data term |
---|
[669b481] | 294 | (C:abac_term_add_constraint) |
---|
[0b3ac65] | 295 | ***/ |
---|
[5d06689] | 296 | int term_add_constraint(Constraint& cond) { |
---|
| 297 | abac_term_add_constraint(m_term, cond.constraint()); |
---|
| 298 | return 1; |
---|
[0b3ac65] | 299 | } |
---|
| 300 | /*** |
---|
[5d06689] | 301 | f int term_type() const |
---|
[ed3dc05] | 302 | returns subtype of the data term |
---|
[669b481] | 303 | (C:abac_term_type) |
---|
[5d06689] | 304 | f char *term_name() const |
---|
[ed3dc05] | 305 | returns the name of the data term |
---|
[669b481] | 306 | (C:abac_term_name) |
---|
[0b3ac65] | 307 | ***/ |
---|
[5d06689] | 308 | int term_type() const |
---|
[0b3ac65] | 309 | { abac_term_type(m_term); } |
---|
[5d06689] | 310 | char *term_name() const |
---|
[0b3ac65] | 311 | { return abac_term_name(m_term); } |
---|
[5d06689] | 312 | /*ii** |
---|
[6e8997e] | 313 | f abac_term_t *term() |
---|
[5d06689] | 314 | returns abac_term_t term structure |
---|
[2e9455f] | 315 | (S:abac_term_t) |
---|
[5d06689] | 316 | **ii*/ |
---|
[2e9455f] | 317 | abac_term_t *term() { return m_term; } |
---|
[8bd77b5] | 318 | private: |
---|
| 319 | abac_term_t *m_term; |
---|
| 320 | }; |
---|
| 321 | |
---|
| 322 | |
---|
[ed3dc05] | 323 | /*** |
---|
| 324 | ABAC::Role |
---|
[6e8997e] | 325 | A Role is role specification of a set of entitities for a principal |
---|
[ed3dc05] | 326 | ***/ |
---|
[2af3b82] | 327 | class Role { |
---|
| 328 | public: |
---|
[ed3dc05] | 329 | /*** |
---|
[6e8997e] | 330 | f Role() |
---|
[ed3dc05] | 331 | default constructor, do not use, for swig only |
---|
[6e8997e] | 332 | f Role(const Role &) |
---|
[ed3dc05] | 333 | copy constructor, used for cloning a role |
---|
[2e9455f] | 334 | (C:abac_aspect_dup) |
---|
[6e8997e] | 335 | f ~Role() |
---|
[ed3dc05] | 336 | default destructor |
---|
[2e9455f] | 337 | (C:abac_aspect_free) |
---|
[ed3dc05] | 338 | ***/ |
---|
[8bd77b5] | 339 | Role() : m_role(NULL) { } // do not use: here for swig |
---|
[ed3dc05] | 340 | Role(const Role &role) { |
---|
| 341 | m_role = abac_aspect_dup(role.m_role); |
---|
| 342 | } |
---|
| 343 | ~Role() { |
---|
| 344 | if (m_role) abac_aspect_free(m_role); |
---|
| 345 | } |
---|
[5d06689] | 346 | /*ii** |
---|
[6e8997e] | 347 | f Role(abac_aspect_t*) |
---|
[ed3dc05] | 348 | constructor that takes an abac_aspect_t structure |
---|
[2e9455f] | 349 | (C:abac_aspect_dup) |
---|
[5d06689] | 350 | **ii*/ |
---|
| 351 | Role(abac_aspect_t *role): m_role(abac_aspect_dup(role)) |
---|
| 352 | { } |
---|
| 353 | /*** |
---|
[6e8997e] | 354 | f Role(char*) |
---|
[ed3dc05] | 355 | constructor that builds a bare bone role with just principal's name |
---|
[669b481] | 356 | (C:abac_role_principal_create) |
---|
[6e8997e] | 357 | f Role(char*, char*) |
---|
[ed3dc05] | 358 | constructor that builds a bare bone role with just principal's name |
---|
| 359 | and a role name |
---|
[669b481] | 360 | (C:abac_role_create) |
---|
[7211a95] | 361 | f Role(char*, char*, char*) |
---|
| 362 | constructor that builds a bare bone role with just principal's name |
---|
| 363 | and a linking role name and a role name |
---|
[669b481] | 364 | (C:abac_role_linked_create) |
---|
[ed3dc05] | 365 | ***/ |
---|
[8bd77b5] | 366 | Role(char *principal_name) : |
---|
[5d06689] | 367 | m_role(abac_role_principal_create(principal_name)) |
---|
[ed3dc05] | 368 | { } |
---|
[8bd77b5] | 369 | Role(char *principal_name, char *role_name) : |
---|
[5d06689] | 370 | m_role(abac_role_create(principal_name, role_name)) |
---|
[ed3dc05] | 371 | { } |
---|
[7211a95] | 372 | Role(char *principal_name, char *linked_role_name, char *role_name) : |
---|
| 373 | m_role(abac_role_linked_create(principal_name, linked_role_name,role_name)) |
---|
| 374 | { } |
---|
[ed3dc05] | 375 | /*** |
---|
[5d06689] | 376 | f bool role_is_principal() const |
---|
[ed3dc05] | 377 | return true if the role is a principal object(made from |
---|
| 378 | a data term), the right hand side of, |
---|
| 379 | [keyid:A].role:r <- [keyid:B] |
---|
[669b481] | 380 | (C:abac_role_is_principal) |
---|
[ed3dc05] | 381 | ***/ |
---|
[5d06689] | 382 | bool role_is_principal() const |
---|
| 383 | { return abac_role_is_principal(m_role); } |
---|
[ed3dc05] | 384 | /*** |
---|
[5d06689] | 385 | f bool role_is_linking() const |
---|
[ed3dc05] | 386 | returns true if the role is a linking role like |
---|
| 387 | the right hand side of, |
---|
| 388 | [keyid:A].role:r1 <- [keyid:B].role:r2.role:r3 |
---|
[669b481] | 389 | (C:abac_role_is_linking) |
---|
[ed3dc05] | 390 | ***/ |
---|
| 391 | bool is_linking() const |
---|
[5d06689] | 392 | { return abac_role_is_linking(m_role); } |
---|
[ed3dc05] | 393 | /*** |
---|
[6e8997e] | 394 | f char *string() const |
---|
[ed3dc05] | 395 | returns literal string of the role |
---|
[669b481] | 396 | (C:abac_role_string) |
---|
[6e8997e] | 397 | f char *typed_string() const |
---|
[ed3dc05] | 398 | returns typed literal string of the role |
---|
[669b481] | 399 | (C:abac_role_typed_string) |
---|
[ed3dc05] | 400 | ***/ |
---|
| 401 | char *string() const |
---|
[669b481] | 402 | { return abac_role_string(m_role); } |
---|
[ed3dc05] | 403 | char *typed_string() |
---|
[669b481] | 404 | { return abac_role_typed_string(m_role); } |
---|
[ed3dc05] | 405 | /*** |
---|
[5d06689] | 406 | f char *role_linked_role() const |
---|
[ed3dc05] | 407 | returns linked part of a linking role, for |
---|
[6e8997e] | 408 | [keyid:A].role:r1.role:r2, it returns r1 |
---|
[669b481] | 409 | (C:abac_role_linked_role) |
---|
[ed3dc05] | 410 | ***/ |
---|
[5d06689] | 411 | char *role_linked_role() const |
---|
| 412 | { return abac_role_linked_role(m_role); } |
---|
[ed3dc05] | 413 | /*** |
---|
[6e8997e] | 414 | f char *role_name() const |
---|
[ed3dc05] | 415 | returns the role name of any role (the part after the last dot) |
---|
[6e8997e] | 416 | [keyid:A].role.r1.role:r2, it returns r2 |
---|
| 417 | [keyid:A].role.r1, it returns r1 |
---|
[669b481] | 418 | (C:abac_role_name) |
---|
[5d06689] | 419 | f char *role_principal() const |
---|
| 420 | returns the principal of role (the part before the first dot) |
---|
| 421 | [keyid:A].role.r1, it returns A |
---|
[669b481] | 422 | (C:abac_role_principal) |
---|
[ed3dc05] | 423 | ***/ |
---|
| 424 | char *role_name() const |
---|
[5d06689] | 425 | { return abac_role_name(m_role); } |
---|
| 426 | char *role_principal() const |
---|
| 427 | { return abac_role_principal(m_role); } |
---|
[ed3dc05] | 428 | |
---|
| 429 | /*** |
---|
[5d06689] | 430 | f void role_add_data_term(DataTerm&) |
---|
[ed3dc05] | 431 | add a data term to the role |
---|
[669b481] | 432 | (C:abac_role_add_data_term) |
---|
[ed3dc05] | 433 | ***/ |
---|
[5d06689] | 434 | void role_add_data_term(DataTerm& d) { |
---|
| 435 | abac_role_add_data_term(m_role, d.term()); |
---|
[ed3dc05] | 436 | } |
---|
| 437 | /*** |
---|
[6e8997e] | 438 | f std::vector<DataTerm> get_data_terms(bool &) |
---|
[ed3dc05] | 439 | return the data terms bound to this role. |
---|
[669b481] | 440 | (C:abac_role_get_data_terms) |
---|
[ed3dc05] | 441 | ***/ |
---|
[d037f54] | 442 | std::vector<DataTerm> get_data_terms(bool &success) { |
---|
[ed3dc05] | 443 | abac_term_t **terms, **end; |
---|
| 444 | int i; |
---|
[669b481] | 445 | terms = abac_role_get_data_terms(m_role); |
---|
[ed3dc05] | 446 | for (i = 0; terms[i] != NULL; ++i) |
---|
| 447 | ; |
---|
| 448 | end = &terms[i]; |
---|
| 449 | std::vector<DataTerm> dataterms = std::vector<DataTerm>(terms, end); |
---|
| 450 | abac_terms_free(terms); |
---|
| 451 | success=1; |
---|
| 452 | return dataterms; |
---|
| 453 | } |
---|
[5d06689] | 454 | /*** |
---|
| 455 | f void role_add_linked_data_term(DataTerm&) |
---|
| 456 | add a data term to the linking role |
---|
[669b481] | 457 | (C:abac_role_add_linked_data_term) |
---|
[5d06689] | 458 | ***/ |
---|
| 459 | void role_add_linked_data_term(DataTerm& d) { |
---|
| 460 | abac_role_add_linked_data_term(m_role, d.term()); |
---|
[ed3dc05] | 461 | } |
---|
| 462 | /*** |
---|
[6e8997e] | 463 | f std::vector<DataTerm> get_linked_data_terms(bool &) |
---|
[ed3dc05] | 464 | return the data terms bound to this role's linking role. |
---|
[669b481] | 465 | (C:abac_role_get_linked_data_terms) |
---|
[2e9455f] | 466 | (C::abac_terms_free) |
---|
[ed3dc05] | 467 | ***/ |
---|
[d037f54] | 468 | std::vector<DataTerm> get_linked_data_terms(bool &success) { |
---|
[ed3dc05] | 469 | abac_term_t **terms, **end; |
---|
| 470 | int i; |
---|
[669b481] | 471 | terms = abac_role_get_linked_data_terms(m_role); |
---|
[ed3dc05] | 472 | for (i = 0; terms[i] != NULL; ++i) |
---|
| 473 | ; |
---|
| 474 | end = &terms[i]; |
---|
| 475 | std::vector<DataTerm> dataterms = std::vector<DataTerm>(terms, end); |
---|
| 476 | abac_terms_free(terms); |
---|
| 477 | success=1; |
---|
| 478 | return dataterms; |
---|
| 479 | } |
---|
[5d06689] | 480 | /*ii** |
---|
[6e8997e] | 481 | f abac_aspect_t *role() |
---|
[ed3dc05] | 482 | returns the interal libabac representation of this role |
---|
[2e9455f] | 483 | (S:abac_aspect_t) |
---|
[5d06689] | 484 | **ii*/ |
---|
[8bd77b5] | 485 | abac_aspect_t *role() {return m_role;} |
---|
[2af3b82] | 486 | private: |
---|
[8bd77b5] | 487 | abac_aspect_t *m_role; |
---|
[2af3b82] | 488 | }; |
---|
| 489 | |
---|
[ed3dc05] | 490 | /*** |
---|
| 491 | ABAC::Oset |
---|
[6e8997e] | 492 | An Oset is oset specification of a set of entitities for a principal |
---|
[ed3dc05] | 493 | ***/ |
---|
[8bd77b5] | 494 | class Oset { |
---|
[9dffbd6] | 495 | public: |
---|
[ed3dc05] | 496 | /*** |
---|
[6e8997e] | 497 | f Oset() |
---|
[ed3dc05] | 498 | default constructor, do not use, for swig only |
---|
[6e8997e] | 499 | f Oset(const Oset &) |
---|
[ed3dc05] | 500 | copy constructor, used for cloning an oset |
---|
[2e9455f] | 501 | (C:abac_aspect_dup) |
---|
[6e8997e] | 502 | f ~Oset() |
---|
[ed3dc05] | 503 | default destructor |
---|
[2e9455f] | 504 | (C:abac_aspect_free) |
---|
[ed3dc05] | 505 | ***/ |
---|
[8bd77b5] | 506 | Oset() : m_oset(NULL) { } // do not use: here for swig |
---|
[ed3dc05] | 507 | Oset(const Oset &oset) |
---|
| 508 | { m_oset =abac_aspect_dup(oset.m_oset); } |
---|
| 509 | ~Oset() |
---|
| 510 | { if(m_oset) abac_aspect_free(m_oset); } |
---|
[5d06689] | 511 | /*ii** |
---|
[6e8997e] | 512 | f Oset(abac_aspect_t *) |
---|
[ed3dc05] | 513 | constructor that takes abac_aspect_t structure |
---|
[2e9455f] | 514 | (C:abac_aspect_dup) |
---|
[5d06689] | 515 | **ii*/ |
---|
| 516 | Oset(abac_aspect_t *oset): m_oset(abac_aspect_dup(oset)) |
---|
| 517 | { } |
---|
| 518 | /*** |
---|
[6e8997e] | 519 | f Oset(char *) |
---|
[ed3dc05] | 520 | constructor that makes a principal oset, ie [keyid:B] |
---|
[2e9455f] | 521 | (C:abac_oset_principal_create) |
---|
[6e8997e] | 522 | f Oset(char *, char *) |
---|
[ed3dc05] | 523 | constructor that makes a regular oset, ie. [keyid:B].oset:o |
---|
[2e9455f] | 524 | (C:abac_oset_create) |
---|
[7211a95] | 525 | f Oset(char *, char*, char *) |
---|
| 526 | constructor that makes a linked oset, ie. [keyid:B].role:r.oset:o |
---|
[669b481] | 527 | (C:abac_oset_linked_create) |
---|
[6e8997e] | 528 | f Oset(DataTerm&) |
---|
[ed3dc05] | 529 | constructor that makes an object oset, ie. [urn:'file/fileA'] |
---|
[669b481] | 530 | (C:abac_oset_object_create) |
---|
[ed3dc05] | 531 | ***/ |
---|
[5d06689] | 532 | Oset(char *oset_name) : m_oset(abac_oset_principal_create(oset_name)) |
---|
[ed3dc05] | 533 | { } |
---|
[8bd77b5] | 534 | Oset(char *principal_name, char *oset_name) : |
---|
[5d06689] | 535 | m_oset(abac_oset_create(principal_name, oset_name)) |
---|
[ed3dc05] | 536 | { } |
---|
[7211a95] | 537 | Oset(char *principal_name, char *linked_role_name,char *oset_name) : |
---|
| 538 | m_oset(abac_oset_linked_create(principal_name, linked_role_name, oset_name)) |
---|
| 539 | { } |
---|
[5110d42] | 540 | Oset(DataTerm& d) : |
---|
[5d06689] | 541 | m_oset(abac_oset_object_create(d.term())) |
---|
[ed3dc05] | 542 | { } |
---|
| 543 | |
---|
| 544 | /*** |
---|
[5d06689] | 545 | f bool oset_is_object(), ie <- [integer:10] |
---|
[ed3dc05] | 546 | return ture if this oset is an object oset |
---|
[669b481] | 547 | (C:abac_oset_is_object) |
---|
[ed3dc05] | 548 | ***/ |
---|
[5d06689] | 549 | bool oset_is_object() const |
---|
| 550 | { return abac_oset_is_object(m_oset); } |
---|
[ed3dc05] | 551 | /*** |
---|
[5d06689] | 552 | f bool oset_is_principal() const |
---|
[ed3dc05] | 553 | return true if the oset is a principal object(made from |
---|
| 554 | a data term), the right hand side of, |
---|
| 555 | [keyid:A].oset:o <- [keyid:B] |
---|
[669b481] | 556 | (C:abac_oset_is_principal) |
---|
[ed3dc05] | 557 | ***/ |
---|
[5d06689] | 558 | bool oset_is_principal() const |
---|
| 559 | { return abac_oset_is_principal(m_oset); } |
---|
[ed3dc05] | 560 | /*** |
---|
[5d06689] | 561 | f bool oset_is_linking() const |
---|
[ed3dc05] | 562 | returns true if the oset is a linking oset like |
---|
| 563 | the right hand side of, |
---|
| 564 | [keyid:A].oset:o1 <- [keyid:B].role:r1.oset:o2 |
---|
[669b481] | 565 | (C:abac_oset_is_linking) |
---|
[ed3dc05] | 566 | ***/ |
---|
[5d06689] | 567 | bool oset_is_linking() const |
---|
| 568 | { return abac_oset_is_linking(m_oset); } |
---|
[ed3dc05] | 569 | /*** |
---|
[6e8997e] | 570 | f char *string() const |
---|
[ed3dc05] | 571 | returns literal string of the oset |
---|
[669b481] | 572 | (C:abac_oset_string) |
---|
[6e8997e] | 573 | f char *typed_string() const |
---|
[ed3dc05] | 574 | returns typed literal string of the oset |
---|
[669b481] | 575 | (C:abac_oset_typed_string) |
---|
[ed3dc05] | 576 | ***/ |
---|
| 577 | char *string() const |
---|
[669b481] | 578 | { return abac_oset_string(m_oset); } |
---|
[ed3dc05] | 579 | char *typed_string() |
---|
[669b481] | 580 | { return abac_oset_typed_string(m_oset); } |
---|
[ed3dc05] | 581 | /*** |
---|
[5d06689] | 582 | f char *oset_linked_role() const |
---|
[ed3dc05] | 583 | returns linked part of a linking oset, for |
---|
[6e8997e] | 584 | [keyid:A].role:r1.oset:o1, it returns r1 |
---|
[669b481] | 585 | (C:abac_oset_linked_role) |
---|
[ed3dc05] | 586 | ***/ |
---|
[5d06689] | 587 | char *oset_linked_role() const |
---|
| 588 | { return abac_oset_linked_role(m_oset); } |
---|
[ed3dc05] | 589 | /*** |
---|
[6e8997e] | 590 | f char *oset_name() const |
---|
[ed3dc05] | 591 | returns oset name, |
---|
[6e8997e] | 592 | [keyid:A].role:r1.oset:o1, it returns o1 |
---|
| 593 | [keyid:A].oset:o1, it returns o1 |
---|
[669b481] | 594 | (C:abac_oset_name) |
---|
[ed3dc05] | 595 | ***/ |
---|
| 596 | char *oset_name() const |
---|
[5d06689] | 597 | { return abac_oset_name(m_oset); } |
---|
[ed3dc05] | 598 | /*** |
---|
[5d06689] | 599 | f char *oset_principal() const |
---|
[ed3dc05] | 600 | returns principal name, |
---|
[6e8997e] | 601 | [keyid:A].role:r1.oset:o1, it returns A |
---|
[669b481] | 602 | (C:abac_oset_principal) |
---|
[ed3dc05] | 603 | ***/ |
---|
[5d06689] | 604 | char *oset_principal() const |
---|
| 605 | { return abac_oset_principal(m_oset); } |
---|
[ed3dc05] | 606 | /*** |
---|
[5d06689] | 607 | f char *oset_object() const |
---|
[ed3dc05] | 608 | returns object's name when the oset is a principal object |
---|
[6e8997e] | 609 | [keyid:A].oset:values <- [integer:10], it returns 10 |
---|
[669b481] | 610 | (C:abac_oset_object) |
---|
[ed3dc05] | 611 | ***/ |
---|
[5d06689] | 612 | char *oset_object() const |
---|
| 613 | { return abac_oset_object(m_oset); } |
---|
[ed3dc05] | 614 | /*** |
---|
[5d06689] | 615 | f void add_data_term(DataTerm&) |
---|
[ed3dc05] | 616 | add a data term to this oset's parameter set |
---|
[669b481] | 617 | (C:abac_oset_add_data_term) |
---|
[ed3dc05] | 618 | ***/ |
---|
[5d06689] | 619 | void oset_add_data_term(DataTerm& d) { |
---|
| 620 | abac_oset_add_data_term(m_oset, d.term()); |
---|
[ed3dc05] | 621 | } |
---|
| 622 | /*** |
---|
[6e8997e] | 623 | f std::vector<DataTerm> get_data_terms(bool &) |
---|
[ed3dc05] | 624 | returns the data terms bound to this oset. |
---|
[669b481] | 625 | (C:abac_oset_get_data_terms) |
---|
[2e9455f] | 626 | (C::abac_terms_free) |
---|
[ed3dc05] | 627 | ***/ |
---|
[d037f54] | 628 | std::vector<DataTerm> get_data_terms(bool &success) { |
---|
[ed3dc05] | 629 | abac_term_t **terms, **end; |
---|
| 630 | int i; |
---|
[669b481] | 631 | terms = abac_oset_get_data_terms(m_oset); |
---|
[ed3dc05] | 632 | for (i = 0; terms[i] != NULL; ++i) |
---|
| 633 | ; |
---|
| 634 | end = &terms[i]; |
---|
| 635 | std::vector<DataTerm> dataterms = std::vector<DataTerm>(terms, end); |
---|
| 636 | abac_terms_free(terms); |
---|
| 637 | success=1; |
---|
| 638 | return dataterms; |
---|
| 639 | } |
---|
| 640 | /*** |
---|
[5d06689] | 641 | f void oset_add_linked_data_term(DataTerm&) |
---|
[ed3dc05] | 642 | add a data term to this oset's linking role's parameter set. |
---|
[669b481] | 643 | (C:abac_oset_add_linked_data_term) |
---|
[ed3dc05] | 644 | ***/ |
---|
[5d06689] | 645 | void oset_add_linked_data_term(DataTerm& d) { |
---|
| 646 | abac_oset_add_linked_data_term(m_oset, d.term()); |
---|
[ed3dc05] | 647 | } |
---|
| 648 | /*** |
---|
[6e8997e] | 649 | f std::vector<DataTerm> get_linked_data_terms(bool &) |
---|
[ed3dc05] | 650 | returns the data terms bound to this oset's linking role. |
---|
[669b481] | 651 | (C:abac_oset_get_linked_data_terms) |
---|
[2e9455f] | 652 | (C::abac_terms_free) |
---|
[ed3dc05] | 653 | ***/ |
---|
[d037f54] | 654 | std::vector<DataTerm> get_linked_data_terms(bool &success) { |
---|
[ed3dc05] | 655 | abac_term_t **terms, **end; |
---|
| 656 | int i; |
---|
[669b481] | 657 | terms = abac_oset_get_linked_data_terms(m_oset); |
---|
[ed3dc05] | 658 | for (i = 0; terms[i] != NULL; ++i) |
---|
| 659 | ; |
---|
| 660 | end = &terms[i]; |
---|
| 661 | std::vector<DataTerm> dataterms = std::vector<DataTerm>(terms, end); |
---|
| 662 | abac_terms_free(terms); |
---|
| 663 | success=1; |
---|
| 664 | return dataterms; |
---|
| 665 | } |
---|
[5d06689] | 666 | /*ii** |
---|
[6e8997e] | 667 | f abac_aspect_t *oset() |
---|
[5d06689] | 668 | internal returns the internal libabac representation of the oset |
---|
[2e9455f] | 669 | (S:abac_aspect_t) |
---|
[5d06689] | 670 | **ii*/ |
---|
[8bd77b5] | 671 | abac_aspect_t *oset() {return m_oset;} |
---|
[9dffbd6] | 672 | private: |
---|
[8bd77b5] | 673 | abac_aspect_t *m_oset; |
---|
[9dffbd6] | 674 | }; |
---|
| 675 | |
---|
[8bd77b5] | 676 | |
---|
[1621520] | 677 | /*** |
---|
| 678 | ABAC::ID |
---|
| 679 | An ID holds a principal credential. It maybe imported from an existing |
---|
| 680 | ID credential via external files, constructed from a streaming chunk, |
---|
| 681 | or instantiated on the fly |
---|
| 682 | ***/ |
---|
[8bd77b5] | 683 | class ID { |
---|
[64fa9ba] | 684 | public: |
---|
[1621520] | 685 | /*** |
---|
[6e8997e] | 686 | f ID() |
---|
[1621520] | 687 | default constructor, do not use, for swig only |
---|
[6e8997e] | 688 | f ID(const ID &) |
---|
[1621520] | 689 | copy constructor, used for cloning an ID |
---|
[2e9455f] | 690 | (C:abac_id_dup) |
---|
[6e8997e] | 691 | f ~ID() |
---|
[1621520] | 692 | default destructor |
---|
[2e9455f] | 693 | (C:abac_id_free) |
---|
[1621520] | 694 | ***/ |
---|
[8bd77b5] | 695 | ID() : m_id(NULL) { } // do not use: here for swig |
---|
| 696 | ID(const ID &id) { m_id =abac_id_dup(id.m_id); } |
---|
| 697 | ~ID() { if(m_id) abac_id_free(m_id); } |
---|
[5d06689] | 698 | /*ii** |
---|
[6e8997e] | 699 | f ID(abac_id_t *) |
---|
[1621520] | 700 | constructor from abac_id_t |
---|
[2e9455f] | 701 | (C:abac_id_dup) |
---|
[6e8997e] | 702 | f ID(abac_id_credential_t *) |
---|
[09496b3] | 703 | constructor from abac_id_credential_t |
---|
[2e9455f] | 704 | (C:abac_id_credential_id) |
---|
| 705 | (S::abac_id_credential_t) |
---|
[5d06689] | 706 | **ii*/ |
---|
[1621520] | 707 | ID(abac_id_t *id): m_id(abac_id_dup(id)) |
---|
| 708 | { } |
---|
| 709 | ID(abac_id_credential_t *idcred) { |
---|
| 710 | if(idcred) |
---|
| 711 | m_id=abac_id_dup(abac_id_credential_id(idcred)); |
---|
| 712 | else m_id=NULL; |
---|
| 713 | } |
---|
| 714 | /*** |
---|
[6e8997e] | 715 | f ID(char *) |
---|
[1621520] | 716 | load an ID cert from a file, will throw an exception |
---|
| 717 | if the cert cannot be loaded |
---|
[669b481] | 718 | (C:abac_id_from_file) |
---|
[1621520] | 719 | ***/ |
---|
[8bd77b5] | 720 | ID(char *filename) { |
---|
[09496b3] | 721 | if(debug) printf("calling ID with a filename\n"); |
---|
[1621520] | 722 | m_id=abac_id_from_file(filename); |
---|
[b8a6fd2a] | 723 | if(m_id==NULL) { |
---|
| 724 | printf("trying.. %s\n",filename); |
---|
[1621520] | 725 | abac_errx(1, "Id creation from filename failed"); |
---|
[b8a6fd2a] | 726 | } |
---|
[1621520] | 727 | } |
---|
| 728 | /*** |
---|
[dfe6b61] | 729 | f ID_chunk(abac_chunk_t chunk) |
---|
[09496b3] | 730 | create an ID cert from an cert chunk, will |
---|
| 731 | throw an exception if the cert cannot be loaded |
---|
| 732 | (C:abac_id_from_chunk) |
---|
| 733 | ***/ |
---|
[dfe6b61] | 734 | ID(abac_chunk_t chunk) { |
---|
| 735 | /* had to renamed to ID_chunk(chunk) to make it to work with swig */ |
---|
[09496b3] | 736 | if(debug) printf("calling ID with chunk\n"); |
---|
[dfe6b61] | 737 | m_id=abac_id_from_chunk(chunk); |
---|
[09496b3] | 738 | if(m_id==NULL) |
---|
| 739 | abac_errx(1, "Id creation from chunk failed"); |
---|
| 740 | } |
---|
| 741 | /*** |
---|
[6e8997e] | 742 | f ID(char *,int) |
---|
[ba6027a] | 743 | generates a new ID(cert&key) with the supplied CN and validity period |
---|
[1621520] | 744 | - CN must be alphanumeric and begin with a letter |
---|
| 745 | - validity must be at least one second |
---|
| 746 | will throw an exception if either of the above is violated |
---|
[669b481] | 747 | (C:abac_id_generate) |
---|
[1621520] | 748 | ***/ |
---|
[8bd77b5] | 749 | ID(char *cn, int validity) { |
---|
[1621520] | 750 | int rt=abac_id_generate(&m_id, cn, validity); |
---|
| 751 | if(rt != ABAC_ID_SUCCESS) |
---|
[09496b3] | 752 | abac_errx(1, "Id generation failed"); |
---|
[1621520] | 753 | } |
---|
| 754 | /*** |
---|
[ba6027a] | 755 | f ID(char *,int, char*, char*) |
---|
| 756 | generates a new ID from a supplied CN, keyfile, passphrase(optional) file |
---|
| 757 | and validity period |
---|
| 758 | - CN must be alphanumeric and begin with a letter |
---|
| 759 | - validity must be at least one second |
---|
[2e9455f] | 760 | - optional passphrase is when the keyfile is encrypted |
---|
[ba6027a] | 761 | will throw an exception if either of the above is violated |
---|
| 762 | (C:abac_id_generate_with_key) |
---|
| 763 | ***/ |
---|
| 764 | ID(char *cn, int validity, char *kfile, char* pfile) { |
---|
| 765 | |
---|
| 766 | int rt=abac_id_generate_with_key(&m_id, cn, validity, kfile, pfile); |
---|
| 767 | if(rt != ABAC_ID_SUCCESS) |
---|
| 768 | abac_errx(1, "Id (with key) creation failed"); |
---|
| 769 | } |
---|
| 770 | /*** |
---|
[5d06689] | 771 | f void id_load_privkey_file(char *) |
---|
[ba6027a] | 772 | loads the private key associated with the ID credential, |
---|
[1621520] | 773 | will throw an exception if the key cannot be loaded |
---|
[669b481] | 774 | (C:abac_id_load_privkey_file) |
---|
[1621520] | 775 | ***/ |
---|
[5d06689] | 776 | void id_load_privkey_file(char *filename) { |
---|
[adc0815] | 777 | int rt=abac_id_load_privkey_file(m_id, filename); |
---|
| 778 | if(rt != 1) |
---|
| 779 | abac_errx(1, "Failed to load private key"); |
---|
| 780 | } |
---|
[ba6027a] | 781 | /*** |
---|
| 782 | f void id_load_encrypted_privkey_file(char *, char*) |
---|
| 783 | loads an encrypted private key and pfile associated with the |
---|
| 784 | ID credential, will throw an exception if the key cannot be loaded |
---|
| 785 | (C:abac_id_load_enc_privkey_file) |
---|
| 786 | ***/ |
---|
| 787 | void id_load_encrypted_privkey_file(char *filename, char* pfile) { |
---|
[2e9455f] | 788 | int rt=abac_id_load_enc_privkey_file(m_id, filename, pfile); |
---|
[ba6027a] | 789 | if(rt != 1) |
---|
| 790 | abac_errx(1, "Failed to load private key"); |
---|
| 791 | } |
---|
[1621520] | 792 | /*** |
---|
[5d06689] | 793 | f char *id_keyid() |
---|
[1621520] | 794 | returns the SHA1 keyid of the id cert |
---|
[669b481] | 795 | (C:abac_id_keyid) |
---|
[5d06689] | 796 | f char *id_name() |
---|
[adc0815] | 797 | returns the CN (the parameter passed to the constructor or the |
---|
| 798 | CN of the cert). |
---|
[669b481] | 799 | (C:abac_id_cn) |
---|
[1621520] | 800 | ***/ |
---|
[5d06689] | 801 | char *id_keyid() { return abac_id_keyid(m_id); } |
---|
| 802 | char *id_name() { return abac_id_cn(m_id); } |
---|
[1621520] | 803 | /*** |
---|
[5d06689] | 804 | f bool id_has_privkey() |
---|
[1621520] | 805 | returns true if the ID has an associated private key |
---|
[669b481] | 806 | (C:abac_id_has_privkey) |
---|
[1621520] | 807 | ***/ |
---|
[5d06689] | 808 | bool id_has_privkey() |
---|
[1621520] | 809 | { return abac_id_has_privkey(m_id); } |
---|
| 810 | |
---|
| 811 | /*** |
---|
[5d06689] | 812 | f void id_write_cert(FILE *) |
---|
[1621520] | 813 | writes a PEM-encoded cert to the file handle |
---|
[669b481] | 814 | (C:abac_id_write_cert) |
---|
[5d06689] | 815 | f void id_write_cert(char *) |
---|
[1621520] | 816 | writes a PEM-encoded cert to a file named out |
---|
[669b481] | 817 | (C:abac_id_write_cert_fname) |
---|
[1621520] | 818 | ***/ |
---|
[5d06689] | 819 | void id_write_cert(FILE *out) |
---|
[1621520] | 820 | { abac_id_write_cert(m_id, out); } |
---|
[669b481] | 821 | void id_write_cert(char *filename) |
---|
| 822 | { abac_id_write_cert_fname(m_id, filename); } |
---|
[1621520] | 823 | /*** |
---|
[5d06689] | 824 | f void id_write_privkey(FILE *) |
---|
[1621520] | 825 | writes a PEM-encoded private key to the file handle |
---|
| 826 | throws an exception if no private key is loaded |
---|
[669b481] | 827 | (C:abac_id_write_privkey) |
---|
[5d06689] | 828 | f void id_write_privkey(char *) |
---|
[1621520] | 829 | writes a PEM-encoded private key a file named out |
---|
| 830 | throws an exception if no private key is loaded |
---|
[669b481] | 831 | (C:abac_id_write_privkey_fname) |
---|
[1621520] | 832 | ***/ |
---|
[5d06689] | 833 | void id_write_privkey(FILE *out) { |
---|
| 834 | if(!id_has_privkey()) |
---|
[1621520] | 835 | abac_errx(1, "No privkey to write"); |
---|
| 836 | abac_id_write_privkey(m_id, out); |
---|
| 837 | } |
---|
[669b481] | 838 | void id_write_privkey(char *filename) |
---|
| 839 | { abac_id_write_privkey_fname(m_id, filename); } |
---|
[1621520] | 840 | /*** |
---|
[5d06689] | 841 | f abac_chunk_t id_cert_chunk() |
---|
[1621520] | 842 | returns a DER-encoded binary representation of the X.509 ID cert |
---|
| 843 | associated with this ID. |
---|
| 844 | can be passed to libabac's Context::load_id_chunk() |
---|
[669b481] | 845 | (C:abac_id_cert_chunk) |
---|
[9b43fc3] | 846 | f abac_chunk_t id_privkey_chunk() |
---|
| 847 | returns a PEM-encoded binary representation of the private key |
---|
| 848 | associated with this ID. |
---|
| 849 | can be passed to libabac's Context::load_id_chunks() |
---|
| 850 | (C:abac_id_privkey_chunk) |
---|
[1621520] | 851 | ***/ |
---|
[5d06689] | 852 | abac_chunk_t id_cert_chunk() |
---|
[dfe6b61] | 853 | { |
---|
| 854 | return abac_id_cert_chunk(m_id); |
---|
| 855 | } |
---|
[9b43fc3] | 856 | abac_chunk_t id_privkey_chunk() |
---|
| 857 | { return abac_id_privkey_chunk(m_id); } |
---|
[1621520] | 858 | /*** |
---|
[6e8997e] | 859 | f char *string() |
---|
[1621520] | 860 | returns literal string of the id credential |
---|
[669b481] | 861 | (C:abac_id_string) |
---|
[1621520] | 862 | ***/ |
---|
[5d06689] | 863 | char *string() |
---|
| 864 | { return abac_id_string(m_id); } |
---|
[2e9455f] | 865 | /*ii** |
---|
| 866 | f abac_id_t *id() |
---|
| 867 | returns the interal libabac representation of this id |
---|
| 868 | (S:abac_id_t) |
---|
| 869 | **ii*/ |
---|
| 870 | abac_id_t *id() { return m_id; } |
---|
| 871 | private: |
---|
[8bd77b5] | 872 | abac_id_t *m_id; |
---|
| 873 | }; |
---|
[64fa9ba] | 874 | |
---|
[8bd77b5] | 875 | |
---|
[1621520] | 876 | /*** |
---|
| 877 | ABAC::Attribute |
---|
| 878 | This is the attribute representation for the access policy rule |
---|
[6e8997e] | 879 | LHS <- RHS |
---|
[1621520] | 880 | The sequence of generation is to |
---|
[6e8997e] | 881 | first, instantiate the object, ie, LHS (head) |
---|
| 882 | second, adding subject(s) to it, ie, RHS (tail) |
---|
| 883 | and then baking it. |
---|
[1621520] | 884 | Only once it's baked can you access the X.509 cert. |
---|
| 885 | Once it's been baked you can no longer add subjects to it |
---|
| 886 | ***/ |
---|
[8bd77b5] | 887 | class Attribute { |
---|
| 888 | public: |
---|
[1621520] | 889 | /*** |
---|
[6e8997e] | 890 | f Attribute() |
---|
[1621520] | 891 | default constructor, do not use, for swig only |
---|
[6e8997e] | 892 | f Attribute(const Attribute &) |
---|
[1621520] | 893 | copy constructor, used for cloning an attribute |
---|
[2e9455f] | 894 | (C:abac_attribute_dup) |
---|
[6e8997e] | 895 | f ~Attribute() |
---|
[1621520] | 896 | default destructor |
---|
[2e9455f] | 897 | (C:abac_attribute_free) |
---|
[1621520] | 898 | ***/ |
---|
| 899 | Attribute() : m_attr(NULL) { } |
---|
| 900 | Attribute(const Attribute &id) |
---|
| 901 | { m_attr =abac_attribute_dup(id.m_attr); } |
---|
| 902 | ~Attribute() |
---|
| 903 | { if(m_attr) abac_attribute_free(m_attr); } |
---|
[5d06689] | 904 | /*ii** |
---|
[6e8997e] | 905 | f Attribute(abac_attribute_t *) |
---|
[adc0815] | 906 | constructor that takes abac_attribute_t, locally used |
---|
[2e9455f] | 907 | (C:abac_attribute_dup) |
---|
[6e8997e] | 908 | f Attribute(abac_credential_t *) |
---|
[adc0815] | 909 | constructor that takes abac_credential_t, locally used |
---|
[2e9455f] | 910 | (C:abac_attribute_dup) |
---|
| 911 | (C::abac_credential_attribute) |
---|
| 912 | (S::abac_credential_t) |
---|
[5d06689] | 913 | **ii*/ |
---|
[8bd77b5] | 914 | Attribute(abac_attribute_t *attr): m_attr(abac_attribute_dup(attr)) |
---|
[adc0815] | 915 | { } |
---|
| 916 | Attribute(abac_credential_t *cred) |
---|
| 917 | { m_attr=abac_attribute_dup(abac_credential_attribute(cred)); } |
---|
| 918 | /*** |
---|
[6e8997e] | 919 | f Attribute(Role&, int) |
---|
[adc0815] | 920 | constructor that creates an attribute policy to be signed by the issuer |
---|
| 921 | with the given role with a specified validity period |
---|
| 922 | An exception will be thrown if: |
---|
| 923 | - the issuer has no private key |
---|
| 924 | - the Head role is invalid |
---|
| 925 | - the validity period is invalid (must be >= 1 second) |
---|
[669b481] | 926 | (C:abac_attribute_create) |
---|
[adc0815] | 927 | ***/ |
---|
[8bd77b5] | 928 | Attribute(Role& head, int validity) { |
---|
[adc0815] | 929 | int rt=abac_attribute_create(&m_attr, head.role(), NULL, validity); |
---|
| 930 | if(rt!=ABAC_ATTRIBUTE_SUCCESS) |
---|
| 931 | abac_errx(1, "attribute(role), unable to make an attribute"); |
---|
| 932 | } |
---|
| 933 | /*** |
---|
[6e8997e] | 934 | f Attribute(Oset&, int) |
---|
[adc0815] | 935 | constructor that creates an attribute policy to be signed by the issuer |
---|
| 936 | with the given oset with a specified validity period |
---|
| 937 | An exception will be thrown if: |
---|
| 938 | - the issuer has no private key |
---|
| 939 | - the Head oset is invalid |
---|
| 940 | - the validity period is invalid (must be >= 1 second) |
---|
[669b481] | 941 | (C:abac_attribute_create) |
---|
[adc0815] | 942 | ***/ |
---|
[8bd77b5] | 943 | Attribute(Oset& head, int validity) { |
---|
[adc0815] | 944 | int rt=abac_attribute_create(&m_attr, head.oset(), NULL, validity); |
---|
| 945 | if(rt!=ABAC_ATTRIBUTE_SUCCESS) |
---|
| 946 | abac_errx(1, "attribute(oset), unable to make an attribute"); |
---|
| 947 | } |
---|
| 948 | /*** |
---|
[dfe6b61] | 949 | f Attribute_chunk(abac_chunk_t chunk) |
---|
| 950 | constructor that creates an attribute policy to be signed by the issuer |
---|
| 951 | with a given cert chunk. |
---|
| 952 | (C:abac_attribute_from_chunk) |
---|
| 953 | ***/ |
---|
| 954 | Attribute(abac_chunk_t chunk) { |
---|
| 955 | /* had to renamed to Attribute_chunk(chunk) to make it to work with swig */ |
---|
| 956 | m_attr=abac_attribute_from_chunk(chunk); |
---|
| 957 | if(m_attr==NULL) |
---|
| 958 | abac_errx(1, "attribute(chunk), unable to make an attribute"); |
---|
| 959 | } |
---|
| 960 | /*** |
---|
[5d06689] | 961 | f bool attribute_add_tail(Role&) |
---|
[669b481] | 962 | Add a role tail. Call multiple times for intersection |
---|
| 963 | (C:abac_attribute_add_tail) |
---|
[5d06689] | 964 | f bool attribute_add_tail(Oset&) |
---|
[669b481] | 965 | Add an oset tail. Call multiple times for intersection |
---|
| 966 | (C:abac_attribute_add_tail) |
---|
[2e9455f] | 967 | f void attribute_set_using_this() |
---|
| 968 | Allow user set whether this attribute has '?This' in its |
---|
| 969 | attribute rule |
---|
| 970 | (C:abac_attribute_set_using_this) |
---|
[adc0815] | 971 | ***/ |
---|
[5d06689] | 972 | bool attribute_add_tail(Role& tail) { |
---|
[adc0815] | 973 | if(abac_attribute_add_tail(m_attr, tail.role())) |
---|
| 974 | return 1; |
---|
| 975 | else return 0; |
---|
| 976 | } |
---|
[5d06689] | 977 | bool attribute_add_tail(Oset& tail) { |
---|
[adc0815] | 978 | if(abac_attribute_add_tail(m_attr, tail.oset())) |
---|
| 979 | return 1; |
---|
| 980 | else return 0; |
---|
| 981 | } |
---|
[2e9455f] | 982 | void attribute_set_using_this() { |
---|
| 983 | abac_attribute_set_using_this(m_attr,1); |
---|
| 984 | } |
---|
| 985 | /*** |
---|
[adc0815] | 986 | /*** |
---|
[6e8997e] | 987 | f char *head_string() |
---|
[adc0815] | 988 | returns literal string of head of the attribute |
---|
[669b481] | 989 | (C:abac_head_string) |
---|
[6e8997e] | 990 | f char *tail_string() |
---|
[adc0815] | 991 | returns literal string of tail of the attribute |
---|
[669b481] | 992 | (C:abac_tail_string) |
---|
[adc0815] | 993 | ***/ |
---|
[5d06689] | 994 | char *head_string() |
---|
| 995 | { return abac_head_string(m_attr); } |
---|
| 996 | char *tail_string() |
---|
| 997 | { return abac_tail_string(m_attr); } |
---|
[adc0815] | 998 | /*** |
---|
[6e8997e] | 999 | f char *head_typed_string() |
---|
[adc0815] | 1000 | returns typed literal string of head of the attribute |
---|
[669b481] | 1001 | (C:abac_head_typed_string) |
---|
[6e8997e] | 1002 | f char *tail_typed_string() |
---|
[adc0815] | 1003 | returns typed literal string of tail of the attribute |
---|
[669b481] | 1004 | (C:abac_tail_typed_string) |
---|
[adc0815] | 1005 | ***/ |
---|
[5d06689] | 1006 | char *head_typed_string() |
---|
| 1007 | { return abac_head_typed_string(m_attr); } |
---|
| 1008 | char *tail_typed_string() |
---|
| 1009 | { return abac_tail_typed_string(m_attr); } |
---|
[adc0815] | 1010 | /*** |
---|
[6e8997e] | 1011 | f char *string() |
---|
[adc0815] | 1012 | returns literal string of the attribute |
---|
[669b481] | 1013 | (C:abac_attribute_string) |
---|
[6e8997e] | 1014 | f char *typed_string() |
---|
[adc0815] | 1015 | returns typed literal string of the attribute |
---|
[669b481] | 1016 | (C:abac_attribute_typed_string) |
---|
[adc0815] | 1017 | ***/ |
---|
[5d06689] | 1018 | char *string() |
---|
| 1019 | { return abac_attribute_string(m_attr); } |
---|
| 1020 | char *typed_string() |
---|
| 1021 | { return abac_attribute_typed_string(m_attr); } |
---|
| 1022 | |
---|
[adc0815] | 1023 | /*** ??? not sure about implmentation |
---|
[6e8997e] | 1024 | f const Role &role_head() |
---|
[adc0815] | 1025 | returns the head role |
---|
[2e9455f] | 1026 | (C:abac_attribute_head) |
---|
[6e8997e] | 1027 | f const Oset &oset_head() |
---|
[adc0815] | 1028 | returns the oset head |
---|
[2e9455f] | 1029 | (C:abac_attribute_head) |
---|
[adc0815] | 1030 | ***/ |
---|
[8bd77b5] | 1031 | const Role &role_head() { |
---|
[adc0815] | 1032 | abac_aspect_t *head=abac_attribute_head(m_attr); |
---|
| 1033 | static Role role=Role(head); |
---|
| 1034 | return role; |
---|
| 1035 | } |
---|
[8bd77b5] | 1036 | const Oset &oset_head() { |
---|
[2e9455f] | 1037 | abac_aspect_t *head=abac_attribute_head(m_attr); |
---|
[adc0815] | 1038 | static Oset oset=Oset(head); |
---|
| 1039 | return oset; |
---|
| 1040 | } |
---|
[5d06689] | 1041 | /*** |
---|
[6e8997e] | 1042 | f std::vector<Role> role_tails(bool &) |
---|
[adc0815] | 1043 | retrieve tail role which maybe more than 1 if intersecting |
---|
[669b481] | 1044 | (C:abac_attribute_role_tails) |
---|
[2e9455f] | 1045 | (C::abac_attribute_is_role) |
---|
| 1046 | (C::abac_aspects_free) |
---|
[6e8997e] | 1047 | f std::vector<Oset> oset_tails(bool &) |
---|
[adc0815] | 1048 | retrieve tail oset which maybe more than 1 if intersecting |
---|
[669b481] | 1049 | (C:abac_attribute_oset_tails) |
---|
[2e9455f] | 1050 | (C::abac_attribute_is_role) |
---|
| 1051 | (C::abac_aspects_free) |
---|
[adc0815] | 1052 | ***/ |
---|
[d037f54] | 1053 | std::vector<Role> role_tails(bool &success) { |
---|
[adc0815] | 1054 | abac_aspect_t **tails, **end; |
---|
| 1055 | int i; |
---|
| 1056 | /* make sure it is role */ |
---|
| 1057 | if(!abac_attribute_is_role(m_attr)) { |
---|
| 1058 | success=0; |
---|
| 1059 | abac_errx(1, "role_tails, attribute is not a role"); |
---|
[8bd77b5] | 1060 | } |
---|
[669b481] | 1061 | tails = abac_attribute_role_tails(m_attr); |
---|
[adc0815] | 1062 | for (i = 0; tails[i] != NULL; ++i) |
---|
| 1063 | ; |
---|
| 1064 | end = &tails[i]; |
---|
| 1065 | std::vector<Role> roles = std::vector<Role>(tails, end); |
---|
| 1066 | abac_aspects_free(tails); |
---|
| 1067 | success=1; |
---|
| 1068 | return roles; |
---|
| 1069 | } |
---|
[d037f54] | 1070 | std::vector<Oset> oset_tails(bool &success) { |
---|
[adc0815] | 1071 | abac_aspect_t **tails, **end; |
---|
| 1072 | int i; |
---|
| 1073 | /* make sure that tail is not role */ |
---|
| 1074 | if(abac_attribute_is_role(m_attr)) { |
---|
| 1075 | success=0; |
---|
| 1076 | abac_errx(1, "oset_tails, attribute is not an oset"); |
---|
[8bd77b5] | 1077 | } |
---|
[669b481] | 1078 | tails = abac_attribute_oset_tails(m_attr); |
---|
[adc0815] | 1079 | for (i = 0; tails[i] != NULL; ++i) |
---|
| 1080 | ; |
---|
| 1081 | end = &tails[i]; |
---|
| 1082 | std::vector<Oset> osets = std::vector<Oset>(tails, end); |
---|
| 1083 | success=1; |
---|
| 1084 | abac_aspects_free(tails); |
---|
| 1085 | return osets; |
---|
| 1086 | } |
---|
| 1087 | /*** |
---|
[5d06689] | 1088 | f bool attribute_bake() |
---|
[adc0815] | 1089 | Generate the cert. Call this after you've added subjects to your cert. |
---|
| 1090 | This returns false if there are no subjects |
---|
| 1091 | This will throw an exception if the cert's already been baked. |
---|
[669b481] | 1092 | (C:abac_attribute_bake) |
---|
[adc0815] | 1093 | ***/ |
---|
[5d06689] | 1094 | bool attribute_bake() { |
---|
[adc0815] | 1095 | /* can not bake in ABAC_CN mode */ |
---|
| 1096 | if(USE("ABAC_CN")) |
---|
| 1097 | abac_errx(1, "bake, can not bake the cert with env(ABAC_CN) set"); |
---|
| 1098 | int rt=abac_attribute_bake(m_attr); |
---|
| 1099 | if(rt!=1) |
---|
| 1100 | abac_errx(1, "bake, can not bake the cert"); |
---|
| 1101 | } |
---|
| 1102 | /*** |
---|
[5d06689] | 1103 | f bool attribute_baked() |
---|
[adc0815] | 1104 | returns true iff the cert has been baked. |
---|
[669b481] | 1105 | (C:abac_attribute_baked) |
---|
[adc0815] | 1106 | ***/ |
---|
[5d06689] | 1107 | bool attribute_baked() |
---|
[adc0815] | 1108 | { return abac_attribute_baked(m_attr); } |
---|
| 1109 | |
---|
| 1110 | /*** |
---|
[5d06689] | 1111 | f void attribute_write_cert(FILE *) |
---|
[adc0815] | 1112 | write the DER-encoded X.509 attribute cert to the open file handle |
---|
| 1113 | Throws an exception if the cert isn't baked |
---|
[669b481] | 1114 | (C:abac_attribute_write_cert) |
---|
[adc0815] | 1115 | ***/ |
---|
[5d06689] | 1116 | void attribute_write_cert(FILE *out) { |
---|
| 1117 | int rt= abac_attribute_write_cert(m_attr,out); |
---|
[adc0815] | 1118 | if(!rt) |
---|
| 1119 | abac_errx(1, "write, cert is not baked"); |
---|
| 1120 | } |
---|
| 1121 | /*** |
---|
[5d06689] | 1122 | f void attribute_write_cert(char *) |
---|
[adc0815] | 1123 | write the DER-encoded X.509 attribute cert to a file named out |
---|
| 1124 | Throws an exception if the cert isn't baked |
---|
[669b481] | 1125 | (C:abac_attribute_write_cert_fname) |
---|
[adc0815] | 1126 | ***/ |
---|
[669b481] | 1127 | void attribute_write_cert(char *filename) |
---|
| 1128 | { abac_attribute_write_cert_fname(m_attr,filename); } |
---|
[adc0815] | 1129 | /*** |
---|
[6e8997e] | 1130 | f abac_chunk_t cert_chunk() |
---|
[adc0815] | 1131 | returns a DER-encoded binary representation of the X.509 attribute |
---|
| 1132 | cert associated with this cert |
---|
| 1133 | Throws an exception if the cert isn't baked |
---|
| 1134 | the chunk can be passed to libabac's Context::load_attribute_chunk() |
---|
[669b481] | 1135 | (C:abac_attribute_cert_chunk) |
---|
[adc0815] | 1136 | ***/ |
---|
| 1137 | abac_chunk_t cert_chunk() |
---|
| 1138 | { return abac_attribute_cert_chunk(m_attr); } |
---|
[2e9455f] | 1139 | /*ii** |
---|
| 1140 | f abac_attribute_t *attribute() |
---|
| 1141 | return libabac structure for attribute |
---|
| 1142 | (S:abac_attribute_t) |
---|
| 1143 | **ii*/ |
---|
| 1144 | abac_attribute_t *attribute() { return m_attr; } |
---|
[8bd77b5] | 1145 | private: |
---|
| 1146 | abac_attribute_t *m_attr; |
---|
| 1147 | }; |
---|
[9dffbd6] | 1148 | |
---|
[8bd77b5] | 1149 | |
---|
[adc0815] | 1150 | /*** |
---|
| 1151 | ABAC::Context |
---|
[6e8997e] | 1152 | An ABAC Context |
---|
[adc0815] | 1153 | ***/ |
---|
[8bd77b5] | 1154 | class Context { |
---|
| 1155 | public: |
---|
[adc0815] | 1156 | /*** |
---|
[6e8997e] | 1157 | f Context() |
---|
[adc0815] | 1158 | default constructor |
---|
[2e9455f] | 1159 | (C:abac_context_new) |
---|
[6e8997e] | 1160 | f Context(const Context &) |
---|
[adc0815] | 1161 | copy constructor, used for cloning the context |
---|
[2e9455f] | 1162 | (C:abac_context_dup) |
---|
[6e8997e] | 1163 | f ~Context() |
---|
[adc0815] | 1164 | default destructor |
---|
[2e9455f] | 1165 | (C:abac_context_free) |
---|
[adc0815] | 1166 | ***/ |
---|
[2efdff5] | 1167 | Context() { |
---|
| 1168 | m_ctx = abac_context_new(); |
---|
[2e9455f] | 1169 | m_abac_version=abac_xstrdup(abac_version()); |
---|
[2efdff5] | 1170 | } |
---|
[8bd77b5] | 1171 | Context(const Context &context) { |
---|
[adc0815] | 1172 | m_ctx = abac_context_dup(context.m_ctx); |
---|
[2e9455f] | 1173 | m_abac_version=abac_xstrdup(context.m_abac_version); |
---|
[adc0815] | 1174 | } |
---|
[8bd77b5] | 1175 | ~Context() { |
---|
[e3c7769] | 1176 | if(m_abac_version!=NULL) free(m_abac_version); |
---|
| 1177 | if(m_ctx!=NULL) abac_context_free(m_ctx); |
---|
[adc0815] | 1178 | } |
---|
| 1179 | /*** |
---|
[6e8997e] | 1180 | f int load_id(ABAC::ID&) |
---|
[adc0815] | 1181 | load id cert from ID |
---|
[669b481] | 1182 | (C:abac_context_load_id) |
---|
[6e8997e] | 1183 | f int load_id_file(char *) |
---|
[ba6027a] | 1184 | load id cert from an idkey combo file. key retrieval will be attempted |
---|
[adc0815] | 1185 | but won't fail if not found |
---|
[2e9455f] | 1186 | (C:abac_context_load_id_idkey_file) |
---|
[ba6027a] | 1187 | f int load_id_encrypted_file(char *, char *) |
---|
| 1188 | load id cert from an idkey combo file and a pfile. Encrypted key |
---|
| 1189 | retrieval will be attempted but won't fail if not found |
---|
| 1190 | (C:abac_context_load_encrypted_id_file) |
---|
[5d06689] | 1191 | f int load_id_files(char *, char *) |
---|
[adc0815] | 1192 | load id cert from an id file and a key file |
---|
[669b481] | 1193 | (C:abac_context_load_id_files) |
---|
[ba6027a] | 1194 | f int load_id_encrypted_files(char *, char *, char *) |
---|
| 1195 | load id cert from an id file, an encrypted key file, and a pfile |
---|
| 1196 | (C:abac_context_load_encrypted_id_files) |
---|
[6e8997e] | 1197 | f int load_id_chunk(abac_chunk_t) |
---|
[adc0815] | 1198 | load id cert from a chunk structure |
---|
[669b481] | 1199 | (C:abac_context_load_id_chunk) |
---|
[9b43fc3] | 1200 | f int load_id_chunks(abac_chunk_t, abac_chunk_t) |
---|
[ba6027a] | 1201 | load id & privkey from chunk structures |
---|
[9b43fc3] | 1202 | (C:abac_context_load_id_privkey_chunk) |
---|
[ba6027a] | 1203 | f int load_id_encrypted_chunks(abac_chunk_t, abac_chunk_t,char *pfile) |
---|
| 1204 | load id & encrypted privkey from chunk structures |
---|
| 1205 | (C:abac_context_load_id_enc_privkey_chunk) |
---|
[6e8997e] | 1206 | returns: |
---|
[adc0815] | 1207 | ABAC_CERT_SUCCESS successfully loaded |
---|
| 1208 | ABAC_CERT_INVALID invalid certificate (or file not found) |
---|
| 1209 | ABAC_CERT_BAD_SIG invalid signature |
---|
| 1210 | ***/ |
---|
| 1211 | int load_id(ABAC::ID& id) |
---|
[5d06689] | 1212 | { return abac_context_load_id(m_ctx, id.id()); } |
---|
[adc0815] | 1213 | int load_id_file(char *filename) |
---|
[2e9455f] | 1214 | { return abac_context_load_id_idkey_file(m_ctx, filename); } |
---|
[ba6027a] | 1215 | int load_id_encrypted_file(char *filename, char *pfile) |
---|
| 1216 | { return abac_context_load_encrypted_id_file(m_ctx, filename, pfile); } |
---|
[5d06689] | 1217 | int load_id_files(char *filename, char *keyfilename) |
---|
| 1218 | { return abac_context_load_id_files(m_ctx, filename, keyfilename); } |
---|
[ba6027a] | 1219 | int load_id_encrypted_files(char *filename, char *keyfilename, char *pfile) |
---|
| 1220 | { return abac_context_load_encrypted_id_files(m_ctx, filename, keyfilename, pfile); } |
---|
[adc0815] | 1221 | int load_id_chunk(abac_chunk_t cert) |
---|
| 1222 | { return abac_context_load_id_chunk(m_ctx, cert); } |
---|
[9b43fc3] | 1223 | int load_id_chunks(abac_chunk_t cert, abac_chunk_t privkey) |
---|
[8798f04] | 1224 | { if(debug) printf("load_id_chunks, FUNNY privkey ptr, loc(%p)\n", |
---|
| 1225 | privkey.ptr); |
---|
[ba6027a] | 1226 | return abac_context_load_id_privkey_chunk(m_ctx, cert, privkey); } |
---|
| 1227 | int load_id_encrypted_chunks(abac_chunk_t cert, abac_chunk_t privkey, char *pfile) |
---|
[8798f04] | 1228 | { if(debug) printf("load_id_encrypted_chunks, FUNNY privkey ptr, loc(%p)\n", |
---|
| 1229 | privkey.ptr); |
---|
[ba6027a] | 1230 | return abac_context_load_id_enc_privkey_chunk(m_ctx, cert, privkey, pfile); } |
---|
[adc0815] | 1231 | |
---|
| 1232 | /*** |
---|
[6e8997e] | 1233 | f int load_attribute(ABAC::Attribute&) |
---|
[adc0815] | 1234 | load attribute credential from attribute structure |
---|
[669b481] | 1235 | (C:abac_context_load_attribute) |
---|
[6e8997e] | 1236 | f int load_attribute_file(char *) |
---|
[adc0815] | 1237 | load attribute credential from a file |
---|
[669b481] | 1238 | (C:abac_context_load_attribute_file) |
---|
[6e8997e] | 1239 | f int load_attribute_chunk(abac_chunk_t) |
---|
[adc0815] | 1240 | load attribute credential from a chunk |
---|
[669b481] | 1241 | (C:abac_context_load_attribute_chunk) |
---|
[6e8997e] | 1242 | f returns the same values as above, additionally |
---|
| 1243 | returns ABAC_CERT_MISSING_ISSUER if the issuer |
---|
| 1244 | certificate has not been loaded |
---|
[adc0815] | 1245 | ***/ |
---|
| 1246 | int load_attribute(ABAC::Attribute& a) |
---|
[5d06689] | 1247 | { return abac_context_load_attribute(m_ctx, a.attribute()); } |
---|
[adc0815] | 1248 | int load_attribute_file(char *filename) |
---|
| 1249 | { return abac_context_load_attribute_file(m_ctx, filename); } |
---|
| 1250 | int load_attribute_chunk(abac_chunk_t cert) |
---|
| 1251 | { return abac_context_load_attribute_chunk(m_ctx, cert); } |
---|
| 1252 | /*** |
---|
[2efdff5] | 1253 | f void load_principals(char *) |
---|
| 1254 | load a directory full of principals only: |
---|
| 1255 | f first: ${path}/*_ID.{der,pem} as identity certificates |
---|
| 1256 | implicitly looking for ${path}/*_private.{der,pem} as |
---|
| 1257 | the private key file |
---|
| 1258 | then: ${path}/*_IDKEY.{der,pem} as id/key combo certificate |
---|
| 1259 | (C:abac_context_load_principals) |
---|
[6e8997e] | 1260 | f void load_directory(char *) |
---|
[adc0815] | 1261 | load a directory full of certificates: |
---|
[6e8997e] | 1262 | f first: ${path}/*_ID.{der,pem} as identity certificates |
---|
[adc0815] | 1263 | implicitly looking for ${path}/*_private.{der,pem} as |
---|
| 1264 | the private key file |
---|
| 1265 | then: ${path}/*_IDKEY.{der,pem} as id/key combo certificate |
---|
| 1266 | last: ${path}/*_attr.der as attribute certificates |
---|
[669b481] | 1267 | (C:abac_context_load_directory) |
---|
[adc0815] | 1268 | ***/ |
---|
[2efdff5] | 1269 | void load_principals(char *path) |
---|
| 1270 | { abac_context_load_principals(m_ctx, path); } |
---|
[adc0815] | 1271 | void load_directory(char *path) |
---|
| 1272 | { abac_context_load_directory(m_ctx, path); } |
---|
| 1273 | /*** |
---|
[646e57e] | 1274 | f void set_no_partial_proof() |
---|
| 1275 | (C:abac_context_set_no_partial_proof) |
---|
| 1276 | void set_want_partial_proof() |
---|
| 1277 | enable and disable the partial proof on query proof failure |
---|
| 1278 | (C:abac_context_set_want_partial_proof) |
---|
| 1279 | ***/ |
---|
| 1280 | void set_no_partial_proof() |
---|
| 1281 | { abac_context_set_no_partial_proof(m_ctx); } |
---|
| 1282 | void set_want_partial_proof() |
---|
| 1283 | { abac_context_set_want_partial_proof(m_ctx); } |
---|
| 1284 | /*** |
---|
[6e8997e] | 1285 | f std::vector<Attribute> query(char *, char *, bool &) |
---|
[adc0815] | 1286 | the string version is for query that is composed by hand with SHA or |
---|
| 1287 | in non ABAC_CN mode |
---|
[669b481] | 1288 | (C:abac_context_query) |
---|
[2e9455f] | 1289 | (C::abac_free_credentials) |
---|
[6e8997e] | 1290 | f std::vector<Attribute> query(Role &, Role &, bool &) |
---|
[669b481] | 1291 | (C:abac_context_query_with_structure) |
---|
[2e9455f] | 1292 | (C::abac_free_credentials) |
---|
[adc0815] | 1293 | std::vector<Attribute> query(Oset &, Oset &, bool &) |
---|
[669b481] | 1294 | (C:abac_context_query_with_structure) |
---|
[2e9455f] | 1295 | (C::abac_free_credentials) |
---|
[adc0815] | 1296 | runs the query: |
---|
[8bd77b5] | 1297 | role <-?- principal |
---|
[6e8997e] | 1298 | oset <-?- principal/obj |
---|
[adc0815] | 1299 | returns true/false in success |
---|
[6e8997e] | 1300 | returns a proof upon success, |
---|
[646e57e] | 1301 | a partial proof on failure by default |
---|
[adc0815] | 1302 | ***/ |
---|
[8bd77b5] | 1303 | std::vector<Attribute> query(char *role, char *principal, bool &success) { |
---|
[adc0815] | 1304 | abac_credential_t **creds, **end; |
---|
| 1305 | int i, success_int; |
---|
[8bd77b5] | 1306 | |
---|
[adc0815] | 1307 | creds = abac_context_query(m_ctx, role, principal, &success_int); |
---|
| 1308 | success = success_int; |
---|
[8bd77b5] | 1309 | |
---|
[2e9455f] | 1310 | if(debug) printf("query, returning success(%d)\n", success_int); |
---|
| 1311 | |
---|
[adc0815] | 1312 | for (i = 0; creds[i] != NULL; ++i) |
---|
| 1313 | ; |
---|
[9dffbd6] | 1314 | |
---|
[adc0815] | 1315 | end = &creds[i]; |
---|
| 1316 | std::vector<Attribute> attributes = std::vector<Attribute>(creds, end); |
---|
| 1317 | if(debug) printf("query, got rules(%d)\n", i); |
---|
[9dffbd6] | 1318 | |
---|
[2e9455f] | 1319 | abac_free_credentials(creds); |
---|
[9dffbd6] | 1320 | |
---|
[adc0815] | 1321 | return attributes; |
---|
| 1322 | } |
---|
[64fa9ba] | 1323 | |
---|
[5110d42] | 1324 | std::vector<Attribute> query(Role &role, Role &p_role, bool &success) { |
---|
[adc0815] | 1325 | abac_credential_t **creds, **end; |
---|
| 1326 | int i, success_int; |
---|
[5110d42] | 1327 | |
---|
[adc0815] | 1328 | creds = abac_context_query_with_structure(m_ctx, role.role(), p_role.role(), &success_int); |
---|
| 1329 | success = success_int; |
---|
[5110d42] | 1330 | |
---|
[2e9455f] | 1331 | if(debug) printf("query, returning success(%d)\n", success_int); |
---|
| 1332 | |
---|
[adc0815] | 1333 | for (i = 0; creds[i] != NULL; ++i) |
---|
| 1334 | ; |
---|
[5110d42] | 1335 | |
---|
[adc0815] | 1336 | end = &creds[i]; |
---|
| 1337 | std::vector<Attribute> attributes = std::vector<Attribute>(creds, end); |
---|
[5110d42] | 1338 | |
---|
[2e9455f] | 1339 | abac_free_credentials(creds); |
---|
[5110d42] | 1340 | |
---|
[adc0815] | 1341 | return attributes; |
---|
| 1342 | } |
---|
[5110d42] | 1343 | |
---|
| 1344 | std::vector<Attribute> query(Oset &oset, Oset &p_oset, bool &success) { |
---|
[adc0815] | 1345 | abac_credential_t **creds, **end; |
---|
| 1346 | int i, success_int; |
---|
| 1347 | |
---|
| 1348 | creds = abac_context_query_with_structure(m_ctx, oset.oset(), p_oset.oset(), &success_int); |
---|
| 1349 | success = success_int; |
---|
[5110d42] | 1350 | |
---|
[2e9455f] | 1351 | if(debug) printf("query, returning success(%d)\n", success_int); |
---|
| 1352 | |
---|
[adc0815] | 1353 | for (i = 0; creds[i] != NULL; ++i) |
---|
| 1354 | ; |
---|
[5110d42] | 1355 | |
---|
[adc0815] | 1356 | end = &creds[i]; |
---|
| 1357 | std::vector<Attribute> attributes = std::vector<Attribute>(creds, end); |
---|
| 1358 | if(debug) printf("query, returning rules(%d)\n", i); |
---|
[5110d42] | 1359 | |
---|
[2e9455f] | 1360 | abac_free_credentials(creds); |
---|
[5110d42] | 1361 | |
---|
[adc0815] | 1362 | return attributes; |
---|
| 1363 | } |
---|
[5110d42] | 1364 | |
---|
[abf8d5d] | 1365 | /*** |
---|
| 1366 | f std::vector<Attribute> next_proof(bool &) |
---|
| 1367 | (C:abac_context_query_again) |
---|
[2e9455f] | 1368 | (C::abac_free_credentials) |
---|
[abf8d5d] | 1369 | force backtrack and try to get next solution proof: |
---|
| 1370 | returns true/false in success |
---|
| 1371 | returns a proof upon success, |
---|
| 1372 | ***/ |
---|
| 1373 | std::vector<Attribute> next_proof(bool &success) { |
---|
| 1374 | abac_credential_t **creds, **end; |
---|
| 1375 | int i, success_int; |
---|
| 1376 | |
---|
| 1377 | creds = abac_context_query_again(m_ctx, &success_int); |
---|
| 1378 | success = success_int; |
---|
| 1379 | |
---|
| 1380 | for (i = 0; creds[i] != NULL; ++i) |
---|
| 1381 | ; |
---|
| 1382 | |
---|
| 1383 | end = &creds[i]; |
---|
| 1384 | std::vector<Attribute> attributes = std::vector<Attribute>(creds, end); |
---|
| 1385 | if(debug) printf("repeat query, got rules(%d)\n", i); |
---|
| 1386 | |
---|
[2e9455f] | 1387 | abac_free_credentials(creds); |
---|
[abf8d5d] | 1388 | |
---|
| 1389 | return attributes; |
---|
| 1390 | } |
---|
[adc0815] | 1391 | /*** |
---|
[6e8997e] | 1392 | f std::vector<Attribute> context_credentials(bool &) |
---|
[adc0815] | 1393 | returns a vector of all the credentials loaded in the context |
---|
| 1394 | extracted from the internal data structure |
---|
[669b481] | 1395 | (C:abac_context_credentials) |
---|
[2e9455f] | 1396 | (C::abac_free_credentials) |
---|
| 1397 | f int credential_count() |
---|
| 1398 | returns the number of credentials loaded in the context currently |
---|
| 1399 | (C:abac_context_credential_count() |
---|
[adc0815] | 1400 | ***/ |
---|
[8bd77b5] | 1401 | std::vector<Attribute> context_credentials(bool &success) { |
---|
[adc0815] | 1402 | abac_credential_t **creds, **end; |
---|
| 1403 | int i; |
---|
| 1404 | success = 1; |
---|
[3c4fd68] | 1405 | |
---|
[adc0815] | 1406 | creds = abac_context_credentials(m_ctx); |
---|
| 1407 | for (i = 0; creds[i] != NULL; ++i) |
---|
| 1408 | ; |
---|
[3c4fd68] | 1409 | |
---|
[adc0815] | 1410 | end = &creds[i]; |
---|
| 1411 | std::vector<Attribute> attributes = std::vector<Attribute>(creds, end); |
---|
| 1412 | if(debug) printf("credentials, got (%d)\n", i); |
---|
[3c4fd68] | 1413 | |
---|
[2e9455f] | 1414 | abac_free_credentials(creds); |
---|
[adc0815] | 1415 | if(debug) show_yap_db("calling from context_credentials"); |
---|
| 1416 | return attributes; |
---|
| 1417 | } |
---|
[5110d42] | 1418 | |
---|
[2e9455f] | 1419 | int credential_count() const |
---|
| 1420 | { return abac_context_credential_count(m_ctx); } |
---|
[adc0815] | 1421 | /*** |
---|
[6e8997e] | 1422 | f std::vector<Attribute> context_principals(bool &) |
---|
[adc0815] | 1423 | returns a vector of all the principals loaded in the context |
---|
| 1424 | extracted from the internal data structure |
---|
[669b481] | 1425 | (C:abac_context_principals) |
---|
[2e9455f] | 1426 | (C::abac_free_principals) |
---|
| 1427 | f int principal_count() |
---|
| 1428 | returns the number of principals loaded in the context currently |
---|
| 1429 | (C:abac_context_principal_count() |
---|
[adc0815] | 1430 | ***/ |
---|
[5110d42] | 1431 | std::vector<ID> context_principals(bool &success) { |
---|
[adc0815] | 1432 | abac_id_credential_t **ids, **end; |
---|
| 1433 | int i; |
---|
| 1434 | success = 1; |
---|
[5110d42] | 1435 | |
---|
[adc0815] | 1436 | ids = abac_context_principals(m_ctx); |
---|
| 1437 | for (i = 0; ids[i] != NULL; ++i) |
---|
| 1438 | ; |
---|
[5110d42] | 1439 | |
---|
[adc0815] | 1440 | end = &ids[i]; |
---|
| 1441 | std::vector<ID> principals = std::vector<ID>(ids, end); |
---|
| 1442 | if(debug) printf("principals, got (%d)\n", i); |
---|
[5110d42] | 1443 | |
---|
[2e9455f] | 1444 | abac_free_principals(ids); |
---|
[adc0815] | 1445 | return principals; |
---|
| 1446 | } |
---|
[2e9455f] | 1447 | int principal_count() const |
---|
| 1448 | { return abac_context_principal_count(m_ctx); } |
---|
[adc0815] | 1449 | /*** |
---|
[ba6027a] | 1450 | f ID lookup_principal(char *) |
---|
| 1451 | find a particular principal from the context |
---|
[2e9455f] | 1452 | (C:abac_context_principal_lookup) |
---|
[ba6027a] | 1453 | ***/ |
---|
| 1454 | ID lookup_principal(char *name) const |
---|
| 1455 | { |
---|
| 1456 | abac_id_credential_t *principal=abac_context_principal_lookup(m_ctx,name); |
---|
| 1457 | if(principal==NULL) { |
---|
| 1458 | if(debug) printf("did not find the principal(%s)\n", name); |
---|
| 1459 | abac_errx(1, "lookup principal failed"); |
---|
| 1460 | } |
---|
| 1461 | return principal; |
---|
| 1462 | } |
---|
| 1463 | /*** |
---|
[6e8997e] | 1464 | f char *version() |
---|
[adc0815] | 1465 | return the version of this interface |
---|
| 1466 | ***/ |
---|
[8bd77b5] | 1467 | char *version() const { return m_abac_version; } |
---|
[3c4fd68] | 1468 | |
---|
[2e9455f] | 1469 | /*ii** |
---|
| 1470 | f abac_context_t *context() |
---|
| 1471 | return libabac structure for context |
---|
| 1472 | (S:abac_context_t) |
---|
| 1473 | **ii*/ |
---|
| 1474 | abac_context_t *context() { return m_ctx; } |
---|
[64fa9ba] | 1475 | private: |
---|
| 1476 | abac_context_t *m_ctx; |
---|
[8bd77b5] | 1477 | char *m_abac_version; |
---|
[64fa9ba] | 1478 | }; |
---|
[8bd77b5] | 1479 | |
---|
[0b3ac65] | 1480 | Constraint::Constraint(Role& role) |
---|
[5d06689] | 1481 | { m_constraint=abac_constraint_from_role(role.role()); } |
---|
[0b3ac65] | 1482 | Constraint::Constraint(Oset &oset) |
---|
[5d06689] | 1483 | { m_constraint=abac_constraint_from_oset(oset.oset()); } |
---|
[7211a95] | 1484 | DataTerm::DataTerm(ID& id) |
---|
| 1485 | { m_term=abac_term_id_create(id.id()); } |
---|
[64fa9ba] | 1486 | } |
---|
| 1487 | |
---|
| 1488 | #endif /* __ABAC_HH__ */ |
---|