X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=lib%2Ffides.h;h=4ca088f0707bebe526377f9dd70e9529a504452d;hb=f36a11f15b1d75cf3d786cab06fefe0d50812c83;hp=f5137694d7159f9994bf001ba7f9daaf9a083cda;hpb=406a506e2cb5e69789aef20e145b47e36a778543;p=fides diff --git a/lib/fides.h b/lib/fides.h index f513769..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) const; - void load(const std::string &filename); - void save(const std::string &filename) const; - bool verify(const std::string &data, const std::string &signature) const; - std::string to_string() const; - void from_string(const std::string &in); - std::string fingerprint(unsigned int bits = 64) const; + 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) const; - void load_private(const std::string &filename); - void save_private(const std::string &filename) const; - void generate(const std::string &field); - void generate(unsigned int bits = 224); - std::string sign(const std::string &data) const; - }; - - class certificate { - friend class fides; - const publickey *signer; - struct timeval timestamp; - std::string statement; - std::string signature; - - public: - certificate(const publickey *pub, struct timeval timestamp, const std::string &statement, const std::string &signature); - certificate(const 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) const; - bool validate() const; - }; - - // 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() const; - bool fsck() const; - std::string get_homedir() const; + 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, 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 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) 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(); + 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(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; + 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; + 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; + 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) const; + 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) 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) const; -}; + }; +} #endif