Install a pkg-config file.
[fides] / lib / fides.h
1 /* fides.h - Light-weight, decentralised trust and authorisation management
2    Copyright (C) 2008-2009  Guus Sliepen <guus@tinc-vpn.org>
3   
4    Fides is free software; you can redistribute it and/or modify
5    it under the terms of the GNU Lesser General Public License as
6    published by the Free Software Foundation; either version 2.1 of
7    the License, or (at your option) any later version.
8   
9    Fides is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12    GNU Lesser General Public License for more details.
13   
14    You should have received a copy of the GNU Lesser General Public
15    License along with this program; if not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef __FIDES_H__
19 #define __FIDES_H__
20
21 #include <sys/time.h>
22 #include "certificate.h"
23 #include "publickey.h"
24 #include "privatekey.h"
25 #include "utility.h"
26
27 #ifdef __cplusplus
28 #include <stdexcept>
29 #include <map>
30 #include <vector>
31
32 namespace Fides {
33         class exception: public std::runtime_error {
34                 public:
35                 exception(const std::string reason): runtime_error(reason) {}
36         };
37
38         class Manager {
39                 std::string homedir;
40                 std::string certdir;
41                 std::string obsoletedir;
42                 std::string keydir;
43
44                 bool firstrun;
45                 struct timeval latest;
46
47                 private:
48                 PrivateKey mykey;
49                 std::map<std::string, PublicKey *> keys;
50                 std::map<std::string, Certificate *> certs;
51
52                 void merge(Certificate *cert);
53                 void merge(PublicKey *key);
54
55                 public:
56                 Manager(const std::string &homedir = "");
57                 ~Manager();
58
59                 bool is_firstrun() const;
60                 bool fsck() const;
61                 std::string get_homedir() const;
62
63                 void sign(const std::string &statement);
64
65                 void allow(const std::string &statement, const PublicKey *key = 0);
66                 void dontcare(const std::string &statement, const PublicKey *key = 0);
67                 void deny(const std::string &statement, const PublicKey *key = 0);
68                 bool is_allowed(const std::string &statement, const PublicKey *key = 0) const;
69                 bool is_denied(const std::string &statement, const PublicKey *key = 0) const;
70
71                 void auth_stats(const std::string &statement, int &self, int &trusted, int &all) const;
72                 void trust(const PublicKey *key);
73                 void dctrust(const PublicKey *key);
74                 void distrust(const PublicKey *key);
75                 bool is_trusted(const PublicKey *key) const;
76                 bool is_distrusted(const PublicKey *key) const;
77                 PublicKey *find_key(const std::string &fingerprint) const;
78                 void update_trust();
79
80                 std::vector<const Certificate *> find_certificates(const PublicKey *key, const std::string &statement) const;
81                 std::vector<const Certificate *> find_certificates(const std::string &statement) const;
82                 std::vector<const Certificate *> find_certificates(const PublicKey *key) const;
83
84                 const Certificate *import_certificate(const std::string &Certificate);
85                 std::string export_certificate(const Certificate *) const;
86
87                 const PublicKey *import_key(const std::string &key);
88                 std::string export_key(const PublicKey *key) const;
89
90                 void import_all(std::istream &in);
91                 void export_all(std::ostream &out) const;
92
93                 Certificate *certificate_from_string(const std::string &Certificate);
94                 Certificate *certificate_load(const std::string &filename);
95                 void certificate_save(const Certificate *cert, const std::string &filename) const;
96
97         };
98 }
99
100 extern "C" {
101 typedef Fides::Manager fides_manager;
102 #else
103 #include <stdbool.h>
104 #include <stdio.h>
105 typedef struct fides_manager fides_manager;
106 #endif
107
108 extern fides_manager *fides_init_manager(char *homedir);
109 extern void fides_exit_manager(fides_manager *m);
110
111 extern bool fides_is_firstrun(fides_manager *m);
112 extern bool fides_fsck(fides_manager *m);
113 extern char *fides_get_homedir(fides_manager *m);
114
115 extern void fides_sign(fides_manager *m, const char *statement);
116
117 extern void fides_allow(fides_manager *m, const char *statement, const fides_publickey *key);
118 extern void fides_dontcare(fides_manager *m, const char *statement, const fides_publickey *key);
119 extern void fides_deny(fides_manager *m, const char *statement, const fides_publickey *key);
120 extern bool fides_is_allowed(fides_manager *m, const char *statement, const fides_publickey *key);
121 extern bool fides_is_denied(fides_manager *m, const char *statement, const fides_publickey *key);
122
123 extern void fides_auth_stats(fides_manager *m, const char *statement, int *self, int *trusted, int *all);
124 extern void fides_trust(fides_manager *m, const fides_publickey *key);
125 extern void fides_dctrust(fides_manager *m, const fides_publickey *key);
126 extern void fides_distrust(fides_manager *m, const fides_publickey *key);
127 extern bool fides_is_trusted(fides_manager *m, const fides_publickey *key);
128 extern bool fides_is_distrusted(fides_manager *m, const fides_publickey *key);
129 extern fides_publickey *fides_find_key(fides_manager *m, const char *fingerprint);
130 extern void fides_update_trust(fides_manager *m);
131
132 extern fides_certificate **find_certificates(fides_manager *m, const fides_publickey *key, const char *statement);
133
134 extern const fides_certificate *fides_import_certificate(fides_manager *m, const char *certificate);
135 extern char *fides_export_certificate(fides_manager *m, const fides_certificate *certificcate);
136
137 extern const fides_publickey *fides_import_key(fides_manager *m, const char *key);
138 extern char *fides_export_key(fides_manager *m, const fides_publickey *key);
139
140 extern void fides_import_all(fides_manager *m, FILE *in);
141 extern void fides_export_all(fides_manager *m, FILE *out);
142
143 extern fides_certificate *fides_certificate_from_string(fides_manager *m, const char *certificate);
144 extern fides_certificate *fides_certificate_load(fides_manager *m, const char *filename);
145 extern void fides_certificate_save(fides_manager *m, const fides_certificate *cert, const char *filename);
146
147 #ifdef __cplusplus
148 }
149 #endif
150
151 #endif