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