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/>.
26 #include "certificate.h"
27 #include "publickey.h"
28 #include "privatekey.h"
32 class exception: public std::runtime_error {
34 exception(const std::string reason): runtime_error(reason) {}
40 std::string obsoletedir;
44 struct timeval latest;
48 std::map<std::string, PublicKey *> keys;
49 std::map<std::string, Certificate *> certs;
51 void merge(Certificate *cert);
52 void merge(PublicKey *key);
55 Manager(const std::string &homedir = "");
58 bool is_firstrun() const;
60 std::string get_homedir() const;
62 void sign(const std::string &statement);
64 void allow(const std::string &statement, const PublicKey *key = 0);
65 void dontcare(const std::string &statement, const PublicKey *key = 0);
66 void deny(const std::string &statement, const PublicKey *key = 0);
67 bool is_allowed(const std::string &statement, const PublicKey *key = 0) const;
68 bool is_denied(const std::string &statement, const PublicKey *key = 0) const;
70 void auth_stats(const std::string &statement, int &self, int &trusted, int &all) const;
71 void trust(const PublicKey *key);
72 void dctrust(const PublicKey *key);
73 void distrust(const PublicKey *key);
74 bool is_trusted(const PublicKey *key) const;
75 bool is_distrusted(const PublicKey *key) const;
76 PublicKey *find_key(const std::string &fingerprint) const;
79 std::vector<const Certificate *> find_certificates(const PublicKey *key, const std::string &statement) const;
80 std::vector<const Certificate *> find_certificates(const std::string &statement) const;
81 std::vector<const Certificate *> find_certificates(const PublicKey *key) const;
83 const Certificate *import_certificate(const std::string &Certificate);
84 std::string export_certificate(const Certificate *) const;
86 const PublicKey *import_key(const std::string &key);
87 std::string export_key(const PublicKey *key) const;
89 void import_all(std::istream &in);
90 void export_all(std::ostream &out) const;
92 Certificate *certificate_from_string(const std::string &Certificate);
93 Certificate *certificate_load(const std::string &filename);
94 void certificate_save(const Certificate *cert, const std::string &filename) const;