X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/tripe/blobdiff_plain/aa2405e804f2c2e06204c31ebe8e84e2db3ebefd..9e930d39de569d0aa24eeb7e0603408e89a35c95:/server/tripe.h diff --git a/server/tripe.h b/server/tripe.h index a3f04c73..ad20daa7 100644 --- a/server/tripe.h +++ b/server/tripe.h @@ -52,6 +52,7 @@ #include #include #include +#include #include #include @@ -70,9 +71,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -103,6 +106,7 @@ #include #include +#include "priv.h" #include "protocol.h" #include "slip.h" #include "util.h" @@ -122,15 +126,29 @@ #define T_KEYEXCH 64u #define T_KEYMGMT 128u #define T_CHAL 256u +/* T_PRIVSEP in priv.h */ -#define T_ALL 511u +#define T_ALL 1023u /* --- Units --- */ #define SEC(n) (n##u) #define MIN(n) (n##u * 60u) +#define F_2P32 (65536.0*65536.0) #define MEG(n) (n##ul * 1024ul * 1024ul) +/* --- Timing parameters --- */ + +#define T_EXP MIN(60) /* Expiry time for a key */ +#define T_REGEN MIN(40) /* Regeneration time for a key */ + +#define T_VALID SEC(20) /* Challenge validity period */ +#define T_RETRYMIN SEC(2) /* Minimum retry interval */ +#define T_RETRYMAX MIN(5) /* Maximum retry interval */ +#define T_RETRYGROW (5.0/4.0) /* Retry interval growth factor */ + +#define T_WOBBLE (1.0/3.0) /* Relative timer randomness */ + /* --- Other things --- */ #define PKBUFSZ 65536 @@ -221,6 +239,8 @@ typedef struct keyset { #define KSERR_REGEN -1 /* Regenerate keys */ #define KSERR_NOKEYS -2 /* No keys left */ #define KSERR_DECRYPT -3 /* Unable to decrypt message */ +#define KSERR_SEQ -4 /* Incorrect sequence number */ +#define KSERR_MALFORMED -5 /* Input ciphertext is broken */ /* --- Key exchange --- * * @@ -231,6 +251,10 @@ typedef struct keyset { * Clive Jones. */ +typedef struct retry { + double t; /* Current retry time */ +} retry; + #define KX_NCHAL 16u typedef struct kxchal { @@ -240,6 +264,7 @@ typedef struct kxchal { keyset *ks; /* Pointer to temporary keyset */ unsigned f; /* Various useful flags */ sel_timer t; /* Response timer for challenge */ + retry rs; /* Retry state */ octet hc[MAXHASHSZ]; /* Hash of his challenge */ octet ck[MAXHASHSZ]; /* His magical check value */ octet hswrq_in[MAXHASHSZ]; /* Inbound switch request message */ @@ -254,6 +279,7 @@ typedef struct keyexch { unsigned f; /* Various useful flags */ unsigned s; /* Current state in exchange */ sel_timer t; /* Timer for next exchange */ + retry rs; /* Retry state */ ge *kpub; /* Peer's public key */ time_t texp_kpub; /* Expiry time for public key */ mp *alpha; /* My temporary secret */ @@ -287,8 +313,9 @@ struct peer; typedef struct tunnel_ops { const char *name; /* Name of this tunnel driver */ + unsigned flags; /* Various interesting flags */ +#define TUNF_PRIVOPEN 1u /* Need helper to open file */ void (*init)(void); /* Initializes the system */ - int (*open)(char **/*ifn*/); /* Open tunnel and report ifname */ tunnel *(*create)(struct peer */*p*/, int /*fd*/, char **/*ifn*/); /* Initializes a new tunnel */ void (*setifname)(tunnel */*t*/, const char */*ifn*/); @@ -327,11 +354,14 @@ typedef struct stats { typedef struct peerspec { char *name; /* Peer's name */ + char *tag; /* Public key tag */ const tunnel_ops *tops; /* Tunnel operations */ unsigned long t_ka; /* Keep alive interval */ addr sa; /* Socket address to speak to */ size_t sasz; /* Socket address size */ - unsigned kxf; /* Key exchange flags to set */ + unsigned f; /* Flags for the peer */ +#define PSF_KXMASK 255u /* Key-exchange flags to set */ +#define PSF_MOBILE 256u /* Address may change rapidly */ } peerspec; typedef struct peer_byname { @@ -419,12 +449,6 @@ typedef struct admin_addop { peerspec peer; /* Peer pending creation */ } admin_addop; -typedef struct admin_greetop { - admin_resop r; /* Name resolution header */ - void *c; /* Challenge block */ - size_t sz; /* Length of challenge */ -} admin_greetop; - typedef struct admin_pingop { admin_bgop bg; /* Background operation header */ ping ping; /* Ping pending response */ @@ -665,15 +689,6 @@ extern keyset *ks_gen(const void */*k*/, size_t /*x*/, size_t /*y*/, size_t /*z*/, peer */*p*/); -/* --- @ks_tregen@ --- * - * - * Arguments: @keyset *ks@ = pointer to a keyset - * - * Returns: The time at which moves ought to be made to replace this key. - */ - -extern time_t ks_tregen(keyset */*ks*/); - /* --- @ks_activate@ --- * * * Arguments: @keyset *ks@ = pointer to a keyset @@ -825,6 +840,37 @@ extern int c_check(buf */*b*/); #define A_END ((char *)0) +/* --- @a_vformat@ --- * + * + * Arguments: @dstr *d@ = where to leave the formatted message + * @const char *fmt@ = pointer to format string + * @va_list ap@ = arguments in list + * + * Returns: --- + * + * Use: Main message token formatting driver. The arguments are + * interleaved formatting tokens and their parameters, finally + * terminated by an entry @A_END@. + * + * Tokens recognized: + * + * * "*..." ... -- pretokenized @dstr_putf@-like string + * + * * "?ADDR" SOCKADDR -- a socket address, to be converted + * + * * "?B64" BUFFER SIZE -- binary data to be base64-encoded + * + * * "?TOKENS" VECTOR -- null-terminated vector of tokens + * + * * "?PEER" PEER -- peer's name + * + * * "?ERRNO" ERRNO -- system error code + * + * * "[!]..." ... -- @dstr_putf@-like string as single token + */ + +extern void a_vformat(dstr */*d*/, const char */*fmt*/, va_list /*ap*/); + /* --- @a_warn@ --- * * * Arguments: @const char *fmt@ = pointer to format string @@ -901,13 +947,15 @@ extern void a_daemon(void); * Arguments: @const char *sock@ = socket name to create * @uid_t u@ = user to own the socket * @gid_t g@ = group to own the socket + * @mode_t m@ = permissions to set on the socket * * Returns: --- * * Use: Creates the admin listening socket. */ -extern void a_init(const char */*sock*/, uid_t /*u*/, gid_t /*g*/); +extern void a_init(const char */*sock*/, + uid_t /*u*/, gid_t /*g*/, mode_t /*m*/); /*----- Mapping with addresses as keys ------------------------------------*/ @@ -963,6 +1011,68 @@ extern void *am_find(addrmap */*m*/, const addr */*a*/, extern void am_remove(addrmap */*m*/, void */*i*/); +/*----- Privilege separation ----------------------------------------------*/ + +/* --- @ps_trace@ --- * + * + * Arguments: @unsigned mask@ = trace mask to check + * @const char *fmt@ = message format + * @...@ = values for placeholders + * + * Returns: --- + * + * Use: Writes a trace message. + */ + +T( extern void ps_trace(unsigned /*mask*/, const char */*fmt*/, ...); ) + +/* --- @ps_warn@ --- * + * + * Arguments: @const char *fmt@ = message format + * @...@ = values for placeholders + * + * Returns: --- + * + * Use: Writes a warning message. + */ + +extern void ps_warn(const char */*fmt*/, ...); + +/* --- @ps_tunfd@ --- * + * + * Arguments: @const tunnel_ops *tops@ = pointer to tunnel operations + * @char **ifn@ = where to put the interface name + * + * Returns: The file descriptor, or @-1@ on error. + * + * Use: Fetches a file descriptor for a tunnel driver. + */ + +extern int ps_tunfd(const tunnel_ops */*tops*/, char **/*ifn*/); + +/* --- @ps_split@ --- * + * + * Arguments: @int detachp@ = whether to detach the child from its terminal + * + * Returns: --- + * + * Use: Separates off the privileged tunnel-opening service from the + * rest of the server. + */ + +extern void ps_split(int /*detachp*/); + +/* --- @ps_quit@ --- * + * + * Arguments: --- + * + * Returns: --- + * + * Use: Detaches from the helper process. + */ + +extern void ps_quit(void); + /*----- Peer management ---------------------------------------------------*/ /* --- @p_txstart@ --- * @@ -1150,6 +1260,15 @@ extern peer *p_create(peerspec */*spec*/); extern const char *p_name(peer */*p*/); +/* --- @p_tag@ --- * + * + * Arguments: @peer *p@ = pointer to a peer block + * + * Returns: A pointer to the peer's public key tag. + */ + +extern const char *p_tag(peer */*p*/); + /* --- @p_spec@ --- * * * Arguments: @peer *p@ = pointer to a peer block @@ -1203,7 +1322,7 @@ extern void p_destroy(peer */*p*/); #define FOREACH_PEER(p, stuff) do { \ peer_iter i_; \ peer *p; \ - for (p_mkiter(&i_); (p = p_next(&i_)) != 0; ) do stuff while (0); \ + for (p_mkiter(&i_); (p = p_next(&i_)) != 0; ) stuff \ } while (0) /* --- @p_mkiter@ --- *