add notes
[iotcloud.git] / doc / iotcloud.tex
1 \documentclass[11pt]{article}\r
2 \newcommand{\tuple}[1]{\ensuremath \langle #1 \rangle}\r
3 \usepackage{color}\r
4 \usepackage{amsthm}\r
5 \newtheorem{theorem}{Theorem}\r
6 \newtheorem{defn}{Definition}\r
7 \newcommand{\note}[1]{{\color{red} \bf [[#1]]}}\r
8 \r
9 \begin{document}\r
10 \section{Approach}\r
11 \r
12 \subsection{Keys}\r
13 \r
14 Each device has: user id + password\r
15 \r
16 Server login is:\r
17 hash1(user id), hash1(password)\r
18 \r
19 Symmetric Crypto keys is:\r
20 hash2(user id | password)\r
21 \r
22 Server has finite length queue of entries + max\_entry\_identifier +\r
23 server login key\r
24 \r
25 \textbf{Login}\r
26 \note{Look at formal algorithm descriptions elsewhere, this is just informal prose...  It really needs to be more precise...}\r
27 \r
28 \begin{enumerate}\r
29 \item In the beginning, there are $d$ devices. Each of the \r
30 devices has a randomly/user-chosen self-generated $m$-bit user \r
31 identification $i$ and $n$-bit password $p$.\note{All devices being known in the beginning seems unreasonable...How about 1 device initially, and devices can be added at any time...}\r
32 \item Each device registers these $i$ and $p$ with the server. \r
33 The server appends ‘salt’ values, $k$-bit random strings $s1$ \r
34 and $s2$, and generate hash values $j=h(i+s1)$ and \r
35 $o=h(p+s2)$ for each $i$ and $p$. All $s1$, $s2$, $j$ and $o$ \r
36 are then stored in the database.\note{Are these the same $i$ and $p$ as below, if so, you just gave away the password}\r
37 \item Device to server validation is done by checking the hash values \r
38 $j\textsc{\char13}$ and $o\textsc{\char13}$ from $i\textsc{\char13}$ and \r
39 $p\textsc{\char13}$ that are given by users at login time against \r
40 $i$ and $p$ that are stored in the database.\r
41 \end{enumerate}\r
42 \r
43 \textbf{Symmetric Keys}\r
44 \note{The user uses the same username/key to log into all devices}\r
45 \begin{enumerate}\r
46 \item In the beginning, there are $d$ devices. Each of the \r
47 devices has a randomly/user-chosen self-generated $m$-bit user \r
48 identification $i$ and $n$-bit password $p$. These $i$ and $p$ \r
49 are used for device login on server.\r
50 \item All of $d$ agree on a hash function $h$ that is not known by \r
51 the server.\note{Doesn't make sense to agree on a hash function...People have a shared key.}\r
52 \item A symmetric key for each device is generated by applying $h$\r
53 to the value $(i + p)$ that gives $SK=h(i + p)$.\r
54 \item This value $SK$ is pre-known and pre-stored by all other \r
55 devices prior to operation of the data structure.\r
56 \end{enumerate}\r
57 \r
58 \textbf{Data Structure on Server}\r
59 \begin{enumerate}\r
60 \item Server maintains a finite length $q$-entry FIFO queue \r
61 $Q=\{0, 1, …, q-1\}$. It has a head and a tail pointers that keep track \r
62 of head and tail slots.\r
63 \item Server records a max entry identifier $max$ as a limit for $q$. \r
64 It keeps track that $q \leq max$ at all times. When $q=max$, the queue \r
65 mechanism allows this sequence of events when there is a new slot added:\r
66 \begin{enumerate}\r
67 \item Pointer for entry $0$ now points to entry $1$, making it the new \r
68 entry $0$.\r
69 \item Entry $0$ is expunged from the queue.\r
70 \item New entry is added to the end of the queue, making it entry $q$.\r
71 \item Pointer for entry $q-1$ is advanced to entry $q$, making it the new \r
72 entry $q-1$.\r
73 \end{enumerate}\r
74 \item For client login, server maintains a table with values $i$, $p$,\r
75 $s1$, and $s2$ that are generated when device registers itself on server \r
76 for the first time.\r
77 \end{enumerate}\r
78 \r
79 \subsection{Entry layout}\r
80 Each entry has:\r
81 \begin{enumerate}\r
82 \item Sequence identifier\r
83 \item Random IV (if needed by crypto algorithm)\r
84 \item Encrypted payload\r
85 \end{enumerate}\r
86 \r
87 Payload has:\r
88 \begin{enumerate}\r
89 \item Sequence identifier\r
90 \item Machine id (most probably something like a 64-bit random number \r
91 that is self-generated by client)\r
92 \item HMAC of previous slot\r
93 \item Data entries\r
94 \item HMAC of current slot\r
95 \end{enumerate}\r
96 \r
97 A data entry can be one of these:\r
98 \begin{enumerate}\r
99 \item All or part of a Key-value entry\r
100 \item Slot sequence entry: Machine id + last message identifier \r
101 \newline {The purpose of this is to keep the record of the last slot \r
102 from a certain client if a client's update has to expunge that other \r
103 client's last entry from the queue. This is kept in the slot until \r
104 the entry owner inserts a newer update into the queue.}\r
105 \item Queue state entry: Includes queue size \newline {The purpose \r
106 of this is for the client to tell if the server lies about the number \r
107 of slots in the queue, e.g. if there are 2 queue state entry in the queue, \r
108 e.g. 50 and 70, the client knows that when it sees 50, it should expect \r
109 at most 50 slots in the queue and after it sees 70, it should expect \r
110 50 slots before that queue state entry slot 50 and at most 70 slots. \r
111 The queue state entry slot 70 is counted as slot number 51 in the queue.}\r
112 \end{enumerate}\r
113 \r
114 \subsection{Live status}\r
115 \r
116 Live status of entries:\r
117 \begin{enumerate}\r
118 \item Key-Value Entry is dead if either (a) there is a newer key-value pair or (b) it is incomplete.\r
119         \r
120 \item Slot sequence number (of either a message version data\r
121 or user-level data) is dead if there is a newer slot from the same machine.\r
122 \r
123 \item Queue state entry is dead if there is a newer queue state entry.\r
124 {In the case of queue state entries 50 and 70, this means that queue state \r
125 entry 50 is dead and 70 is live. However, not until the number of slotes reaches \r
126 70 that queue state entry 50 will be expunged from the queue.}\r
127 \end{enumerate}\r
128 \r
129 When data is at the end of the queue ready to expunge, if:\r
130 \begin{enumerate}\r
131 \item The key-value entry is not dead, it must be reinserted at the\r
132 beginning of the queue.\r
133 \r
134 \item If the slot sequence number is not dead, then a message sequence\r
135 entry must be inserted.\r
136 \r
137 \item If the queue state entry is not dead, it must be reinserted at the\r
138 beginning of the queue.\r
139 \end{enumerate}\r
140 \r
141 \r
142 \paragraph{Reads:}\r
143 Client sends a sequence number.  Server replies with either: all data\r
144 entries or all newer data entries.\r
145 \r
146 \paragraph{Writes:}\r
147 Client sends slot, server verifies that sequence number is valid,\r
148 checks entry hash, and replies with an accept message if all checks\r
149 pass.  On success, client updates its sequence number.  On failure,\r
150 server sends updates slots to client and client validates those slots.\r
151 \r
152 \paragraph{Local state on each client:}\r
153 A list of machines and the corresponding latest sequence numbers.\r
154 \r
155 \paragraph{Validation procedure on client:}\r
156 \begin{enumerate}\r
157 \item Decrypt each new slot in order.\r
158 \item For each slot:\r
159     (a) check its HMAC, and\r
160     (b) check that the previous entry HMAC field matches the previous\r
161     entry.\r
162 \item Check that the last message version for our machine matches our\r
163 last message sent.\r
164 \item For all other machines, check that the latest sequence number is\r
165 at least as large (never goes backwards).\r
166 \item That the queue has a current queue state entry.\r
167 \item That the number of entries received is consistent with the size\r
168 specified in the queue state entry.\r
169 \end{enumerate}\r
170 \r
171 Key-value entries can span multiple slots.  They aren't valid until\r
172 they are complete.\r
173 \r
174 \subsection{Resizing Queue}\r
175 Client can make a request to resize the queue. This is done as a write that combines:\r
176   (a) a slot with the message, and\r
177         (b) a request to the server\r
178 \r
179 \subsection{Formal Guarantees}\r
180 \r
181 \textit{To be completed ...}\r
182 \r
183 \begin{defn}[System Execution]\r
184 Formalize a system execution as a sequence of slot updates...  There\r
185 is a total order of all slot updates.\r
186 \end{defn}\r
187 \r
188 \begin{defn}[Transitive Closure]\r
189 Define transitive closure relation for slot updates...  There is an\r
190 edge from a slot update to a slot receive event if the receive event\r
191 reads from the update event.\r
192 \end{defn}\r
193 \r
194 \begin{defn}[Suborder]\r
195 Define suborder of total order.  It is a sequence of contiguous slots\r
196 updates (as observed by a given device).\r
197 \end{defn}\r
198 \r
199 \begin{defn}[Prefix of a suborder]\r
200 Given a sub order $o=u_{i},u_{i+1},...,u_j, u_{j+i},..., u', ...$ and\r
201 a slot update $u'$ in $o$, the prefix of $o$ is a sequence of all\r
202 updates that occur before $u'$ and $u'$.\r
203 \end{defn}\r
204 \r
205 \begin{defn}[Consistency between a suborder and a total order]\r
206 A suborder $o$ is consistent with a total order $t$, if all updates in $o$ appear in $t$ and they appear in the same order.\r
207 \end{defn}\r
208 \r
209 \begin{defn}[Consistency between suborders]\r
210 Define notion of consistency between suborders...  Two suborders U,V\r
211 are consistent if there exist a total order T such that both U and V\r
212 are suborders of T.\r
213 \end{defn}\r
214 \r
215 \begin{defn}[Error-free execution]\r
216 Define error-free execution --- execution for which the client does\r
217 not flag any errors...\r
218 \end{defn}\r
219 \r
220 \begin{theorem} Error-free execution of algorithm ensures that the suborder\r
221 for node n is consistent with the prefix suborder for all other nodes\r
222 that are in the transitive closure.\r
223 \end{theorem}\r
224 \begin{proof}\r
225 \textit{TODO}\r
226 \end{proof}\r
227 \r
228 \begin{defn}[State of Data Structure]\r
229 Define in terms of playing all updates sequentially onto local data\r
230 structure.\r
231 \end{defn}\r
232 \r
233 \begin{theorem}\r
234 Algorithm gives consistent view of data structure.\r
235 \end{theorem}\r
236 \begin{proof}\r
237 \textit{TODO}\r
238 \end{proof}\r
239 \r
240 \subsection{Future Work}\r
241 \paragraph{Support Messages}\r
242   A message is dead once receiving machine sends an entry with a newer\r
243   sequence identifier\r
244 \r
245 \paragraph{Persistent data structures}\r
246         Root object w/ fields\r
247         Other objects can be reachable from root\r
248         Each object has its own entries\r
249         Dead objects correspond to dead \r
250 \r
251 \paragraph{Multiple App Sharing}\r
252 \r
253 Idea is to separate subspace of entries...  Shared with other cloud...\r
254 \end{document}\r