implementation.tex (18578B)
1 \section{Implementation} 2 3 The Anastasis is written in C. We decided to use C because of the 4 various dependencies, including cryptographic libraries. Especially, 5 GNU Taler and Sync, which are working in concert with Anastasis, are 6 also written in C. Using the same language makes integration and 7 testing of Anastasis much easier. 8 9 The whole Anastasis application consists of multiple components. 10 Figure~\ref{fig:secret_split:overview} gives an overview over all the 11 components. 12 13 \begin{figure}[H] 14 \centering 15 \includegraphics[scale=0.5]{images/system-architecture.png} 16 \caption{System architecture overview} 17 \label{fig:system_arch:overview} 18 \end{figure} 19 20 \noindent In the center is the core implementation of Anastasis. 21 On the left are some of the planned authentication methods from the 22 application. On the right side of the box are the core parts which are 23 necessary to operate Anastasis commercially. These parts are 24 anticipated for a production deployment, but not part of the 25 implementation for this thesis. 26 27 At the bottom section are the external libraries used for the project. 28 These libraries are presented in Section~\ref{sec:libraries}. 29 \newpage 30 31 32 \subsection{System architecture} 33 34 This graphic shows the basic architecture of the Anastasis 35 application. It shows a simplified flow of the application. The 36 details of each component are explained later. 37 38 \begin{figure}[H] 39 \centering 40 \includegraphics[scale=0.4]{images/system_design.png} 41 \caption{System design overview} 42 \label{fig:system_design} 43 \end{figure} 44 45 \begin{enumerate} 46 \item The Anastasis CLI interacts with the Anastasis API. The 47 Anastasis API is responsible for triggering interactions with the 48 user, and also manages the interactions between the 49 various client-side components. 50 \item After the user provided their unforgettable secret, the 51 Crypto API derives the needed key material for the further 52 communication. This is simplified, in reality the client would first 53 need to download the server salt to generate the user keys. The 54 crypto API is later also responsible for the decryption and 55 encryption of the data, sent or received from the server. 56 \item The Service API is responsible for the communication with the 57 Anastasis server. The Anastasis API sends the previously generated 58 data and the user selected request to the service. 59 The Service API is also responsible to handle 60 the server's response to the request. 61 \item The central webserver logic handles HTTP requests sent to it by the 62 clients. It will dispatch requests to the corresponding handler. The 63 webserver's core logic also returns the response and the status code 64 of the operation to the client application. 65 \item Each REST endpoint of the Anastasis server is implemented by 66 a specific handler. The handler processes the requests, typically 67 by storing or looking up the requested 68 data with the database. When the request is finished, the handler will 69 send back the data or the status code to the webserver's core logic. 70 \end{enumerate} 71 72 73 \input{server_architecture} 74 75 \input{client_architecture} 76 77 \newpage 78 \subsection{Application flow} 79 80 This section describes a happy flow of the two protocols of Anastasis, 81 secret splitting and secret recovery. 82 83 \subsubsection{Secret splitting} 84 85 Figure~\ref{fig:secret_split} illustrates the secret splitting 86 process. 87 88 \begin{figure}[H] 89 \centering 90 \includegraphics[scale=0.5]{images/secret_split.png} 91 \caption{Secret split process} 92 \label{fig:secret_split} 93 \end{figure} 94 \newpage 95 \begin{enumerate} 96 \item The user selects a new escrow provider on which per wants to 97 store a truth object. 98 \item The client software downloads the terms of service for this 99 provider (GET /terms). This is also a check if the server is 100 available if this command doesn't respond the client will abort the 101 process. 102 \item Next the client requests the server configuration (GET 103 /configuration). The configuration lists the available 104 authentication methods and the protocol version of the server. 105 \item The client downloads the server salt (GET /salt). The salt is 106 used to generate the server specific account public key, which 107 identifies the user. 108 \item After the user has generated the public key, per will create a 109 truth object on the client. The truth object contains all the needed 110 information for the recovery for this key share. This truth object 111 is sent encrypted to the server and stored under the TRUTH\_PUB the client 112 generated (POST /truth/\$TRUTH\_PUB). 113 \item In this scenario the client has not jet paid for the 114 upload. This means the server will respond with the HTTP status code 115 \texttt{402 Payment required}. The client first must do a payment with our 116 payment provider --- GNU Taler. After the successful payment the client 117 will receive a payment identifier. With this payment identifier he 118 can resend the previously failed request. 119 \item The user will now repeat the steps 1-6 until per thinks that they 120 have setup a sufficient amount of authentication methods. The user 121 can now combine these providers to create policies. For example per 122 may have stored three truth objects at three different providers. 123 This means per can now define combinations with these providers, 124 for example A+B, A+C and B+C. This means the user has three ways to 125 recover their secret. 126 \item After the user has generated the policies the client will 127 generate a recovery document. The recovery document contains a list 128 of all truth\_seed's used, a list of the policies and the encrypted core 129 secret of the user. The client will now send a encrypted recovery 130 document to each provider used in the recovery document (POST 131 /policy/\$ACCOUNT\_PUB). Through this, the recovery document is 132 replicated and recovery can proceed without a single point of 133 failure. 134 \end{enumerate} 135 \newpage 136 \subsubsection{Secret recovery} 137 138 Figure~\ref{fig:recovery_process} illustrates the recovery process. 139 \begin{figure}[H] 140 \centering 141 \includegraphics[scale=0.5]{images/recovery_process.png} 142 \caption{Secret recovery process} 143 \label{fig:recovery_process} 144 \end{figure} 145 \begin{enumerate} 146 \item The user selects a server on which per previously stored a 147 recovery document. 148 \item Next the client downloads the server salt to compute the server 149 specific account public key (GET /salt). 150 \item After the user generated the public key, per will download the 151 recovery document. At this point per can define a 152 specific version or the latest version of the recovery document. In 153 the illustration the client downloads the latest version (GET 154 /policy/\$ACCOUNT\_PUB). 155 \item The client will now decrypt the recovery document and list all 156 policies and authentication methods. The user now has to solve these 157 challenges. In this example the user has to answer a secure question 158 which was sent to them in the recovery document. (GET 159 /truth/\$TRUTH\_PUB?response=\$RESPONSE) \\ 160 \item Note the server can define that a challenge has a certain cost, 161 in this scenario the server rejects the first request because the 162 user has not yet paid for recovery. After the payment the user can 163 resend the request. After each successfully solved challenge the 164 client will check if one of the policies is completely satisfied. 165 If all shares needed for one of the policies have been recovered, 166 the client will decrypt the core secret and provide it to the user. 167 \end{enumerate} 168 169 Figure~\ref{fig:recovery_process} shows the flow using a secure 170 question for the authentication challenge. If the user would have 171 chosen a complex authentication method like SMS or E-Mail, the client 172 would first need to start the challenge with the request (GET 173 /truth/\$TRUTH\_PUB). The server would then notify the user that per will 174 receive some token out of bounds. After that, the user would have to 175 provide for example the PIN sent to them via SMS with the same request 176 as before (GET /truth/\$TRUTH\_PUB?response=\$RESPONSE). 177 178 179 \subsection{Client Application Command Line Interface (CLI)} 180 181 There are two client applications which interact with the user. First 182 the Anastasis {\em splitter} and second the Anastasis {\em 183 assembler}. The splitter application is responsible for the backup 184 of the core secret. The assembler is then responsible for the recovery 185 of the core secret. 186 187 Both commands are started with a configuration option ``--me=FILE'' 188 that gives the name of a file with the user's identity attributes. 189 190 \subsubsection{Anastasis splitter} 191 192 The user starts the assembler by passing a JSON document with their 193 unforgettable identity attributes (name, social security number, ...). 194 195 The following commands are available: 196 197 \begin{itemize} 198 \item server add \$URL: this command lets the user add escrow 199 providers. The command will check if a supported escrow service is 200 available under the provided URL. Afterwards it will download its 201 terms and salt. The server needs to be added before the user can do 202 any uploads on it. 203 \item truth add \$server \$method \$truth: with this command the user 204 can upload a truth on a previously added server. The user needs to 205 specify the authorization method used and the truth for the 206 authorization process, for example the phone number for SMS 207 authentication. The application will check if the server supports the 208 provided method before uploading. 209 \item policy add \$truth1 \$truth2...: after a user has added all the 210 truths, per can start to create policies. Per can combine the truths 211 in any way they wish. It is also possible to just store one truth in 212 a policy, but this is not recommended since it defies the design of 213 the application. 214 \item policy: shows all created policies. 215 \item truth: shows all created truths. 216 \item server: shows all added servers. 217 \item publish \$secret: if the user is finished per can publish the 218 configuration. The application will then generate the recovery 219 document with the provided information and secret. Afterwards, it 220 will upload the recovery document on every server that was used. For 221 recovery, the user only needs to remember any one of the servers. 222 \end{itemize} 223 224 Below is an example transcript of an interaction with the splitter: 225 226 \begin{lstlisting} 227 $ anastasis-splitter --me=identity.json 228 anastasis-splitter> server add $URL1 229 version: 1.0 230 annual fee: 4.99 KUDOS, 231 available policy methods: sms 232 Server #1 available 233 anastasis-splitter> server add $URL2 234 version: 1.0 235 annual fee: 3.99 KUDOS, 236 available policy methods: sms, question 237 Server #2 available 238 anastasis-splitter> truth add server#1 sms +492452526 239 Truth #1 added for server #1 240 anastasis-splitter> truth add server#2 mail "hoehenweg 80, Biel" 241 Sorry, server #2 does not support 'mail' 242 anastasis-splitter> truth add question "favorite color" "red" 243 Truth #2 added 244 anastasis-splitter> policy add truth#1 truth#2 245 Policy #1 defined 246 anastasis-splitter> policy 247 Policy#1: #truth#1 #truth2 248 anastasis-splitter> truth 249 truth#1: server#1 sms +492452526 250 truth#2: server#2 question "favorite color" <OMITTED> 251 anastasis-splitter> truth --secrets 252 truth#1: sms +492452526 253 truth#2: question "favorite color" "red" 254 anastasis-splitter> server 255 server#1: http://anastasis.example.com/ methods: sms, 256 insured up to: 420 KUDOS, cost: 0.4 KUDOS 257 anastasis-splitter> publish 258 Server#1 failure: 402 payment required: 259 payto://pay/ABALSASDFA KUDOS:0.3 260 Server#2 failure: 402 payment required: 261 payto://pay/ABALSAADAS KUDOS:0.5 262 Total: 0.8 KUDOS 263 # Here: taler-wallet-cli payto://pay/ABALASDFA used to pay! 264 anastasis-splitter> publish 265 Server#2 failure: 402 payment required 266 # Here: taler-wallet-cli payto://pay/ABASDFASDF used to pay! 267 anastasis-splitter> publish "my super secret" 268 Thank you for using Anastasis. 269 $ 270 \end{lstlisting} 271 272 \subsubsection{Anastasis assembler} 273 274 The user starts the assembler by passing a JSON document with their 275 unforgettable identity attributes (name, social security number, ...). 276 They also must pass the URL of an escrow provider which stores their 277 recovery document, as well as the requested version of the recovery 278 document. The assembler will then download and decrypt the recovery 279 document and begin the recovery process. 280 281 282 The following commands are available: 283 \begin{itemize} 284 \item truth: shows all available authorization challenges 285 from the recovery document and their status (``(-)'' not solved, ``(+)'' solved) 286 \item policies: shows all available policies in the recovery document and 287 the respective status of the truths used in each policy. 288 \item try \$truth: this command starts an authorization process which 289 needs interaction with external services like SMS or email. It shows 290 the instructions to follow to authorize release of the share. 291 \item answer \$truth \$answer: this command tries to answer the 292 selected challenge with the provided answer. The application will 293 check the answer and give a feedback to the user. Every time a 294 challenge is solved, the client API will check if as a result any of 295 the policies is completely satisfied. If any policy was completely 296 satisfied, the assembler will print out the recovered core secret 297 and exit. 298 \end{itemize} 299 300 Below is an example transcript of an interaction with the assembler: 301 302 \begin{lstlisting} 303 $ anastasis-assembler --import https://anastasis.example.com/ 304 --policy-version=42 --me=identity.json 305 anastasis-assembler> truth 306 truth#1(-): KUDOS 0.0 question "favorite color" 307 truth#2(-): KUDOS 0.4 sms 308 truth#3(-): KUDOS 2.6 post 309 anastasis-assembler> policies 310 policy#1: KUDOS 0.4 truth#1 truth#2 missing 311 policy#2: KUDOS 3.0 truth#1 truth#2 truth#3 missing 312 anastasis-assembler> try truth#2 313 payto://pay/BASDFASD 314 # SMS arrives asynchronously 315 anastasis-assembler> answer truth#2 1234 316 Success truth#2 317 anastasis-assembler> answer truth#1 "blue" 318 Failed truth#1 319 anastasis-assembler> truth 320 truth#1(-): KUDOS 0.0 question "favorite color" 321 truth#2(+): KUDOS 0.4 sms 322 truth#3(-): KUDOS 2.6 post 323 anastasis-assembler> policies 324 policy#1: KUDOS 0.0 truth#1 missing 325 policy#2: KUDOS 2.6 truth#1 truth#3 missing 326 anastasis-assembler> answer truth#2 "red" 327 Success truth#2 328 //One of the policies was solved successfully and the secret is recovered. 329 Secret was: "my super secret" 330 $ 331 \end{lstlisting} 332 333 334 335 \subsection{Libraries} \label{sec:libraries} 336 337 In this section the libraries used by Anastasis are presented. 338 339 \subsubsection{GNU Taler} 340 341 GNU Taler is one of the main reasons why we started to implement 342 Anastasis, since the application needs a system to back up the private 343 keys of their users. ``GNU Taler is a privacy-preserving payment 344 system. Customers can stay anonymous, but merchants can not hide their 345 income through payments with GNU Taler. This helps to avoid tax 346 evasion and money laundering.''~\cite{gnu_taler} 347 348 To operate GNU Taler the user needs to install an electronic 349 wallet. Backups of the wallet are secured with a secret key. Here 350 comes Anastasis into play, Anastasis will secure this secret key for 351 the user. 352 353 In our implementation GNU Taler is also our payment system. We decided 354 to use GNU Taler because both Anastasis and GNU Taler are privacy 355 preserving applications. If we for example used credit cards for 356 payments the user would no longer be anonymous which is helpful for 357 the security of Anastasis as it allows us to use the user's name in 358 the user's identity attributes. GNU Taler is also a GNU package 359 and Free Software.~\cite{gnu_taler} 360 \newpage 361 \subsubsection{PostgreSQL} 362 363 PostgreSQL is a Free/Libre Open Source object-relational 364 database. PostgreSQL has over 30 years of active development which 365 makes it a stable and reliable software. 366 367 We use PostgreSQL as our database on the Anastasis server. We decided 368 to use PostgreSQL because it is an open source and lightweight 369 software which has a big community. This means there are a lot of 370 helpful documentations and forums.~\cite{postgresql} 371 372 \subsubsection{Libcurl} 373 374 Libcurl is a libre URL transfer library. Libcurl supports a wide range 375 of protocols and a C API. Libcurl is also ready for IPv6 and SSL 376 certificates. 377 378 For Anastasis we use Libcurl to generate the client-side HTTP 379 requests. We decided to use Libcurl because it is also written in C 380 and free software. The software is also well supported and has a good 381 documentation. This makes the integration in our application 382 easy.~\cite{libcurl} 383 384 \subsubsection{GNU Libmicrohttpd} 385 386 GNU libmicrottpd is a small C library which provides an easy way to 387 run a HTTP server. We use GNU Libmicrohttpd in Anastasis to provide a 388 simple webserver. The main reason why we did not use apache or nginx 389 is that we do not need a standalone webserver. The Anastasis webserver 390 just must handle some API requests, a standalone webserver is not 391 needed for that and would make the infrastructure more complex to 392 maintain and develop. GNU Libmicrohttpd is also a GNU package 393 and Free Software.~\cite{libmicrohttpd} 394 395 \subsection{Testing} 396 397 To test our application, we used the GNU Taler testing library as our 398 foundation for t of our testings. This library allows you to create testing instances of 399 both the Anastasis application and the GNU Taler payment system. We 400 implemented unit tests for the crypto functions and the database operations. 401 The following four tests are independently performed. 402 403 \begin{itemize} 404 \item The first test is the database test. The Anastasis testing library first connects to a test database, this database is only used for the testing, we never test on the live database. The test first deletes and recreates the database. After that it will perform several unit tests to check if the database queries of the application are working as intended. 405 \item Next we test the Anastasis crypto API, it tests all the 406 cryptographic functions used in the API with unit tests. 407 The most important part is that the recreation of the keys 408 and decryption works as intended. 409 \item After the basic parts of the application are tested the client 410 will test every request in the Anastasis server API. For this we need the 411 Taler Testing library. The Taler testing library will start an instance 412 of the Anastasis webserver and a GNU Taler merchant service. The merchant 413 service is needed to process the payment operations. The testing library 414 will now send a request to every end point of the Anastasis REST API. It will 415 check if every response of the REST API is as intended. 416 \item At the end the whole application flow is tested. For this 417 we need to start a Anastasis server, Taler merchant and Taler exchange instance. 418 The library will now perform a full secret split and secret recovery. 419 This test is successful if the provided core secret at the begin, matches the 420 recovered core secret. 421 \end{itemize}