Install a pkg-config file.
[fides] / IDEA
1 X.509 and OpenPGP certificates are primarily for authentication (proving
2 identity).  There is limitted support for authorisation, and that support is
3 very domain-specific (hostnames in X.509, email addresses in OpenPGP).
4 Certificates are quite large.  Once a certifacte has been generated, adding or
5 removing authentication or authorisation is hard, especially removing.  X.509
6 hierarchical trust is inflexible, OpenPGP web-of-trust is much better.
7
8 Libfides is about managing certificates. Small and lots of certificates.  There
9 is nothing domain-specific, a certificate can be for authentication or
10 authorisation, or for binding, or anything that can be implemented as a signed
11 statement.  There is only one kind of certificate, there are no special things
12 like revocation certificates.
13
14 Libfides uses ECC, because ECC keys and ECDSA signatures are small, which is
15 necessary if we want to handle lots of certificates. It also allows
16 certificates to be cut&pasted or written down or efficiently sent via the
17 network.
18
19 A certificate consists of a timestamp, a key identifier, a statement, and a
20 signature of the timestamp and statement made with the key identified.
21
22 Libfides also provides functions to work with the known set of certificates.
23 It should make the following very easy for a programmer using libfides:
24
25 - intialisation (key generation, creating repository)
26 - generating certificates
27 - verifying certificates
28 - setting trust for other keys
29 - query trust paths
30 - calculating if a statement is to be trusted
31 - handling negative statements
32 - searching statements
33 - synchronising certificate repositories
34
35 fides_init();
36 fides_cert *cert = fides_cert_create("Hello certificate!");
37 puts(fides_cert_get_statement(cert)); // prints "Hello certificate!";
38 puts(fides_cert_to_string(cert));     // prints above + timestamp + keyid + signature;
39 char *othercert = gets();             // you get the idea
40 fides_cert *cert2 = fides_cert_import(othercert);
41 if(cert2)
42         puts(fides_cert_get_statement(cert2)); // prints statement included in certificate read from stdin
43 if(!fides_cert_verify(cert2))         // verifies signature
44         puts("BAD certificate! BAD!");
45 fides_cert_store(cert2);
46
47 // Find certificates with a particular statement
48 fides_cert *certs[100];
49 int matches = fides_cert_find("Another statement", certs, 100);
50 for(int i = 0; i < matches; i++)
51         puts(fides_cert_to_string(certs[i]));
52
53 // Trust or remove trust of other's keys
54 fides_key *key1, *key2, *key3;
55 fides_key_trust(key1);
56 fides_key_untrust(key2);
57 if(fides_key_is_trusted(key3))
58         printf("We trust %s\n", fides_key_to_string(key3));
59
60 // Find out if a statement is authorised
61 // Looks for statements like "allow localuser read /etc/motd" and "deny localuser read /etc/motd",
62 // looks at the most recent statement from each key,
63 // discards keys that are not trusted,
64 // and decides to allow or deny based on count of "allow ..." and "deny ..." statements left.
65 if(fides_is_allowed("localuser read /etc/motd"))
66         puts("User 'localuser' is allowed to read '/etc/motd'");
67 if(fides_is_denied("remoteuser port 22"))
68         puts("User 'remoteuser' is denied access to port 22");
69
70 // Automatically create allow or deny certificates
71 fides_allow("all access http://my.site.org/");
72 fides_deny("googlebot access http://my.site.org/dontindex/");
73
74 // Revoke your own key
75 fides_key *key = fides_key_self();
76 fides_key_untrust(key);
77 fides_cert *cert = fides_cert_create_trust(key); // generate a certificate saying whether we trust a key or not
78 puts(fides_cert_to_string(cert));
79
80 // Repository synchronisation
81 // First exchanges timestamp of latest known certificate.
82 // If one side has earlier timestamp, other side send all certificates with a newer timestamp.
83 // Then exchange number of items and hash of entire repository with peer.
84 // If the number or hash doesn't match, binary subdivision will follow.
85 // Hash is last 128 bits of the XOR of all valid signatures.
86 // Binary subdivision based on the last bits of the signatures.
87 char outbuf[1024];
88 char inbuf[1024];
89 fides_sync_start();
90 while(!fides_sync_done()) {
91         len = fides_sync_read(char *buf, sizeof buf);
92         if(len)
93                 send(sock, buf, len);
94         if(poll(sock, POLLIN)) {
95                 len = recv(sock, buf, sizeof buf);
96                 fides_sync_write(buf, len);
97         }
98 }