License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
+#include <cstdio>
#include <string>
#include "certificate.h"
return data;
}
}
+
+// C bindings
+
+fides_certificate *fides_certificate_new(const fides_publickey *pub, struct timeval timestamp, const char *statement, const char *signature) {
+ return new Fides::Certificate(pub, timestamp, statement, signature);
+}
+
+fides_certificate *fides_certificate_new_priv(const fides_privatekey *priv, struct timeval timestamp, const char *statement) {
+ return new Fides::Certificate(priv, timestamp, statement);
+}
+
+void fides_certificate_free(fides_certificate *c) {
+ delete c;
+}
+
+
+char *fides_certificate_to_string(fides_certificate *c) {
+ return strdup(c->to_string().c_str());
+}
+
+char *fides_certificate_fingerprint(fides_certificate *c, unsigned int bits) {
+ return strdup(c->fingerprint(bits).c_str());
+}
+
+bool fides_certificate_validate(fides_certificate *c) {
+ return c->validate();
+}
#ifndef __FIDES_CERTIFICATE_H__
#define __FIDES_CERTIFICATE_H__
-#include <string>
#include <sys/time.h>
#include "publickey.h"
#include "privatekey.h"
+#ifdef __cplusplus
+#include <string>
+
namespace Fides {
class Certificate {
friend class Manager;
};
}
+extern "C" {
+typedef Fides::Certificate fides_certificate;
+#else
+typedef struct fides_certificate fides_certificate;
+#endif
+
+extern fides_certificate *fides_certificate_new(const fides_publickey *pub, struct timeval timestamp, const char *statement, const char *signature);
+extern fides_certificate *fides_certificate_new_priv(const fides_privatekey *priv, struct timeval timestamp, const char *statement);
+extern void fides_certificate_free(fides_certificate *c);
+
+extern char *fides_certificate_to_string(fides_certificate *c);
+extern char *fides_certificate_fingerprint(fides_certificate *c, unsigned int bits);
+extern bool fides_certificate_validate(fides_certificate *c);
+
+#ifdef __cplusplus
+}
+#endif
+
#endif
sign(full);
}
}
+
+// C bindings
+
+fides_manager *fides_init_manager(char *homedir) {
+ return new Fides::Manager(homedir);
+}
+
+void fides_exit_manager(fides_manager *m) {
+ delete m;
+}
+
+bool fides_is_firstrun(fides_manager *m) {
+ return m->is_firstrun();
+}
+
+bool fides_fsck(fides_manager *m) {
+ return m->fsck();
+}
+
+char *fides_get_homedir(fides_manager *m) {
+ return strdup(m->get_homedir().c_str());
+}
+
+void fides_sign(fides_manager *m, const char *statement) {
+ m->sign(statement);
+}
+
+void fides_allow(fides_manager *m, const char *statement, const fides_publickey *key) {
+ m->allow(statement, key);
+}
+
+void fides_dontcare(fides_manager *m, const char *statement, const fides_publickey *key) {
+ m->dontcare(statement, key);
+}
+
+void fides_deny(fides_manager *m, const char *statement, const fides_publickey *key) {
+ m->deny(statement, key);
+}
+
+bool fides_is_allowed(fides_manager *m, const char *statement, const fides_publickey *key) {
+ return m->is_allowed(statement, key);
+}
+
+bool fides_is_denied(fides_manager *m, const char *statement, const fides_publickey *key) {
+ return m->is_denied(statement, key);
+}
+
+void fides_auth_stats(fides_manager *m, const char *statement, int *self, int *trusted, int *all) {
+ return m->auth_stats(statement, *self, *trusted, *all);
+}
+
+void fides_trust(fides_manager *m, const fides_publickey *key) {
+ m->trust(key);
+}
+
+void fides_dctrust(fides_manager *m, const fides_publickey *key) {
+ m->dctrust(key);
+}
+
+void fides_distrust(fides_manager *m, const fides_publickey *key) {
+ m->distrust(key);
+}
+
+bool fides_is_trusted(fides_manager *m, const fides_publickey *key) {
+ return m->is_trusted(key);
+}
+
+bool fides_is_distrusted(fides_manager *m, const fides_publickey *key) {
+ return m->is_distrusted(key);
+}
+
+fides_publickey *fides_find_key(fides_manager *m, const char *fingerprint) {
+ return m->find_key(fingerprint);
+}
+
+void fides_update_trust(fides_manager *m) {
+ m->update_trust();
+}
+
+#if 0
+const fides_certificate **find_certificates(fides_manager *m, const fides_publickey *key, const char *statement) {
+ fides_certificate **result = 0;
+ vector<const Certificate *> certs = m->find_certificates(key, statement);
+ if(certs->size()) {
+ result = malloc(sizeof *result * certs->size());
+ for(int i = 0; i < certs->size(); i++)
+ result[i] = certs[i];
+ }
+ return result;
+}
+
+const fides_certificate *fides_import_certificate(fides_manager *m, const char *certificate) {
+ m->import_certificate(certificate);
+}
+
+char *fides_export_certificate(fides_manager *m, const fides_certificate *certificate) {
+ return strdup(m->export_certificate(certificate).c_str());
+}
+
+const fides_publickey *fides_import_key(fides_manager *m, const char *key) {
+ return m->import_key(key);
+}
+
+char *fides_export_key(fides_manager *m, const fides_publickey *key) {
+ return strdup(m->export_key(key).c_str());
+}
+
+void fides_import_all(fides_manager *m, FILE *in) {
+ m->import_all(in);
+}
+
+void fides_export_all(fides_manager *m, FILE *out) {
+ m->export_all(out);
+}
+#endif
+
+fides_certificate *fides_certificate_from_string(fides_manager *m, const char *certificate) {
+ return m->certificate_from_string(certificate);
+}
+
+fides_certificate *fides_certificate_load(fides_manager *m, const char *filename) {
+ return m->certificate_load(filename);
+}
+
+void fides_certificate_save(fides_manager *m, const fides_certificate *cert, const char *filename) {
+ m->certificate_save(cert, filename);
+}
#ifndef __FIDES_H__
#define __FIDES_H__
-#include <stdexcept>
#include <sys/time.h>
-#include <map>
-#include <vector>
-
#include "certificate.h"
#include "publickey.h"
#include "privatekey.h"
#include "utility.h"
+#ifdef __cplusplus
+#include <stdexcept>
+#include <map>
+#include <vector>
+
namespace Fides {
class exception: public std::runtime_error {
public:
};
}
+extern "C" {
+typedef Fides::Manager fides_manager;
+#else
+#include <stdbool.h>
+#include <stdio.h>
+typedef struct fides_manager fides_manager;
+#endif
+
+extern fides_manager *fides_init_manager(char *homedir);
+extern void fides_exit_manager(fides_manager *m);
+
+extern bool fides_is_firstrun(fides_manager *m);
+extern bool fides_fsck(fides_manager *m);
+extern char *fides_get_homedir(fides_manager *m);
+
+extern void fides_sign(fides_manager *m, const char *statement);
+
+extern void fides_allow(fides_manager *m, const char *statement, const fides_publickey *key);
+extern void fides_dontcare(fides_manager *m, const char *statement, const fides_publickey *key);
+extern void fides_deny(fides_manager *m, const char *statement, const fides_publickey *key);
+extern bool fides_is_allowed(fides_manager *m, const char *statement, const fides_publickey *key);
+extern bool fides_is_denied(fides_manager *m, const char *statement, const fides_publickey *key);
+
+extern void fides_auth_stats(fides_manager *m, const char *statement, int *self, int *trusted, int *all);
+extern void fides_trust(fides_manager *m, const fides_publickey *key);
+extern void fides_dctrust(fides_manager *m, const fides_publickey *key);
+extern void fides_distrust(fides_manager *m, const fides_publickey *key);
+extern bool fides_is_trusted(fides_manager *m, const fides_publickey *key);
+extern bool fides_is_distrusted(fides_manager *m, const fides_publickey *key);
+extern fides_publickey *fides_find_key(fides_manager *m, const char *fingerprint);
+extern void fides_update_trust(fides_manager *m);
+
+extern fides_certificate **find_certificates(fides_manager *m, const fides_publickey *key, const char *statement);
+
+extern const fides_certificate *fides_import_certificate(fides_manager *m, const char *certificate);
+extern char *fides_export_certificate(fides_manager *m, const fides_certificate *certificcate);
+
+extern const fides_publickey *fides_import_key(fides_manager *m, const char *key);
+extern char *fides_export_key(fides_manager *m, const fides_publickey *key);
+
+extern void fides_import_all(fides_manager *m, FILE *in);
+extern void fides_export_all(fides_manager *m, FILE *out);
+
+extern fides_certificate *fides_certificate_from_string(fides_manager *m, const char *certificate);
+extern fides_certificate *fides_certificate_load(fides_manager *m, const char *filename);
+extern void fides_certificate_save(fides_manager *m, const fides_certificate *cert, const char *filename);
+
+#ifdef __cplusplus
+}
+#endif
+
#endif
return string((const char *)sig.begin(), (size_t)sig.size());
}
}
+
+// C bindings
+
+fides_privatekey *fides_privatekey_new() {
+ return new Fides::PrivateKey();
+}
+
+void fides_privatekey_free(fides_privatekey *k) {
+ delete k;
+}
+
+void fides_privatekey_load_public(fides_privatekey *k, const char *filename) {
+ k->load(filename);
+}
+
+void fides_privatekey_save_public(fides_privatekey *k, const char *filename) {
+ k->save(filename);
+}
+
+void fides_privatekey_load(fides_privatekey *k, const char *filename) {
+ k->load_private(filename);
+}
+
+void fides_privatekey_save(fides_privatekey *k, const char *filename) {
+ k->save_private(filename);
+}
+
+void fides_privatekey_generate_field(fides_privatekey *k, const char *field) {
+ k->generate(field);
+}
+
+void fides_privatekey_generate(fides_privatekey *k, unsigned int bits) {
+ k->generate(bits);
+}
+
+char *fides_privatekey_sign(fides_privatekey *k, const char *data) {
+ return strdup(k->sign(data).c_str());
+}
#ifndef __FIDES_PRIVATEKEY_H__
#define __FIDES_PRIVATEKEY_H__
+#include "publickey.h"
+
+#ifdef __cplusplus
#include <string>
#include <botan/botan.h>
#include <botan/ecdsa.h>
-#include "publickey.h"
namespace Fides {
class PrivateKey: public PublicKey {
};
}
+extern "C" {
+typedef Fides::PrivateKey fides_privatekey;
+#else
+typedef struct fides_privatekey fides_privatekey;
+#endif
+
+extern fides_privatekey *fides_privatekey_new();
+extern void fides_privatekey_free(fides_privatekey *k);
+
+extern void fides_privatekey_load_public(fides_privatekey *k, const char *filename);
+extern void fides_privatekey_save_public(fides_privatekey *k, const char *filename);
+extern void fides_privatekey_load(fides_privatekey *k, const char *filename);
+extern void fides_privatekey_save(fides_privatekey *k, const char *filename);
+extern void fides_privatekey_generate_field(fides_privatekey *k, const char *field);
+extern void fides_privatekey_generate(fides_privatekey *k, unsigned int bits);
+extern char *fides_privatekey_sign(fides_privatekey *k, const char *data);
+#ifdef __cplusplus
+}
+#endif
+
#endif
return verifier->check_signature(sig);
}
}
+
+// C bindings
+
+fides_publickey *fides_publickey_new() {
+ return new Fides::PublicKey();
+}
+
+void fides_publickey_free(fides_publickey *k) {
+ delete k;
+}
+
+
+void fides_publickey_set_trust(fides_publickey *k, int trust) {
+ k->trust = trust;
+}
+
+int fides_publickey_get_trust(fides_publickey *k) {
+ return k->trust;
+}
+
+
+void fides_publickey_load(fides_publickey *k, const char *filename) {
+ k->load(filename);
+}
+
+void fides_publickey_save(fides_publickey *k, const char *filename) {
+ k->save(filename);
+}
+
+bool fides_publickey_verify(fides_publickey *k, const char *data, const char *signature) {
+ return k->verify(data, signature);
+}
+
+char *fides_publickey_to_string(fides_publickey *k) {
+ return strdup(k->to_string().c_str());
+}
+
+void fides_publickey_from_string(fides_publickey *k, const char *in) {
+ k->from_string(in);
+}
+
+char *fides_publickey_fingerprint(fides_publickey *k, unsigned int bits) {
+ return strdup(k->fingerprint(bits).c_str());
+}
#ifndef __FIDES_PUBLICKEY_H__
#define __FIDES_PUBLICKEY_H__
+#ifdef __cplusplus
#include <string>
#include <iostream>
#include <botan/botan.h>
};
}
+extern "C" {
+typedef Fides::PublicKey fides_publickey;
+#else
+#include <stdbool.h>
+typedef struct fides_publickey fides_publickey;
+#endif
+
+extern fides_publickey *fides_publickey_new();
+extern void fides_publickey_free(fides_publickey *k);
+
+extern void fides_publickey_set_trust(fides_publickey *k, int trust);
+extern int fides_publickey_get_trust(fides_publickey *k);
+
+extern void fides_publickey_load(fides_publickey *k, const char *filename);
+extern void fides_publickey_save(fides_publickey *k, const char *filename);
+extern bool fides_publickey_verify(fides_publickey *k, const char *data, const char *signature);
+extern char *fides_publickey_to_string(fides_publickey *k);
+extern void fides_publickey_from_string(fides_publickey *k, const char *in);
+extern char *fides_publickey_fingerprint(fides_publickey *k, unsigned int bits);
+
+#ifdef __cplusplus
+}
+#endif
+
#endif
return files;
}
}
+
+// C bindings
+
+char *fides_b64encode(const char *in) {
+ return strdup(Fides::b64encode(in).c_str());
+}
+
+char *fides_b64decode(const char *in) {
+ return strdup(Fides::b64decode(in).c_str());
+}
+
+char *fides_hexencode(const char *in) {
+ return strdup(Fides::hexencode(in).c_str());
+}
+
+char *fides_hexdecode(const char *in) {
+ return strdup(Fides::hexdecode(in).c_str());
+}
#ifndef __FIDES_UTILITY_H__
#define __FIDES_UTILITY_H__
+#ifdef __cplusplus
#include <stdexcept>
#include <string>
#include <vector>
std::vector<std::string> dirlist(const std::string &path);
}
+extern "C" {
+#endif
+
+extern char *fides_b64encode(const char *in);
+extern char *fides_b64decode(const char *in);
+extern char *fides_hexencode(const char *in);
+extern char *fides_hexdecode(const char *in);
+
+#ifdef __cplusplus
+}
+#endif
+
#endif