otrv4.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. --------------------------------------------------------------------------------
  2. --
  3. -- Murphi Model of the OTRv4 Draft Protocol State Machine
  4. --
  5. --------------------------------------------------------------------------------
  6. --
  7. -- Written by Nik Unger in 2018
  8. --
  9. -- This is free and unencumbered software released into the public domain.
  10. -- See the UNLICENSE file for the full license / public domain declaration.
  11. --
  12. -- The structure of this Murphi description is heavily inspired by the
  13. -- Needham-Schroeder description by Ulrich Stern, 1998 (bundled with CMurphi),
  14. -- and the OTRv2 description by Andrew Morrison and Joe Bonneau, 2006.
  15. --
  16. --------------------------------------------------------------------------------
  17. --------------------------------------------------------------------------------
  18. -- Declarations
  19. --------------------------------------------------------------------------------
  20. const
  21. NumClients: 2; -- number of clients in the system
  22. NetworkSize: 1; -- maximum number of in-flight messages in network
  23. MaxMessages: 10; -- maximum number of messages sent in a conversation
  24. MaxKnowledge: 10; -- maximum number of messages intruder can remember
  25. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  26. type
  27. InstanceTag: scalarset (NumClients);
  28. MessageType : enum { -- Types of messages that can be sent
  29. M_Plaintext, -- Ordinary plaintext without special values
  30. M_WSpTaggedPlaintext, -- Plaintext with a whitespace tag
  31. M_QueryMessage, -- OTR query message
  32. M_ErrorMessage, -- OTR error message
  33. M_IdentityMessage, -- Identity message (DAKEZ flow 1)
  34. M_AuthR, -- Auth-R message (DAKEZ flow 2)
  35. M_AuthI, -- Auth-I message (DAKEZ flow 3)
  36. M_NonInteractiveAuth, -- Non-Interactive-Auth message (XZDH flow 2)
  37. M_DAKEData, -- Mandatory encrypted message reply to an Auth-I
  38. M_DataMessage -- Encrypted message with text and optionally TLV(s)
  39. };
  40. TLVType : enum { -- Types of encoded TLVs inside data messages
  41. T_Padding, -- Data to ignore (to hide message lengths)
  42. T_Disconnected, -- States that the conversation is over
  43. T_SMP1, -- SMP flow 1
  44. T_SMP2, -- SMP flow 2
  45. T_SMP3, -- SMP flow 3
  46. T_SMP4, -- SMP flow 4
  47. T_SMPAbort, -- States that the SMP has failed
  48. T_ExtraSymmetric -- Request for an extra symmetric key
  49. };
  50. Message : record
  51. msgType: MessageType;
  52. src, dst: InstanceTag; -- The actual sender & receiver clients
  53. -- TODO
  54. endrecord;
  55. ClientProfile : record
  56. owner: InstanceTag; -- Instance tag of creating client
  57. -- TODO
  58. expired: boolean;
  59. endrecord;
  60. -- Not modeled: fragmented messages
  61. -- Not modeled: OTRv3 transitions
  62. ProtocolState : enum { -- Main protocol states for OTRv4 clients
  63. S_Start, -- Initial client state
  64. S_WaitingAuthR, -- Waiting for M_AuthR
  65. S_WaitingAuthI, -- Waiting for M_AuthI
  66. S_WaitingDAKEData, -- Waiting for M_DAKEData
  67. S_EncryptedMessages, -- DAKE is finished, ready for encrypted messages
  68. S_Finished -- Received a disconnected message
  69. };
  70. SMPState : enum { -- SMP state, which expects an S_EncryptedMessages state
  71. SMP_Expect1, -- Initial SMP state, waiting for a T_SMP1 TLV
  72. SMP_Expect2, -- Waiting for a T_SMP2 TLV
  73. SMP_Expect3, -- Waiting for a T_SMP3 TLV
  74. SMP_Expect4 -- Waiting for a T_SMP4 TLV
  75. };
  76. Conversation : record
  77. protoState: ProtocolState; -- Overall protocol state machine
  78. smpState: SMPState; -- SMP state machine
  79. -- TODO
  80. endrecord;
  81. msgCount: 0 .. MaxMessages;
  82. Client : record
  83. conv: array[InstanceTag] of Conversation;
  84. msgCount: msgCount
  85. endrecord;
  86. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  87. -- The global state of the system
  88. var
  89. net: multiset[NetworkSize] of Message; -- In-flight messages
  90. clients: array[InstanceTag] of Client; -- Honest clients
  91. -- Adversarial knowledge:
  92. -- TODO
  93. --------------------------------------------------------------------------------
  94. -- Helper procedures and functions
  95. --------------------------------------------------------------------------------
  96. function transmittable(src, dst: InstanceTag) : boolean;
  97. begin
  98. return src != dst
  99. & multisetcount(l:net, true) < NetworkSize
  100. & clients[src].msgCount < MaxMessages;
  101. endfunction;
  102. procedure transmitMessage(src, dst: InstanceTag; var msg: Message);
  103. begin
  104. msg.src := src;
  105. msg.dst := dst;
  106. multisetadd(msg, net);
  107. clients[src].msgCount := clients[src].msgCount + 1
  108. endprocedure;
  109. --------------------------------------------------------------------------------
  110. -- Client and user rules
  111. --------------------------------------------------------------------------------
  112. ruleset a : InstanceTag; b : InstanceTag do
  113. rule "User requests a new OTR conversation with a query message"
  114. transmittable(a, b)
  115. & clients[a].conv[b].protoState != S_EncryptedMessages
  116. ==>
  117. var msg: Message;
  118. begin
  119. undefine msg;
  120. msg.msgType := M_QueryMessage;
  121. transmitMessage(a, b, msg)
  122. endrule;
  123. endruleset;
  124. ruleset a : InstanceTag; b : InstanceTag do
  125. rule "User requests a new OTR conversation with a whitespace tag"
  126. transmittable(a, b)
  127. & clients[a].conv[b].protoState != S_EncryptedMessages
  128. ==>
  129. var msg: Message;
  130. begin
  131. undefine msg;
  132. msg.msgType := M_WSpTaggedPlaintext;
  133. transmitMessage(a, b, msg)
  134. endrule;
  135. endruleset;
  136. --------------------------------------------------------------------------------
  137. -- Starting state
  138. --------------------------------------------------------------------------------
  139. startstate
  140. undefine net;
  141. undefine clients;
  142. for i : InstanceTag do
  143. clients[i].msgCount := 0;
  144. for j : InstanceTag do
  145. alias
  146. c : clients[i].conv[j]
  147. do
  148. c.protoState := S_Start;
  149. c.smpState := SMP_Expect1
  150. endalias;
  151. endfor;
  152. endfor;
  153. endstartstate;