blob: 75bda22b6dfbbf344a193bb4de53746b493caa50 [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
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +020083 S:xxx|V:nnn|F:nnn|header1:body1|headerN:bodyN|DATA:body-data
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +020084
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
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +020097The fields S (packet signature), V (version) and F (flags) **MUST** be in this
98order at the start of the packet before any other fields. This 3 fields are
99also referred to as the 'packet header'. The general layout of packets is:
100
101 [fragmentation header]|packet header|packet payload/data
102
103The packet header **MUST NOT** be larger than 512 bytes.
104
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200105By convention, predefined system fields will use capital letters for
106field headers and custom headers used by specific applications will
107use lowercase names to avoid clashes.
108
109A header name **MUST** be unique in a packet.
110
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200111
112Fragmented packets
113------------------
114If a packet exceeds the maximum packet length, it **MUST** be split
115(fragmented) into individual packets small enough.
116Each fragment **MUST** start with a fragmentation header describing how the
117fragments are to be reassembled at the receiving end.
118
119These fragmentation headers are of the format:
120
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200121 PKT:peername:packet-id:packet-number/total-packets|S:xxx|rest-of-packet
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200122
123In this case, the mudname and packet-id combine to form a unique id
124for the packet. The packet-number and total-packets information is
125used to determine when all buffered packets have been received. The
126rest-of-packet part is not parsed, but is stored while the receiver
127awaits the other parts of the packet. When/if all parts have been
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200128received they are concatenated (without the fragmentation header and M fields
129of the individual fragments) and decoded as a normal packet.
130
131When storing fragments of a packet, the receiver **MUST** use a unique packet
132id which uses the peer name, peer address and sending peer port and the sent
133packet-id.
134
135Any peer **MUST** support at least 100 fragments per packet.
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200136
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200137Each fragment **MUST** contain its own valid signature in the field S.
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200138
139The sender **SHOULD** send the fragments in the correct order. However, the
140receiver **MUST** assume the fragments arrive in any order.
141
142The sender **MUST** send all fragments of a packet within 30 s from sending the
143first fragment.
144The receiver **MUST** wait for fragments at least 60 s after the first fragment
145arrived. After this, the receiver may discard any fragments of this packet and
146therefore the packet as a whole.
147
148Packet encoding
149---------------
150Only 2 generic data types are supported (namely strings and integers). All
151other data types **MUST** be expressed as strings or integers.
152
153On encoding integers are simply converted to a corresponding string.
154Strings **MUST** be prefixed with the character $. If the first character of a
155string is the $ character, it is escaped by prepending another $ character.
156
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200157Packet signatures
158-----------------
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200159For packet validation and to prevent tampering on the wire and spoofing of
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200160peers, each packet sent **MUST** contain a field S containing the EC-DSA
161signature of the packet.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200162
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200163The first byte of the MAC field specifies the method and curve used. In intermud
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200164v2.5 the following algorithms **MUST** be supported:
165
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200166*
167*
168*
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200169
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200170The recommended method is ...
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200171
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200172The transferred data is the complete packet string **without** the field S.
173After the packet (or fragment) is encoded (without the field S), the signature
174is calculated using the private EC key and then inserted into the packet
175string either at the beginning of the packet or (for fragments) at the end of
176the fragmentation header.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200177
178Packet validation
179-----------------
180Upon receiving a fragment or packet, the receiver **MUST** first try to
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200181validate the signature in the field S, if a public key for the sending peer is
182known. The receiver extracts the whole field from the received string and
183verifies the signature. If signature can't be verified, the receiver **MUST**
184discard the fragment or packet.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200185
186Fragments are then stored until the packet is completed or the timeout is
187exceeded.
188
189The receiver **SHOULD** parse and decode the packet only after this initial
190validation. If the packet is malformed and cannot be parsed, the receiver
191**MUST** discard the packet.
192
193The intermud protocol versions of peers **SHOULD** be stored and no packets in
194an older protocol version **SHOULD** be accepted.
195
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200196Packet decoding
197---------------
198On decoding, any string with a $ as its first character will have it removed
199and will then be treated as a string.
200Any other strings will be converted to integers.
201
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200202The fields S, V and F **SHOULD** be stripped from the packet data that is
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200203transferred from the inetd implementation to the application.
204
205Legacy mode packets and encoding
206--------------------------------
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200207Any intermud v2.5 peer **MUST** send data as described above. However, unless
208in a so-called strict mode, a receiving peer **MUST** accept data in a relaxed
209format that is sent by older intermud peers. Unless in strict mode, the following
210deviations are acceptable when receiving:
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200211
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200212* The packet header (S, V and F fields) is missing.
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200213* A string **MAY** be prefixed with the character $, but does not have to, unless
214 there ambiguity as to wether they should be decoded as a string or an
215 integer. If a string is losslessly convertable to an integer and back to a
216 string, it **MUST** be prefixed by $.
217 This means however, that any string not starting with $ **MUST** be checked
218 whether it is to be interpreted as integer or string.
219
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200220However, a packet **MUST NOT** be parsed as legacy mode packet, if one of the
221following conditions are met:
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200222
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200223* the packet contains the field S
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200224* the packet contains a version field F with a version of at least 2500
225* the receiving peer operates in strict mode
226
227After a packet conforming to protocol version >= 2.5 (>=2500) was received
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200228from a peer (this implies the succesful validation of the signature), legacy mode
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200229packets from that peer **MUST NOT** be accepted without manual intervention of
230an operator or expiration of the peer from the peer list.
231
232If a peer sends to a peer with a known protocol version older than v2.5 it
233**MAY** send the data as a legacy mode packet. However, this is not recommended.
234
235Strict mode
236-----------
237To prevent spoofing of other muds, an operator MAY decide to operate in strict
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200238mode. In this mode, the peer accepts intermud v2.5 packets with a valid S
239field only and discards all other packets.
240In other words, it disables the compatibility with peers older than v2.5 and
241does not communicate with unknown peers.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200242
243Request bookkeeping
244-------------------
245When sending a request that expects/requires an answer, the sender **MUST**
246keep track of the request to relate any answers to the original request.
247
248Any peer **MUST** be able to keep track of at least 100 requests.
249
250If the answer of a request does not arrive within 60s, the request **SHOULD**
251be expired (timeout).
252
253
254Host list / Peer data
255=====================
256A peer **MUST** store the following data about other known peers:
257
258* peer name (unique)
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200259* public key (unique), if available
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200260* peer address
261* peer port (receiving)
262* time of last contact
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200263* time of first contact
264* reputation (trust) of that peer
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200265
266A peer **SHOULD** store the following data about other known peers:
267
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200268* list of supported services
269* last seen intermud version
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200270* expiration time
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200271* MTU of the peer
272
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200273A peers public key would be the best unique identifier. However, in the
274intermud a peer needs a unique symbolic name to address it. So a peers name
275and its public key should both be used as unique and long-lived identifier.
276
277But a peer MAY change its name by either announcing it or by just using a new
278name. If the public key remains the same, the entry in the peer list should
279be updated accordingly.
280
281If a peer claims to have a name that already exists, but its public key does
282not match the known public key of the existing peer entry, the new peer **MUST
283NOT** be entered in the peer list. Instead, any packets from that peer
284**SHOULD** be discarded. An implementation MAY notify the operator about this.
285
286Reputation
287----------
288The reputation is a score that symbolizes how trustworthy a peer is. It may be
289used for a number of decisions. By default, the reputation score is used as a
290scaling factor when exchanging peer information (see below) and it influences
291how quickly a peer is expired once it can't be reached.
292
293By default, a new peer starts with a score of 0 (which basically means, the
294information it offers, is not trusted). After a peer has been known for some
295time, its score gets increased:
296
297========== ==============
298time known score increase
299========== ==============
3007 days +1
3013 months +1
3021 year +1
303========== ==============
304
305A reputation of more than 3 can only be assigned by an operator.
306
307Peer expiration
308---------------
309A peer should expire peers from its host list some time after the last contact. The
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200310expiration time may be chosen by the operator.
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200311
312However, to prevent rogue peers impersonating other peers, peers **MUST NOT**
313be expired before 48h or a time this peer announced earlier (see module...
314TODO) passed without contact.
315
316========== ===============
317reputation expiration time
318========== ===============
3190 48h
3201 7 days
3212 3 months
3223 6 months
3234+ 12 months
324========== ===============
325
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200326If a peer announces it wants to be remembered for longer than 48h without
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200327contact, this wish MAY be respected and the decision MAY be based on its
328reputation.
329
330An implementation **MAY** may move offline peers to a separate list for
331bookkeeping after some time and stop trying to contact it anymore. This keeps
332the active peer list short and efficient. However the 'long offline' peers
333should still be remembered to keep the binding of public key and name.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200334
335Before expiring a peer, a ping **SHOULD** be sent to check for reachability.
336
337Automatic update of peer data
338-----------------------------
339When receiving a v2.5 packet with valid HMAC from an address and/or port that
340differs from the one in the peer list, the peer entry **SHOULD** be updated to
341the new address/port.
342
343If the address or port of a peer changes, this peer **SHOULD** send a ping to
344known peers to announce the new address or port.
345
346When receiving a legacy mode packet, the peer entry **MAY** be updated.
347However, this carries the risk of rogue peers successfully impersonating
348another peer for an extended time.
349
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200350An inetd **SHOULD** contact the known peers at least once per 24h to check if
351it is still online and reachable (ping or helo).
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200352
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200353Update of the public key
354------------------------
355There ist a way to perform an update of the public key without operator
356intervention. The new public key **MUST** be received in a v2.5 packet with
357valid signature.
358
359A peer may inform other peers about an update of its public key by
360 sending a push notification - TODO fill in module - Such an
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200361 update **SHOULD** be honored.
362
Zesstra@Morgengrauen86eb9762016-04-20 22:49:16 +0200363
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200364Defined system headers / fields
365===============================
366The fields defined in this section **MUST NOT** be used in any application sending
367data via intermud. The sending inetd **SHOULD** check for this during input
368validation before assembling a packet.
369
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200370RCPNT
371 (RECIPIENT) The body of this field should contiain the recipient the message
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200372 is to be sent to if applicable.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200373REQ
374 (REQUEST) The name of the intermud request that is being made of the
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200375 receiving mud. Standard requests that should be supported by
376 all systems are "ping" (PING), "query" (QUERY), and "reply"
377 (REPLY). The PING request is used to determine wether or not a
378 mud is active. The QUERY request is used to query a remote mud
379 for information about itself (look at the udp/query module for
380 details of what information can be requested). The REPLY request
381 is special in that it is the request name used for all replies
382 made to by mud B to an initial request made by a mud A. It is
383 mud A's responsibility to keep track of the original request
384 type so that the reply can be handled appropriately.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200385SND
386 (SENDER) The name of the person or object which sent the request or to
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200387 whom replies should be directed. This is essential if a reply
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200388 is expected.
389DATA
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200390 This field should contain the main body of any packet. It is
391 the only field that can contain special delimiting characters
392 without error.
393
394The following headers are used internally by the inetd and should
395not be used by external objects:
396
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200397HST
398 (HOST) The IP address of the host from which a request was received.
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200399 This is set by the receiving mud and is not contained in
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200400 outgoing packets.
401ID
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200402 The packet id. This field is simply an integer which is set by
403 the sending inetd. The number is incremented each time a packet
404 is sent (zero is never used). This field is only needed if a
405 reply is expected. REPLY packets _must_ include the original
406 request id. This is _not_ done by the inetd.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200407NAME
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200408 The name of the local mud. Used for security checking and to
409 update host list information.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200410PKT
411 (PACKET) A special header reserved for packets which have been fragmented.
412UDP
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200413 The UDP port the local mud is receiving on. Used for security
414 checking and updating host list information.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200415SYS
416 (SYSTEM) Contains special system flags. The only system flag used at
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200417 present is TIME_OUT. This is included in packets returned due
418 to an expected reply timing out to differentiate it from an
419 actual reply.
420
421
422Intermud requests / modules
423===========================
424
425Mandatory requests / modules
426----------------------------
427The following are standard request types that **MUST** be supported
428by all systems:
429
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200430ping
431^^^^
432This module should return a REPLY packet that contains the
433original requests ID in it's ID field and the SENDER in it's
434RECIPIENT field. It should also include an appropriate string
435in the DATA field, eg. "Mud-Name is alive.\n"
436
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200437helo
438^^^^
439Used to exchange information like the public key.
440
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200441query
442^^^^^
443This module expects the type of query requested to appear in the
444recieved DATA field. It should return a REPLY packet containing
445the original ID in the ID field, the SENDER in it's RECIPIENT
446field, and the query type in a QUERY field. The DATA field should
447contain the information requested.
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200448TODO: include asking for peer list in JSON format.
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200449
450
451Optional requests / modules
452----------------------------
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200453These modules are completely optional and their availability at the discretion
454of the operator of a peer.
455
456
457Exchange of secrets for the HMAC
458================================
459In this draft the secrets should be either exchanged manually between
460operators or sent with a push update to known peers.
461For the german MUDs participating in the Intermud, the mailing list
462mudadmins-de@groups.google.com is available.
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200463