blob: 4388317c4c5a6d10ce2c60798ec878d816090b4f [file] [log] [blame]
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +02001intermud v2.5
2*************
3
4Abstract
5========
6This documents describes how intermud data is send across the internet in the
7protocol specification v2.5.
8This specification is derived from Zebedee Intermud (aka Intermud 2) and
9intends to be compatible to it, i.e. hosts conforming to both protocols should
10be able to exchange data. The aim of v2.5 is to deprecate several historic
11ambiguities, define a more consistent (stricter, less implementation-defined)
12behaviour, add some optional system services and improve reliability and
13remove spoofability of MUDs by introducing hash based message authentication
14codes.
15
16Introduction
17============
18
19Overview
20--------
21The intermud protocols define, how (players on) different muds can
22communicate with each other. There are several different variants.
23In version 2 all muds are peers and directly talking to each other. There
24is no central router. Version 2.5 keeps this behaviour but intends to
25strengthen the P2P character of the intermud by defining a default
26behaviour of learning other peers from one known peer.
27The participants of the intermud are intended to be MUDs, not
28individual players.
29
30Terminology
31-----------
32The capitalized key words "MUST", "MUST NOT", "REQUIRED", "SHALL",
33"SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and
34"OPTIONAL" in this document are to be interpreted as described in BCP
3514, RFC 2119 [TERMS].
36
37MUD
38 multi user dungeon
39intermud peer
40 a participant in the intermud
41inetd
42 a program encoding and sending and receiving and decoding intermud data
43peer address
44 IP address of a peer (MUD)
45MUD name / peer name
46 a name (string) for a peer (MUD)
47peer identifier
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +020048 a unique combination of MUD name, peer address and receiving peer port
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +020049
50
51Transport layer
52===============
53Data between intermud peers is sent as UDP packets (datagrams) over
54IP.
55Each peer listens on one port and uses one to send data. This kind of
56transfer is inherently unreliable, but it's fast and doesn't use up
57file descriptors.
58
59Packet length (MTU)
60-------------------
61A peer **MUST** be able to send and receive datagrams of at least 1024
62byte length. The default packet length **SHOULD** be 1024 bytes. If a peer
63announces a greater possible length limit, that **SHOULD** be used by other peers
64when sending packets to this peer.
65
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +020066A peer may announce the largest reliable packet (maximum transmission unit,
67maximum size of datagram) it can receive when asked with the QUERY module
68which should be the preferred way.
69
70If the MTU cannot be determined with a QUERY, the two peers should try to
71determine them by sending heartbeat packets of increasing size to the other
72peer (see below).
73
74The packet size that is used for sending **SHOULD** be the smaller of the
75maximum packet length of the two communicating peers.
76
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +020077Packet format
78-------------
79All information is encoded and transferred as a string of bytes. The header
80names **SHOULD** consist of ASCII characters.
81Each packet sent consists of a string as follows:
82
83 M:xxx|V:nnn|F:nnn|header1:body1|headerN:bodyN|DATA:body-data
84
85In other words, a header name, followed by a : and then the data
86associated with this header. Each field, consisting of a header/body pair, is
87separated by the | character. This means that headers and their body cannot
88contain the | character. Peers **SHOULD** check for this in outgoing
89packets to avoid decoding errors at the receiving end.
90
91The exception to this is the DATA field. If it is present, it **MUST**
92be positioned at the end of the packet. Once a DATA header is
93found, everything following it is interpreted as the body of the DATA
94field. This means it can contain special characters without error and
95it is used to carry the main body or data of all packets.
96
97By convention, predefined system fields will use capital letters for
98field headers and custom headers used by specific applications will
99use lowercase names to avoid clashes.
100
101A header name **MUST** be unique in a packet.
102
103The fields M (hash based message authentication code), V (version) and F
104(flags) **MUST** be in this order at the start of the packet before any other
105fields.
106
107Fragmented packets
108------------------
109If a packet exceeds the maximum packet length, it **MUST** be split
110(fragmented) into individual packets small enough.
111Each fragment **MUST** start with a fragmentation header describing how the
112fragments are to be reassembled at the receiving end.
113
114These fragmentation headers are of the format:
115
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200116 PKT:peername:packet-id:packet-number/total-packets|M:xxx|rest-of-packet
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200117
118In this case, the mudname and packet-id combine to form a unique id
119for the packet. The packet-number and total-packets information is
120used to determine when all buffered packets have been received. The
121rest-of-packet part is not parsed, but is stored while the receiver
122awaits the other parts of the packet. When/if all parts have been
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200123received they are concatenated (without the fragmentation header and M fields
124of the individual fragments) and decoded as a normal packet.
125
126When storing fragments of a packet, the receiver **MUST** use a unique packet
127id which uses the peer name, peer address and sending peer port and the sent
128packet-id.
129
130Any peer **MUST** support at least 100 fragments per packet.
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200131
132Each fragment **MUST** contain its own valid HMAC in the field M.
133
134The sender **SHOULD** send the fragments in the correct order. However, the
135receiver **MUST** assume the fragments arrive in any order.
136
137The sender **MUST** send all fragments of a packet within 30 s from sending the
138first fragment.
139The receiver **MUST** wait for fragments at least 60 s after the first fragment
140arrived. After this, the receiver may discard any fragments of this packet and
141therefore the packet as a whole.
142
143Packet encoding
144---------------
145Only 2 generic data types are supported (namely strings and integers). All
146other data types **MUST** be expressed as strings or integers.
147
148On encoding integers are simply converted to a corresponding string.
149Strings **MUST** be prefixed with the character $. If the first character of a
150string is the $ character, it is escaped by prepending another $ character.
151
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200152Message authentication codes
153----------------------------
154For packet validation and to prevent tampering on the wire and spoofing of
155peers, each packet sent **MUST** contain a field M containing a hash-based
156message authentication code.
157
158The first byte of the MAC field specifies the HMAC algorithm used. In intermud
159v2.5 the following algorithms **MUST** be supported:
160
161* TLS_HASH_SHA1: 1
162* TLS_HASH_SHA256: 2
163* TLS_HASH_SHA512: 3
164
165The recommended method is SHA1.
166
167The transferred data is the complete packet string **without** the field M.
168After the packet (or fragment) is encoded (without the field M), the HMAC is
169calculated and then inserted into the packet string either at the beginning of
170the packet or (for fragments) at the end of the fragmentation
171header.
172
173The secret must be known to both communicating peers and must be exchanged
174between the operators of two communicating peers. If an intermud peer does not
175use an indivdual secret, it **SHOULD** use its own name. If a receiving peer
176does not know the secret of the sending peer, it SHOULD try to use the
177sending peer's name. Of course, this makes the HMAC just a measure to prevent
178transmission errors.
179
180Packet validation
181-----------------
182Upon receiving a fragment or packet, the receiver **MUST** first try to
183validate the HMAC in the field M. The receiver extracts the whole field from
184the received string and re-calculates the HMAC using the known secret or the
185default secret as fallback. If the calculated and received HMACs do not
186match, the receiver **MUST** discard the fragment or packet.
187
188Fragments are then stored until the packet is completed or the timeout is
189exceeded.
190
191The receiver **SHOULD** parse and decode the packet only after this initial
192validation. If the packet is malformed and cannot be parsed, the receiver
193**MUST** discard the packet.
194
195The intermud protocol versions of peers **SHOULD** be stored and no packets in
196an older protocol version **SHOULD** be accepted.
197
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200198Packet decoding
199---------------
200On decoding, any string with a $ as its first character will have it removed
201and will then be treated as a string.
202Any other strings will be converted to integers.
203
204The fields M, V and F **SHOULD** be stripped from the packet data that is
205transferred from the inetd implementation to the application.
206
207Legacy mode packets and encoding
208--------------------------------
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200209Any intermud v2.5 peer **MUST** send data as described above. However, unless
210in a so-called strict mode, a receiving peer **MUST** accept data in a relaxed
211format that is sent by older intermud peers. Unless in strict mode, the following
212deviations are acceptable when receiving:
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200213
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200214* The M, V and F fields are missing or are not the first three fields.
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200215* A string **MAY** be prefixed with the character $, but does not have to, unless
216 there ambiguity as to wether they should be decoded as a string or an
217 integer. If a string is losslessly convertable to an integer and back to a
218 string, it **MUST** be prefixed by $.
219 This means however, that any string not starting with $ **MUST** be checked
220 whether it is to be interpreted as integer or string.
221
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200222However, a packet **MUST NOT** be parsed as legacy mode packet, if one of the
223following conditions are met:
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200224
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200225* the packet contains the field M
226* the packet contains a version field F with a version of at least 2500
227* the receiving peer operates in strict mode
228
229After a packet conforming to protocol version >= 2.5 (>=2500) was received
230from a peer (this implies the succesful validation of the HMAC), legacy mode
231packets from that peer **MUST NOT** be accepted without manual intervention of
232an operator or expiration of the peer from the peer list.
233
234If a peer sends to a peer with a known protocol version older than v2.5 it
235**MAY** send the data as a legacy mode packet. However, this is not recommended.
236
237Strict mode
238-----------
239To prevent spoofing of other muds, an operator MAY decide to operate in strict
240mode. In this mode, the peer accepts intermud v2.5 packets with a valid M
241field only and discards all other packets. Additionally, the default secrets
242are not used.
243In other words, it disables the compatibility with peers older than v2.5.
244
245Determination of the MTU
246------------------------
247
248Request bookkeeping
249-------------------
250When sending a request that expects/requires an answer, the sender **MUST**
251keep track of the request to relate any answers to the original request.
252
253Any peer **MUST** be able to keep track of at least 100 requests.
254
255If the answer of a request does not arrive within 60s, the request **SHOULD**
256be expired (timeout).
257
258
259Host list / Peer data
260=====================
261A peer **MUST** store the following data about other known peers:
262
263* peer name (unique)
264* peer address
265* peer port (receiving)
266* time of last contact
267
268A peer **SHOULD** store the following data about other known peers:
269
270* time of first contact
271* list of supported services
272* last seen intermud version
273* secret for calculating the HMAC
274* trust score of that peer
275* MTU of the peer
276
277A peer should expire peers from its host list some after the last contact. The
278expiration time may be chosen by the operator.
279However, peers **MUST NOT** be expired before 48h or a time this peer
280announced earlier (see module... TODO) passed without contact.
281If a peer announces it wants to be remembered for longer than 48h without
282contact, this wish MAY be respected.
283
284Before expiring a peer, a ping **SHOULD** be sent to check for reachability.
285
286Automatic update of peer data
287-----------------------------
288When receiving a v2.5 packet with valid HMAC from an address and/or port that
289differs from the one in the peer list, the peer entry **SHOULD** be updated to
290the new address/port.
291
292If the address or port of a peer changes, this peer **SHOULD** send a ping to
293known peers to announce the new address or port.
294
295When receiving a legacy mode packet, the peer entry **MAY** be updated.
296However, this carries the risk of rogue peers successfully impersonating
297another peer for an extended time.
298
299Update of the secret
300--------------------
301There are two ways to perform an update of the secret without operator
302intervention. In both cases, the new secret **MUST** be received in a v2.5
303packet with valid HMAC
304
305# Query: a peer may be asked for its secret with a Query request. However, any
306 peer **MAY** decide freely if it honors such a request (e.g. because the
307 requesting peer is known and trustworthy).
308# Push: a peer may inform other peers about an update of its HMAC secret by
309 sending a - TODO fill in module - to trustworthy known peers. Such an
310 update **SHOULD** be honored.
311
312Combined with the default HMAC secret the second possibility enables peers to
313upgrade from the default secret to a specific one at any time.
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200314
Zesstra@Morgengrauen86eb9762016-04-20 22:49:16 +0200315Which peers to inform about the secret, depends on the operator preferences.
316It may depend on a trust score the operator assigns or it may be sent to peers
317that are around for a certain time.
318
319
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200320Defined system headers / fields
321===============================
322The fields defined in this section **MUST NOT** be used in any application sending
323data via intermud. The sending inetd **SHOULD** check for this during input
324validation before assembling a packet.
325
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200326RCPNT
327 (RECIPIENT) The body of this field should contiain the recipient the message
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200328 is to be sent to if applicable.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200329REQ
330 (REQUEST) The name of the intermud request that is being made of the
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200331 receiving mud. Standard requests that should be supported by
332 all systems are "ping" (PING), "query" (QUERY), and "reply"
333 (REPLY). The PING request is used to determine wether or not a
334 mud is active. The QUERY request is used to query a remote mud
335 for information about itself (look at the udp/query module for
336 details of what information can be requested). The REPLY request
337 is special in that it is the request name used for all replies
338 made to by mud B to an initial request made by a mud A. It is
339 mud A's responsibility to keep track of the original request
340 type so that the reply can be handled appropriately.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200341SND
342 (SENDER) The name of the person or object which sent the request or to
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200343 whom replies should be directed. This is essential if a reply
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200344 is expected.
345DATA
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200346 This field should contain the main body of any packet. It is
347 the only field that can contain special delimiting characters
348 without error.
349
350The following headers are used internally by the inetd and should
351not be used by external objects:
352
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200353HST
354 (HOST) The IP address of the host from which a request was received.
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200355 This is set by the receiving mud and is not contained in
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200356 outgoing packets.
357ID
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200358 The packet id. This field is simply an integer which is set by
359 the sending inetd. The number is incremented each time a packet
360 is sent (zero is never used). This field is only needed if a
361 reply is expected. REPLY packets _must_ include the original
362 request id. This is _not_ done by the inetd.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200363NAME
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200364 The name of the local mud. Used for security checking and to
365 update host list information.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200366PKT
367 (PACKET) A special header reserved for packets which have been fragmented.
368UDP
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200369 The UDP port the local mud is receiving on. Used for security
370 checking and updating host list information.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200371SYS
372 (SYSTEM) Contains special system flags. The only system flag used at
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200373 present is TIME_OUT. This is included in packets returned due
374 to an expected reply timing out to differentiate it from an
375 actual reply.
376
377
378Intermud requests / modules
379===========================
380
381Mandatory requests / modules
382----------------------------
383The following are standard request types that **MUST** be supported
384by all systems:
385
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200386ping
387^^^^
388This module should return a REPLY packet that contains the
389original requests ID in it's ID field and the SENDER in it's
390RECIPIENT field. It should also include an appropriate string
391in the DATA field, eg. "Mud-Name is alive.\n"
392
393query
394^^^^^
395This module expects the type of query requested to appear in the
396recieved DATA field. It should return a REPLY packet containing
397the original ID in the ID field, the SENDER in it's RECIPIENT
398field, and the query type in a QUERY field. The DATA field should
399contain the information requested.
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200400
401
402Optional requests / modules
403----------------------------
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200404These modules are completely optional and their availability at the discretion
405of the operator of a peer.
406
407
408Exchange of secrets for the HMAC
409================================
410In this draft the secrets should be either exchanged manually between
411operators or sent with a push update to known peers.
412For the german MUDs participating in the Intermud, the mailing list
413mudadmins-de@groups.google.com is available.
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200414