1 /* fides.h - Light-weight, decentralised trust and authorisation management
2 Copyright (C) 2008-2009 Guus Sliepen <guus@tinc-vpn.org>
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.
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.
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/>.
22 #include "certificate.h"
23 #include "publickey.h"
24 #include "privatekey.h"
33 class exception: public std::runtime_error {
35 exception(const std::string reason): runtime_error(reason) {}
41 std::string obsoletedir;
45 struct timeval latest;
49 std::map<std::string, PublicKey *> keys;
50 std::map<std::string, Certificate *> certs;
52 void merge(Certificate *cert);
53 void merge(PublicKey *key);
56 Manager(const std::string &homedir = "");
59 bool is_firstrun() const;
61 std::string get_homedir() const;
63 void sign(const std::string &statement);
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;
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;
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;
84 const Certificate *import_certificate(const std::string &Certificate);
85 std::string export_certificate(const Certificate *) const;
87 const PublicKey *import_key(const std::string &key);
88 std::string export_key(const PublicKey *key) const;
90 void import_all(std::istream &in);
91 void export_all(std::ostream &out) const;
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;
101 typedef Fides::Manager fides_manager;
105 typedef struct fides_manager fides_manager;
108 extern fides_manager *fides_init_manager(char *homedir);
109 extern void fides_exit_manager(fides_manager *m);
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);
115 extern void fides_sign(fides_manager *m, const char *statement);
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);
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);
132 extern fides_certificate **find_certificates(fides_manager *m, const fides_publickey *key, const char *statement);
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);
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);
140 extern void fides_import_all(fides_manager *m, FILE *in);
141 extern void fides_export_all(fides_manager *m, FILE *out);
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);