Import release 0.05
[secnet] / NOTES
CommitLineData
2fe58dfd
SE
1#* Design of new, multi-subnet secnet protocol
2
3Like the first version, we're tunnelling IP packets inside UDP
4packets. To defeat various restrictions which may be imposed on us by
5network providers (like the prohibition of incoming TCP connections)
6we're sticking with UDP for everything this time, including key setup.
7
8Other new features include being able to deal with subnets hidden
9behind changing 'real' IP addresses, and the ability to choose
10algorithms and keys per pair of communicating sites.
11
12** Configuration and structure
13
14The network is made up from a number of 'sites'. These are collections
15of machines with private IP addresses. The new secnet code runs on
16machines which have interfaces on the private site network and some
17way of accessing the 'real' internet.
18
19Each end of a tunnel is identified by a name. Often it will be
20convenient for every gateway machine to use the same name for each
21tunnel endpoint, but this is not vital. Individual tunnels are
22identified by their two endpoint names.
23
24
25The configuration is held in memory as a data structure as follows:
26
27The root is a Dictionary. Dictionaries hold (key,value) pairs. Keys
28are atoms. Values are lists, dictionaries or closures. Lists can hold
29the following types: string, number.
30
31Closures cannot be constructed directly; they are added to the
32'default' dictionary before the configuration file is read. Invocation
33of a closure can return any type of value.
34
35
36Configuration file format: the file describes a dictionary.
37
38key value;
39
40value is item[,item...]
41
42item can be "string", number, path (looks up in dictionary),
43{dictionary}, value(value), value{dictionary}. If item is a list it
44is copied into the list - we can't have lists of lists.
45
46A path is [/]key[\[index\]][/key[\[index\]]...], defining a lookup
47from the current dictionary (or parents) or the root. If a key refers
48to a list of more than one item then an index number (base 0) in
49square brackets can be used to specify the list item number.
50
51Items of the form value1(value2) invoke executable value1 with an
52argument of value2. The return value can be a string or dictionary,
53but not a list. (Invocation happens after the entire configuration
54file has been read.)
55
56Items of the form value{dict} invoke executable value with an argument
57of a single-element list, containing dict. It's just syntactic sugar
58for value({dict}).
59
60
61When a key is used (rather than defined) it is looked up in the
62current dictionary, and if it isn't found it is looked up in the
63(lexical) parent, until the root is reached.
64
65
66
67
68What sorts of crypto-related things do we need to define?
69
70sources of randomness
71block algorithms
72block cipher modes?
73hash functions
74padding functions
75public key signature algorithms
76public key crypto key stores
77key setup algorithms
78
79
80** Protocols
81
82*** Protocol environment:
83
84Each gateway machine serves a particular, well-known set of private IP
85addresses (i.e. the agreement over which addresses it serves is
86outside the scope of this discussion). Each gateway machine has an IP
87address on the interconnecting network (usually the Internet), which
88may be dynamically allocated and may change at any point.
89
90Each gateway knows the RSA public keys of the other gateways with
91which it wishes to communicate. The mechanism by which this happens is
92outside the scope of this discussion. There exists a means by which
93each gateway can look up the probable IP address of any other.
94
95*** Protocol goals:
96
97The ultimate goal of the protocol is for the originating gateway
98machine to be able to forward packets from its section of the private
99network to the appropriate gateway machine for the destination
100machine, in such a way that it can be sure that the packets are being
101sent to the correct destination machine, the destination machine can
102be sure that the source of the packets is the originating gateway
103machine, and the contents of the packets cannot be understood other
104than by the two communicating gateways.
105
106XXX not sure about the address-change stuff; leave it out of the first
107version of the protocol. From experience, IP addresses seem to be
108quite stable so the feature doesn't gain us much.
109
110**** Protocol sub-goal 1: establish a shared key
111
112Definitions:
113
114A is the originating gateway machine
115B is the destination gateway machine
116PK_A is the public RSA key of A
117PK_B is the public RSA key of B
118PK_A^-1 is the private RSA key of A
119PK_B^-1 is the private RSA key of B
120x is the fresh private DH key of A
121y is the fresh private DH key of B
122k is g^xy mod m
123g and m are generator and modulus for Diffie-Hellman
124nA is a nonce generated by A
125nB is a nonce generated by B
126iA is an index generated by A, to be used in packets sent from B to A
127iB is an index generated by B, to be used in packets sent from A to B
128i? is appropriate index for receiver
129
130Note that 'i' may be re-used from one session to the next, whereas 'n'
131is always fresh.
132
133Messages:
134
1351) A->B: *,iA,msg1,A,B,nA
136
1372) B->A: iA,iB,msg2,B,A,nB,nA
138
139(The order of B and A reverses in alternate messages so that the same
140code can be used to construct them...)
141
1423) A->B: {iB,iA,msg3,A,B,nA,nB,g^x mod m}_PK_A^-1
143
144If message 1 was a replay then A will not generate message 3, because
145it doesn't recognise nA.
146
147If message 2 was from an attacker then B will not generate message 4,
148because it doesn't recognise nB.
149
1504) B->A: {iA,iB,msg4,B,A,nB,nA,g^y mod m}_PK_B^-1
151
152At this point, A and B share a key, k. B must keep retransmitting
153message 4 until it receives a packet encrypted using key k.
154
1555) A: iB,iA,msg5,(ping/msg5)_k
156
1576) B: iA,iB,msg6,(pong/msg6)_k
158
159(Note that these are encrypted using the same transform that's used
160for normal traffic, so they include sequence number, MAC, etc.)
161
162The ping and pong messages can be used by either end of the tunnel at
163any time, but using msg0 as the unencrypted message type indicator.
164
165**** Protocol sub-goal 2: end the use of a shared key
166
1677) i?,i?,msg0,(end-session/msg7,A,B)_k
168
169This message can be sent by either party. Once sent, k can be
170forgotten. Once received and checked, k can be forgotten. No need to
171retransmit or confirm reception. It is suggested that this message be
172sent when a key times out, or the tunnel is forcibly terminated for
173some reason.
174
1758) i?,i?,NAK/msg8
176
177If the link-layer can't work out what to do with a packet (session has
178gone away, etc.) it can transmit a NAK back to the sender. The sender
179can then try to verify whether the session is alive by sending ping
180packets, and forget the key if it isn't. Potential denial-of-service
181if the attacker can stop the ping/pong packets getting through (the
182key will be forgotten and another key setup must take place), but if
183they can delete packets then we've lost anyway...
184
185The attacker can of course forge NAKs since they aren't protected. But
186if they can only forge packets then they won't be able to stop the
187ping/pong working. Trust in NAKs can be rate-limited...
188
189Alternative idea: if you receive a packet you can't decode, because
190there's no key established, then initiate key setup...
191
192**** Protocol sub-goal 3: send a packet
193
1949) i?,i?,msg0,(send-packet/msg9,packet)_k