blob: cad388bc2986de15311063c979855836ababbba5 [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
Zesstra79cdbe52016-04-22 19:26:49 +020050Host list / Peer data
51=====================
52A peer **MUST** store the following data about other known peers:
53
54* peer name (unique) (name)
55* public key (unique), if available (pkey)
56* peer address (ip)
57* receiving peer port (port)
58* time of last contact (tlc)
59* time of first contact (tfc)
60* reputation (trust) of that peer (reputation)
61
62A peer **SHOULD** store the following data about other known peers:
63
64* list of supported services (services)
65* last seen intermud version (lsiv)
66* expiration time (ncttl)
67* MTU of the peer (mtu)
68
69A peers public key would be the best unique identifier. However, in the
70intermud a peer needs a unique symbolic name to address it. So a peers name
71and its public key should both be used as unique and long-lived identifier.
72
73But a peer MAY change its name by either announcing it or by just using a new
74name. If the public key remains the same, the entry in the peer list should
75be updated accordingly.
76
77If a peer claims to have a name that already exists, but its public key does
78not match the known public key of the existing peer entry, the new peer **MUST
79NOT** be entered in the peer list. Instead, any packets from that peer
80**SHOULD** be discarded. An implementation MAY notify the operator about this.
81
82When a peer starts up, it **SHOULD** make itself known by pinging known peers
83or sending a HELO packet.
84
85Host keys
86---------
87Each host **MUST** have an elliptic curve private/public key pair for ECDSA or
88EdDSA signatures using one of the following curves:
89
90* secp256r1 / prime256v1
91* Curve25519
92* secp521r1
93
94This *identity key* is long-lived. Bascically, the intermud peer name and its
95reputation tie to this identity key.
96
97Reputation
98----------
99The reputation is a score that symbolizes how trustworthy a peer is. It may be
100used for a number of decisions. By default, the reputation score is used for
101the following:
102
103* scaling factor when exchanging peer information (see below)
104* peer expiration time since last contact (ncttl)
105* services that are offered to the other peer
106
107Specififally, to prevent spam and misuse, services like public channel
108messages and intermud mail **SHOULD** be restricted to peers with a reputation
109> 0. A peer may also restrict the accessibility of user depending on the
110reputation of the sending peer (e.g. beginners can't be disturbed from freshly
111known intermud peers).
112
113By default, a new peer starts with a score of 0 (which basically means, the
114information it offers, is not trusted). After a peer has been known for some
115time, its score gets increased:
116
117========== ==============
118time known score increase
119========== ==============
1207 days +1
1213 months +1
1221 year +1
123========== ==============
124
125A reputation of more than 3 can only be assigned by an operator.
126
127A negative reputation is possible (e.g. manually assigned by operators) and
128should be used to restrict services. Peers with negativ reputation should also
129be kept longer in the peer list.
130
131Peer expiration
132---------------
133A peer should expire peers from its host list some time after the last contact. The
134expiration time may be chosen by the operator.
135
136However, to prevent rogue peers impersonating other peers, peers **MUST NOT**
137be expired before 48h or a time this peer announced earlier (see module...
138TODO) passed without contact.
139
140========== ===============
141reputation expiration time
142========== ===============
1430 72h
1441 14 days
1452 3 months
1463 6 months
1474+ 12 months
148========== ===============
149
150If a peer announces it wants to be remembered for longer than 72h without
151contact, this wish MAY be respected and the decision MAY be based on its
152reputation. A peer **SHOULD NOT** request more then 12 months.
153
154An implementation **MAY** may move offline peers to a separate list for
155bookkeeping after some time and stop trying to contact it anymore. This keeps
156the active peer list short and efficient. However the 'long offline' peers
157should still be remembered to keep the binding of public key and name.
158
159If a peer has problems keeping track of peers, it **SHOULD** prefer to
160temporarily stop accepting new peers instead of expiring known ones.
161If a peer experiences too much intermud traffic (or other resource drains), it
162**MAY** favor peers with higher reputation.
163
164Automatic update of peer data
165-----------------------------
166When receiving a v2.5 packet with valid HMAC from an address and/or port that
167differs from the one in the peer list, the peer entry **SHOULD** be updated to
168the new address/port.
169
170If the address or port of a peer changes, this peer **SHOULD** send a ping to
171known peers to announce the new address or port.
172
173When receiving a legacy mode packet, the peer entry **MAY** be updated.
174However, this carries the risk of rogue peers successfully impersonating
175another peer for an extended time.
176
177An inetd **SHOULD** contact the known peers at least once per 24h to check if
178it is still online and reachable (ping or helo).
179
180Update of the public key
181------------------------
182There ist a way to perform an update of the public key without operator
183intervention. The new public key **MUST** be received in a v2.5 packet with
184valid signature.
185
186A peer may inform other peers about an update of its public key by
187sending a push notification - TODO fill in module - Such an
188update **SHOULD** be honored.
189
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200190
191Transport layer
192===============
193Data between intermud peers is sent as UDP packets (datagrams) over
194IP.
195Each peer listens on one port and uses one to send data. This kind of
196transfer is inherently unreliable, but it's fast and doesn't use up
197file descriptors.
198
199Packet length (MTU)
200-------------------
201A peer **MUST** be able to send and receive datagrams of at least 1024
202byte length. The default packet length **SHOULD** be 1024 bytes. If a peer
203announces a greater possible length limit, that **SHOULD** be used by other peers
204when sending packets to this peer.
205
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200206A peer may announce the largest reliable packet (maximum transmission unit,
207maximum size of datagram) it can receive when asked with the QUERY module
208which should be the preferred way.
209
210If the MTU cannot be determined with a QUERY, the two peers should try to
211determine them by sending heartbeat packets of increasing size to the other
212peer (see below).
213
214The packet size that is used for sending **SHOULD** be the smaller of the
215maximum packet length of the two communicating peers.
216
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200217Packet format
218-------------
219All information is encoded and transferred as a string of bytes. The header
220names **SHOULD** consist of ASCII characters.
221Each packet sent consists of a string as follows:
222
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200223 S:xxx|V:nnn|F:nnn|header1:body1|headerN:bodyN|DATA:body-data
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200224
225In other words, a header name, followed by a : and then the data
226associated with this header. Each field, consisting of a header/body pair, is
227separated by the | character. This means that headers and their body cannot
228contain the | character. Peers **SHOULD** check for this in outgoing
229packets to avoid decoding errors at the receiving end.
230
231The exception to this is the DATA field. If it is present, it **MUST**
232be positioned at the end of the packet. Once a DATA header is
233found, everything following it is interpreted as the body of the DATA
234field. This means it can contain special characters without error and
235it is used to carry the main body or data of all packets.
236
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200237The fields S (packet signature), V (version) and F (flags) **MUST** be in this
238order at the start of the packet before any other fields. This 3 fields are
239also referred to as the 'packet header'. The general layout of packets is:
240
241 [fragmentation header]|packet header|packet payload/data
242
243The packet header **MUST NOT** be larger than 512 bytes.
244
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200245By convention, predefined system fields will use capital letters for
246field headers and custom headers used by specific applications will
247use lowercase names to avoid clashes.
248
249A header name **MUST** be unique in a packet.
250
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200251
252Fragmented packets
253------------------
254If a packet exceeds the maximum packet length, it **MUST** be split
255(fragmented) into individual packets small enough.
256Each fragment **MUST** start with a fragmentation header describing how the
257fragments are to be reassembled at the receiving end.
258
259These fragmentation headers are of the format:
260
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200261 PKT:peername:packet-id:packet-number/total-packets|S:xxx|rest-of-packet
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200262
263In this case, the mudname and packet-id combine to form a unique id
264for the packet. The packet-number and total-packets information is
265used to determine when all buffered packets have been received. The
266rest-of-packet part is not parsed, but is stored while the receiver
267awaits the other parts of the packet. When/if all parts have been
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200268received they are concatenated (without the fragmentation header and M fields
269of the individual fragments) and decoded as a normal packet.
270
271When storing fragments of a packet, the receiver **MUST** use a unique packet
272id which uses the peer name, peer address and sending peer port and the sent
273packet-id.
274
275Any peer **MUST** support at least 100 fragments per packet.
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200276
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200277Each fragment **MUST** contain its own valid signature in the field S.
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200278
279The sender **SHOULD** send the fragments in the correct order. However, the
280receiver **MUST** assume the fragments arrive in any order.
281
282The sender **MUST** send all fragments of a packet within 30 s from sending the
283first fragment.
284The receiver **MUST** wait for fragments at least 60 s after the first fragment
285arrived. After this, the receiver may discard any fragments of this packet and
286therefore the packet as a whole.
287
288Packet encoding
289---------------
290Only 2 generic data types are supported (namely strings and integers). All
291other data types **MUST** be expressed as strings or integers.
292
293On encoding integers are simply converted to a corresponding string.
294Strings **MUST** be prefixed with the character $. If the first character of a
295string is the $ character, it is escaped by prepending another $ character.
296
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200297Packet signatures
298-----------------
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200299For packet validation and to prevent tampering on the wire and spoofing of
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200300peers, each packet sent **MUST** contain a field S containing the EC-DSA
301signature of the packet.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200302
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200303The first byte of the MAC field specifies the method and curve used. In intermud
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200304v2.5 the following algorithms **MUST** be supported:
305
Zesstra79cdbe52016-04-22 19:26:49 +0200306* ECDSA, SHA1, curves secp256r1 / prime256v1, Curve25519, secp521r1
307* ECDSA, SHA256, curves secp256r1 / prime256v1, Curve25519, secp521r1
308* EdDSA, SHA1, curve Curve25519 (Ed25519)
309* EdDSA, SHA256, curve Curve25519 (Ed25519)
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200310
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200311The recommended method is ...
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200312
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200313The transferred data is the complete packet string **without** the field S.
314After the packet (or fragment) is encoded (without the field S), the signature
315is calculated using the private EC key and then inserted into the packet
316string either at the beginning of the packet or (for fragments) at the end of
317the fragmentation header.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200318
319Packet validation
320-----------------
321Upon receiving a fragment or packet, the receiver **MUST** first try to
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200322validate the signature in the field S, if a public key for the sending peer is
323known. The receiver extracts the whole field from the received string and
324verifies the signature. If signature can't be verified, the receiver **MUST**
325discard the fragment or packet.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200326
327Fragments are then stored until the packet is completed or the timeout is
328exceeded.
329
330The receiver **SHOULD** parse and decode the packet only after this initial
331validation. If the packet is malformed and cannot be parsed, the receiver
332**MUST** discard the packet.
333
334The intermud protocol versions of peers **SHOULD** be stored and no packets in
335an older protocol version **SHOULD** be accepted.
336
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200337Packet decoding
338---------------
339On decoding, any string with a $ as its first character will have it removed
340and will then be treated as a string.
341Any other strings will be converted to integers.
342
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200343The fields S, V and F **SHOULD** be stripped from the packet data that is
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200344transferred from the inetd implementation to the application.
345
346Legacy mode packets and encoding
347--------------------------------
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200348Any intermud v2.5 peer **MUST** send data as described above. However, unless
349in a so-called strict mode, a receiving peer **MUST** accept data in a relaxed
350format that is sent by older intermud peers. Unless in strict mode, the following
351deviations are acceptable when receiving:
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200352
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200353* The packet header (S, V and F fields) is missing.
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200354* A string **MAY** be prefixed with the character $, but does not have to, unless
355 there ambiguity as to wether they should be decoded as a string or an
356 integer. If a string is losslessly convertable to an integer and back to a
357 string, it **MUST** be prefixed by $.
358 This means however, that any string not starting with $ **MUST** be checked
359 whether it is to be interpreted as integer or string.
360
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200361However, a packet **MUST NOT** be parsed as legacy mode packet, if one of the
362following conditions are met:
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200363
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200364* the packet contains the field S
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200365* the packet contains a version field F with a version of at least 2500
366* the receiving peer operates in strict mode
367
368After a packet conforming to protocol version >= 2.5 (>=2500) was received
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200369from a peer (this implies the succesful validation of the signature), legacy mode
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200370packets from that peer **MUST NOT** be accepted without manual intervention of
371an operator or expiration of the peer from the peer list.
372
373If a peer sends to a peer with a known protocol version older than v2.5 it
374**MAY** send the data as a legacy mode packet. However, this is not recommended.
375
376Strict mode
377-----------
378To prevent spoofing of other muds, an operator MAY decide to operate in strict
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200379mode. In this mode, the peer accepts intermud v2.5 packets with a valid S
380field only and discards all other packets.
381In other words, it disables the compatibility with peers older than v2.5 and
382does not communicate with unknown peers.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200383
384Request bookkeeping
385-------------------
386When sending a request that expects/requires an answer, the sender **MUST**
387keep track of the request to relate any answers to the original request.
388
389Any peer **MUST** be able to keep track of at least 100 requests.
390
391If the answer of a request does not arrive within 60s, the request **SHOULD**
392be expired (timeout).
393
394
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200395Defined system headers / fields
396===============================
397The fields defined in this section **MUST NOT** be used in any application sending
398data via intermud. The sending inetd **SHOULD** check for this during input
399validation before assembling a packet.
400
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200401RCPNT
402 (RECIPIENT) The body of this field should contiain the recipient the message
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200403 is to be sent to if applicable.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200404REQ
405 (REQUEST) The name of the intermud request that is being made of the
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200406 receiving mud. Standard requests that should be supported by
407 all systems are "ping" (PING), "query" (QUERY), and "reply"
408 (REPLY). The PING request is used to determine wether or not a
409 mud is active. The QUERY request is used to query a remote mud
410 for information about itself (look at the udp/query module for
411 details of what information can be requested). The REPLY request
412 is special in that it is the request name used for all replies
413 made to by mud B to an initial request made by a mud A. It is
414 mud A's responsibility to keep track of the original request
415 type so that the reply can be handled appropriately.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200416SND
417 (SENDER) The name of the person or object which sent the request or to
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200418 whom replies should be directed. This is essential if a reply
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200419 is expected.
420DATA
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200421 This field should contain the main body of any packet. It is
422 the only field that can contain special delimiting characters
423 without error.
424
425The following headers are used internally by the inetd and should
426not be used by external objects:
427
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200428HST
429 (HOST) The IP address of the host from which a request was received.
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200430 This is set by the receiving mud and is not contained in
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200431 outgoing packets.
432ID
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200433 The packet id. This field is simply an integer which is set by
434 the sending inetd. The number is incremented each time a packet
435 is sent (zero is never used). This field is only needed if a
436 reply is expected. REPLY packets _must_ include the original
437 request id. This is _not_ done by the inetd.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200438NAME
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200439 The name of the local mud. Used for security checking and to
440 update host list information.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200441PKT
442 (PACKET) A special header reserved for packets which have been fragmented.
443UDP
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200444 The UDP port the local mud is receiving on. Used for security
445 checking and updating host list information.
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200446SYS
447 (SYSTEM) Contains special system flags. The only system flag used at
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200448 present is TIME_OUT. This is included in packets returned due
449 to an expected reply timing out to differentiate it from an
450 actual reply.
451
452
453Intermud requests / modules
454===========================
455
456Mandatory requests / modules
457----------------------------
458The following are standard request types that **MUST** be supported
459by all systems:
460
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200461ping
462^^^^
463This module should return a REPLY packet that contains the
464original requests ID in it's ID field and the SENDER in it's
465RECIPIENT field. It should also include an appropriate string
466in the DATA field, eg. "Mud-Name is alive.\n"
467
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200468helo
469^^^^
470Used to exchange information like the public key.
Zesstra79cdbe52016-04-22 19:26:49 +0200471To make UDP amplification attacks (e.g. sending a small packet with a faked
472source which causes a larger packet be sent to the victim) more difficult,
473sent HELO **MUST** be larger than xxx bytes by adding a field 'dummy'
474containing zeroes.
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200475
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200476query
477^^^^^
478This module expects the type of query requested to appear in the
479recieved DATA field. It should return a REPLY packet containing
480the original ID in the ID field, the SENDER in it's RECIPIENT
481field, and the query type in a QUERY field. The DATA field should
482contain the information requested.
Zesstra@Morgengrauen09eef282016-04-21 23:00:38 +0200483TODO: include asking for peer list in JSON format.
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200484
485
486Optional requests / modules
487----------------------------
Zesstra@Morgengrauen20219212016-04-20 22:34:41 +0200488These modules are completely optional and their availability at the discretion
489of the operator of a peer.
490
491
492Exchange of secrets for the HMAC
493================================
494In this draft the secrets should be either exchanged manually between
495operators or sent with a push update to known peers.
496For the german MUDs participating in the Intermud, the mailing list
497mudadmins-de@groups.google.com is available.
Zesstra@Morgengrauen5cad50a2016-04-19 21:44:10 +0200498