X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=lib%2Ffides.h;h=4ca088f0707bebe526377f9dd70e9529a504452d;hb=f36a11f15b1d75cf3d786cab06fefe0d50812c83;hp=ff665afede7d82849fcf04d9c0768a66765cf26a;hpb=4b17b54e2250ea75c9947b92a571554dae672bec;p=fides diff --git a/lib/fides.h b/lib/fides.h index ff665af..4ca088f 100644 --- a/lib/fides.h +++ b/lib/fides.h @@ -19,170 +19,81 @@ #define __FIDES_H__ #include -#include -#include -#include #include #include +#include -class fides { - std::string homedir; - std::string certdir; - std::string obsoletedir; - std::string keydir; - - bool firstrun; - struct timeval latest; - static Botan::AutoSeeded_RNG rng; - - public: - // Utility functions - - static std::string b64encode(const std::string &in); - static std::string b64decode(const std::string &in); - static std::string hexencode(const std::string &in); - static std::string hexdecode(const std::string &in); - - class regexp { - regex_t comp; - - public: - static const int EXTENDED = REG_EXTENDED; - static const int ICASE = REG_ICASE; - static const int NOSUB = REG_NOSUB; - static const int NEWLINE = REG_NEWLINE; - - static const int NOTBOL = REG_NOTBOL; - static const int NOTEAL = REG_NOTEOL; - - regexp(const std::string &exp, int cflags = 0) { - int err = regcomp(&comp, exp.c_str(), cflags | NOSUB); - if(err) - throw exception("Could not compile regular expression"); - } - - ~regexp() { - regfree(&comp); - } - - bool match(const std::string &in, int eflags = 0) { - return regexec(&comp, in.c_str(), 0, 0, eflags) == 0; - } - }; - - // Exception class +#include "certificate.h" +#include "publickey.h" +#include "privatekey.h" +#include "utility.h" +namespace Fides { class exception: public std::runtime_error { - public: - exception(const std::string reason): runtime_error(reason) {} - }; - - // Objects manipulated by fides - - class publickey { - protected: - Botan::ECDSA_PublicKey *pub; - public: - publickey(); - ~publickey(); - - int trust; - void load(std::istream &in); - void save(std::ostream &out); - void load(const std::string &filename); - void save(const std::string &filename); - bool verify(const std::string &data, const std::string &signature); - std::string to_string(); - void from_string(const std::string &in); - std::string fingerprint(unsigned int bits = 64); + exception(const std::string reason): runtime_error(reason) {} }; - class privatekey: public publickey { - Botan::ECDSA_PrivateKey *priv; + class Manager { + std::string homedir; + std::string certdir; + std::string obsoletedir; + std::string keydir; - public: - privatekey(); - ~privatekey(); - - void load_private(std::istream &in); - void save_private(std::ostream &out); - void load_private(const std::string &filename); - void save_private(const std::string &filename); - void generate(const std::string &field); - void generate(unsigned int bits = 224); - std::string sign(const std::string &data); - }; - - class certificate { - friend class fides; - publickey *signer; - struct timeval timestamp; - std::string statement; - std::string signature; - - public: - certificate(publickey *pub, struct timeval timestamp, const std::string &statement, const std::string &signature); - certificate(privatekey *priv, struct timeval timestamp, const std::string &statement); + bool firstrun; + struct timeval latest; - std::string to_string() const; - std::string fingerprint(unsigned int bits = 64); - bool validate(); - }; - - // Fides class itself - - private: - privatekey mykey; - std::map keys; - std::map certs; - std::set trustedkeys; + private: + PrivateKey mykey; + std::map keys; + std::map certs; - void merge(certificate *cert); - void merge(publickey *key); + void merge(Certificate *cert); + void merge(PublicKey *key); - public: - fides(const std::string &homedir = ""); - ~fides(); + public: + Manager(const std::string &homedir = ""); + ~Manager(); - bool is_firstrun(); - bool fsck(); - std::string get_homedir(); + bool is_firstrun() const; + bool fsck() const; + std::string get_homedir() const; - void sign(const std::string &statement); + void sign(const std::string &statement); - void allow(const std::string &statement, publickey *key = 0); - void dontcare(const std::string &statement, publickey *key = 0); - void deny(const std::string &statement, publickey *key = 0); - bool is_allowed(const std::string &statement, publickey *key = 0); - bool is_denied(const std::string &statement, publickey *key = 0); + void allow(const std::string &statement, const PublicKey *key = 0); + void dontcare(const std::string &statement, const PublicKey *key = 0); + void deny(const std::string &statement, const PublicKey *key = 0); + bool is_allowed(const std::string &statement, const PublicKey *key = 0) const; + bool is_denied(const std::string &statement, const PublicKey *key = 0) const; - void auth_stats(const std::string &statement, int &self, int &trusted, int &all); - void trust(publickey *key); - void dctrust(publickey *key); - void distrust(publickey *key); - bool is_trusted(publickey *key); - bool is_distrusted(publickey *key); - publickey *find_key(const std::string &fingerprint); - void update_trust(); + void auth_stats(const std::string &statement, int &self, int &trusted, int &all) const; + void trust(const PublicKey *key); + void dctrust(const PublicKey *key); + void distrust(const PublicKey *key); + bool is_trusted(const PublicKey *key) const; + bool is_distrusted(const PublicKey *key) const; + PublicKey *find_key(const std::string &fingerprint) const; + void update_trust(); - std::vector find_certificates(publickey *key, const std::string &statement); - std::vector find_certificates(const std::string &statement); - std::vector find_certificates(publickey *key); + std::vector find_certificates(const PublicKey *key, const std::string &statement) const; + std::vector find_certificates(const std::string &statement) const; + std::vector find_certificates(const PublicKey *key) const; - certificate *import_certificate(const std::string &certificate); - std::string export_certificate(const certificate *); + const Certificate *import_certificate(const std::string &Certificate); + std::string export_certificate(const Certificate *) const; - publickey *import_key(const std::string &key); - std::string export_key(const publickey *key); + const PublicKey *import_key(const std::string &key); + std::string export_key(const PublicKey *key) const; - void import_all(std::istream &in); - void export_all(std::ostream &out); + void import_all(std::istream &in); + void export_all(std::ostream &out) const; - certificate *certificate_from_string(const std::string &certificate); - certificate *certificate_load(const std::string &filename); - void certificate_save(const certificate *cert, const std::string &filename); + Certificate *certificate_from_string(const std::string &Certificate); + Certificate *certificate_load(const std::string &filename); + void certificate_save(const Certificate *cert, const std::string &filename) const; -}; + }; +} #endif