1 | |
---|
2 | /* verify.c */ |
---|
3 | |
---|
4 | #include <err.h> |
---|
5 | #include <string.h> |
---|
6 | |
---|
7 | #include <abac.h> |
---|
8 | #include "creddy_common.h" |
---|
9 | |
---|
10 | int debug=0; |
---|
11 | |
---|
12 | // verify can only valiate that the issuer and the attribute credential |
---|
13 | // are still valid currently and the issuer's keyid is the same as that |
---|
14 | // of the signing issuer id of the attribute credential |
---|
15 | static void _validate(abac_attribute_t *subjec_cert, abac_id_t *cert); |
---|
16 | |
---|
17 | void verify_main(options_t *opts) { |
---|
18 | if (opts->cert == NULL) |
---|
19 | usage(opts); |
---|
20 | |
---|
21 | abac_id_t *issuer_id = abac_id_from_file(opts->cert); |
---|
22 | if (issuer_id == NULL) |
---|
23 | errx(1, "Can't load issuer cert from %s", opts->cert); |
---|
24 | if (opts->attrcert != NULL) { |
---|
25 | abac_list_t *attr_list = abac_attribute_certs_from_file(opts->attrcert); |
---|
26 | abac_attribute_t *subject_attr=NULL; |
---|
27 | abac_list_foreach(attr_list, subject_attr, |
---|
28 | _validate(subject_attr, issuer_id); |
---|
29 | abac_attribute_free(subject_attr); |
---|
30 | ); |
---|
31 | abac_list_free(attr_list); |
---|
32 | } |
---|
33 | |
---|
34 | abac_id_free(issuer_id); |
---|
35 | |
---|
36 | } |
---|
37 | |
---|
38 | static void _validate(abac_attribute_t *attr, abac_id_t *issuer) |
---|
39 | { |
---|
40 | // checking for matching principal keyid |
---|
41 | char *prin=abac_attribute_get_principal(attr); |
---|
42 | char *keyid=abac_id_keyid(issuer); |
---|
43 | if(strcmp(prin,keyid) != 0) |
---|
44 | puts("issuer and attribute cert have mismatched principals\n"); |
---|
45 | else puts("issuer and attribute cert have matching principals\n"); |
---|
46 | free(prin); |
---|
47 | |
---|
48 | if(!abac_id_still_valid(issuer)) |
---|
49 | puts("issuer cert not valid now"); |
---|
50 | else puts("issuer cert still valid"); |
---|
51 | |
---|
52 | if(!abac_attribute_still_valid(attr)) |
---|
53 | puts("attribute cert not valid now"); |
---|
54 | else puts("attribute cert still valid"); |
---|
55 | } |
---|