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