1 | |
---|
2 | /* verify.c */ |
---|
3 | |
---|
4 | #include <err.h> |
---|
5 | #include <string.h> |
---|
6 | |
---|
7 | #include "libabac_common.h" |
---|
8 | #include "creddy_common.h" |
---|
9 | |
---|
10 | int debug=0; |
---|
11 | |
---|
12 | extern int abac_list_size(abac_list_t *); |
---|
13 | |
---|
14 | // verify can only valiate that the issuer and the attribute credential |
---|
15 | // are still valid currently and the issuer's keyid is the same as that |
---|
16 | // of the signing issuer id of the attribute credential |
---|
17 | static void _validate(abac_attribute_t *subjec_cert, abac_id_t *cert); |
---|
18 | static void _validate_id(abac_id_t *cert); |
---|
19 | |
---|
20 | void verify_main(options_t *opts) { |
---|
21 | if (opts->cert == NULL) |
---|
22 | usage(opts); |
---|
23 | |
---|
24 | abac_id_t *issuer_id = abac_id_from_file(opts->cert); |
---|
25 | printf("creddy verify, issuer: %s\n", opts->cert); |
---|
26 | if(opts->attrcert) |
---|
27 | printf(" attribute cert: %s\n",opts->attrcert); |
---|
28 | |
---|
29 | if (issuer_id == NULL) |
---|
30 | errx(1, "Can't load issuer cert from %s", opts->cert); |
---|
31 | |
---|
32 | if (opts->attrcert != NULL) { |
---|
33 | abac_list_t *attr_list = abac_attribute_certs_from_file(NULL,opts->attrcert); |
---|
34 | abac_attribute_t *subject_attr=NULL; |
---|
35 | int sz=abac_list_size(attr_list); |
---|
36 | if(sz) { |
---|
37 | abac_list_foreach(attr_list, subject_attr, |
---|
38 | _validate(subject_attr, issuer_id); |
---|
39 | abac_attribute_free(subject_attr); |
---|
40 | ); |
---|
41 | } else { |
---|
42 | printf(" fail to extract attribute cert but...\n"); |
---|
43 | _validate_id(issuer_id); |
---|
44 | } |
---|
45 | abac_list_free(attr_list); |
---|
46 | } else { /* just check issuer_id */ |
---|
47 | _validate_id(issuer_id); |
---|
48 | } |
---|
49 | abac_id_free(issuer_id); |
---|
50 | |
---|
51 | } |
---|
52 | |
---|
53 | static void _validate(abac_attribute_t *attr, abac_id_t *issuer) |
---|
54 | { |
---|
55 | // checking for matching principal keyid |
---|
56 | char *prin=abac_attribute_get_principal(attr); |
---|
57 | char *keyid=abac_id_keyid(issuer); |
---|
58 | if(strcmp(prin,keyid) != 0) |
---|
59 | printf(" issuer and attribute cert have mismatched principals\n"); |
---|
60 | else printf(" issuer and attribute cert have matching principals\n"); |
---|
61 | free(prin); |
---|
62 | |
---|
63 | if(!abac_id_still_valid(issuer)) |
---|
64 | printf(" issuer cert not valid now\n"); |
---|
65 | else printf(" issuer cert still valid\n"); |
---|
66 | |
---|
67 | if(!abac_attribute_still_valid(attr)) |
---|
68 | printf(" attribute cert not valid now\n"); |
---|
69 | else printf(" attribute cert still valid\n"); |
---|
70 | } |
---|
71 | |
---|
72 | static void _validate_id(abac_id_t *issuer) |
---|
73 | { |
---|
74 | if(!abac_id_still_valid(issuer)) |
---|
75 | printf(" issuer cert not valid now\n"); |
---|
76 | else printf(" issuer cert still valid\n"); |
---|
77 | } |
---|
78 | |
---|